Working efficiently with VI / VIM

vi or vim

for redhat based systems this doesn’t in any ways pose a difference as both vi and vim are on and the same thing (for more technical vi is aliased to vim).

but if you go to the other variants like debian or slackware these two software do show a difference in terms of evolution vi is what vi was and vim is what we always wanted vi to be.

so here I am presenting some more tips and tricks for better working inside vim

NOTE : most of these option work only in the command mode of vim until and unless explicitly specified

1) :sp <file_name>

split window splits the active vim window into two parts ….. if <file_name> is specified then in that case that particular file is being opened in the other half otherwise the same file is opened…….

2) this split windows can be easily managed by use of CTRL+W

3) :! <command>

this is a very useful option if you don’t want to leave the vi window and yet wish to work on command line for some help or other thing.

4) :set nu

this option can be a real timesaver when looking for errors

this gives number to each other.

5) :set ai

real timesaver for the programmers ai stands for auto indentation and not artificial intelligence 🙂

6) :set tabstop=x

this yet is a programmers help ,

let you specify the  tab stopping which is by default 8 spaces

which can now be changed to x spaces

7) .vimrc The default config for your regular sessions.

if you wish to keep some options as constants what you can do is that you can just put all your general commands in a script file at ~/.vimrc………….

8 )  / for forward searching and ? for reverse searching….

9) most of us who are familiar with vi learned dd yy p and the basic commands

but P is also a paste facility with just one difference…..

when you use p you paste below the current line while P paste above the current line……..

10) sometimes you don’t want to change the binary data in a file or you have to work on binary files try

vim -b <file_name>

11)

we usually go on undoing stuff with “u” but what for redo….

CTRL + R is for the rescue…….

besides these if you are a programmer then you can leave aside the conventional “no file extension also works philosophy” asides just because this gives you a upper edge in vim with a proper syntax highlighting.

I HOPE THESE TIPS HELP YOU SOMEDAY

4 thoughts on “Working efficiently with VI / VIM”

  1. yup u r so correct these commands helps a lot ……………………and please these commands are usefull not for someday it can be used in day today basis , for making vi easy
    but its good that u r giving these commands in public to help person understand more about linux vi.

    carry on ….

  2. :r!COMMAND — read output from command into document. (Example: :r!ls /etc — import a list of the files from the /etc directory into the document at the current cursor location)

    !MOVEMENT COMMAND — replace lines enclosed by movement by filtering them through a command. (Example: {!}sort … move to beginning of a “paragraph” ({ command) … start the “bang” command (!), enclosing through the end of the “paragraph (} command) [at this point vi prompts you for the command using a bang sign at the bottom of the screen, similar to the : prompt). This example is handy for sorting a list of lines separated from the surrounding text by blank lines — which count at paragraph separators by default. Another example would be !}fmt — reformat from the cursor to the end of the current paragraph). (Another example: 1GyGGp!Gwc — append the output that wc would give on the current file at the end of the file. 1GyGGp — copies the whole document, appending the copy to the end and leaving the cursor between the two copies. Then the !Gwc simple filters the copy through the wc command).

    mLETTER — mark a place (valid marks are any single letter)
    ‘LETTER — move/return cursor to marked line
    `LETTER — move/return cursor to specific character at which the mark was made (same line *and* same place within that line)

    “LETTERyMOVEMENT — yank a copy of some text into a named register (each letter is a valid named register). (Example: “xy/foo — copy text from cursor to the first line matching the search for “foo” into the register named “x”) (NOTE: d can cut text into the register, y copies it).
    “LETTERp — paste contents of named register into the document. (Example: “xyyG”xp … yank a line into the “x” register, go to end of the document, paste a copy there. That’s the same as yyGp except that it leaves a copy of the line in the x register for later use)

    @LETTER — execute the contents of the register as if they were vi commands. (Example: :r!locate somefile[Enter]I:r [Esc]”cyy@c — read in the results of a locate command on “somefile, insert the :r command at the beginning of the resulting full path to that file, yank this line into the “c” register, then execute the contents of that register into the file at the current cursor location.

    As shown in the last example, you can combine a few of these into a very efficient way to locate a file on your system, and insert its contents into a file that you’re editing.

    When I teach Linux sysadmin classes I normally present a brief section on these features. Normally my students are advanced UNIX admins who have been using vi on a daily basis for several years (the classes are for teams who are migrating to the new platform). Almost all of my students have learned at least one new trick from that 20 minute “power tips” session.

    None of these are vim specific … they all work on any reasonably good copy of vi.

  3. Caleb Whitesides

    This is a outstanding blog post, I discovered your site searching yahoo for a similar subject matter and arrived to this. I couldnt get to much additional info on this posting, so it was wonderful to find this one. I will likely be returning to check out some other articles that you have another time.

Leave a Comment

Your email address will not be published. Required fields are marked *

Scroll to Top