Blue Flower

Programming

Programming: Tech Notes on things related to Software development. Firmware Development. Scripting. Hacking. CGI and more.  Broken into various related sub-categories.  Click on the big + sign to toggle the listing of categories and/or articles.

How To Stop Vim (vi) From Tracking (Logging/Recording) All Your Actions When You Use Vim On A File

Introduction

On Unix, Linux, and *ix servers, when you text edit a file using Vim, all your actions and some options choices are logged into a file of .viminfo.  So, all your changes, and what you thought you deleted is still reflected in that .viminfo file.  It also allows you to edit another file and scroll through searches you did while working on a previous file.  There are huge benefits for having this automated logging, but that is not what this article is about.  It does not matter what file you edit, when you use the Vim (vi) software, the logging occurs.  So, if you accidentally typed or pasted a password into the command line and edited the .bash_history file to remove it's mentions, then know that it still shows in the .viminfo file.  If you try to edit the .viminfo file by deleting the lines that show things you do not want, those changes will be logged and updated to the .viminfo file.  So, if you edit the .viminfo file itself and close it and then open it again, you will see what you removed continue to be mentioned in some form.  So, as you can see there are times when you will want the logging turned off, and that is easily done.

 

To Turn Off Logging While Using Vim

When editing any file type the following:

:set viminfo=

The above will turn off the logging of your actions when using Vim (vi).

 

Choosing Selective Logging

 I have also collected the following that allows you to selectively turn of or log specific things.  After the = sign, you can indicate Switches that enable (turn on) or disable (turn off) behaviors.

 

  • '0 means that marks will not be saved.
  • :0 means that command line history will not be saved.
  • <0 means that registers will not be saved.
  • @0 means that input line history will not be saved.
  • f0 means that marks will not be saved.
  • % means it saves buffer and restores the buffer list.
  • / means that the search history will not be saved.  The default is to save the search history.
  • n indicates where to save the viminfo files.
  • '10  means marks will be remembered for up to 10 previously edited files.
  • "100 means it will save up to 100 lines for each register.
  • :20  means  up to 20 lines of command line history will be stored.

Example: :set viminfo='0,:0,<0,@0,f0,n~/.viminfo
The / is not used in the above example, and so search history would be saved.

Example: :set viminfo='50,\"1000,:0,n~/vim/viminfo

Example: :set viminfo='10,\"100,:20,%,nc:\\owner\\Windows\\_viminfo
In this case, what follows after n indicates the file system path on a windows operating system.

The above should work for many versions of VIM, including 7.2, and 7.4.
You can access the Vim Help, while using Vim, by typing :h 'viminfo'.

 

What Does Or Can .viminfo Store?

The viminfo file is used to store:
- The command line history.
- The search string history.
- The input-line history.
- Contents of registers.
- Marks for several files.
- File marks, pointing to locations in files; such as cursor position.
- Last search/substitute pattern (for 'n' and '&').
- The buffer list.
- Global variables.
- Deletions and additions (as implied above).

 

Feel Free To Leave A Good Comment. :)

Look around, and you may find other useful articles. Add this site to your Bookmarks/Favorites for easy return for new articles. Consider submitting technical articles for publication, including your embedded links. I will even create a new category if needed.

How To Show Line Numbers In VIM (VI) Editor

 

To Turn On Line Numbers In VIM

To see line number when using VIM (VI), which have no impact on your file content and used for guidance, do the following:

  1. Open a file with VIM.

  2. Enter :set number or :set nu.

To Turn Off Line Numbers In VIM

To no longer see the line numbers show in VIM, then do the following while using the VIM (VI) editor:

  1. Enter :set nu! .

To Make Line Numbers Be On Every Time You Start VIM

To make the line numbers show automatically when you edit a file with VIM, then do the following:

  1. Edit your user's profile .vimrc file or make a new .vimrc file using VIM

    vi ~/.vimrc

  2. Scroll to bottom of file >> and Go into Insert Mode by pushing i on your keyboard >> and add this line:

    set number

  3. Save and Close the .vimrc file:

    Enter :wq .

 

Feel Free To Leave A Good Comment. :)

Look around, and you may find other useful articles.

 

How To Add, Turn On, or Off Coloring To VIM (VI) Editor

 

Turning on text coloring for code syntax that the VIM (VI) editor recognizes helps immensely.  Just being able to separate the Comments from the Code is a huge help by itself.

No Colored Text Example (click to see larger image):

Vim (VI) editor non-colored text example

 

Colored Text Example (click to see larger image):

Vim (VI) editor colored text example

 

The above example was randomly chosen from a .c file on a linux server just to demonstrate the major difference.  This coloring occurs on most code or script files (php, perl, C language, HTML, bash, and many others)

This article assumes you know VIM (VI) program/software.  It is typically a standard installation on Linux or Unix based servers. At a terminal or SSH or Telnet session command prompt, simply type vi test.txt to see it in action. A graphical version, like gvim, could also be used.

Steps To Turn On Or Off The Coloring

Open the file you want to edit

vi YourFileName.extension

Enter Shift : and type syntax on, push Enter key.  If that does not work, then push ESC key, and then enter Shift : and type syntax on, push Enter key.

:syntax on

That is all. To turn off the coloring, do syntax off.

:syntax off

To Make Coloring Automatically Occur Or A Permanent Feature.

Locate the .vimrc file.  This could be in a home directory of a user, or in /etc, or locations.  Edit the .vimrc file, and add the line syntax on.  You can use the VIM editor to do this.

Do
vi .vimrc

and then scroll to the bottom and go into Insert Mode by pushing i, and type:

syntax on


Then push ESC to get out of Insert Mode, and save and exit the updated file by typing

:wq

 

What If Doing The Above Does Not Work

If you do not see the text show with colors after the above is done, then the article of Solution To VIM Not Showing Colors may provide a answer.

 

Feel Free To Leave A Good Comment. :)

Look around, and you may find other useful articles.

Solution To VIM Not Showing Colors Even When The Switch syntax Is Set To On

 

If you have already done what is indicated in the article of Add, Turn On, or Off Coloring To VIM (VI) Editor, and you still are not seeing colors, then the following will hopefully fix the issue. 

Locate your user profile file.  Two examples of file names for this file are .profile, and .bash_profile.

I expect this file to be in the home directory of your user.  If you are logged in as root, then it would be at /root.  Such as /root/.bash_profile.

With the assumption that your are logged in as root, edit the profile file (.bash_profile or .profile or other name you found or documented for your OS and/or shell) by adding the following into it:

export TERM=xterm-color vim

The above is for a Linux OS of like Centos, Fedora, and similar. 

As mentioned in the other article, make sure you have syntax on listed in your .vimrc file within your user's profile home directory; if not add it to the end of the .vimrc file.  The home directory for root is typically /root.