Friday, June 12, 2009

Using vim more effectively

Like many Linux administrator, vim is an editor of choice. However, I fail to exploit the many shortcuts and tricks that make it stand-out. I will list a couple of commands of frequent use

1. Searching
Create a .vimrc in your own home directory. With this you can you place useful commands settings
set incsearch (incremental search function)
set ignorecase (ignore case-sensitive function)
set smartcase (used in conjunction with ignorecase. By default it search for any case unless the user specify uppercase character)

2. Movement from the keyboard.
h (move left)
l (move right)
j (move up)
k (move down)

3. Editing
x (delete the character under the cursor) 
y (copy the characters from the current cursor) 
p (paste previous deleted or copied text after the current cursor position) 
d (delete the characters from the cursor position)

4. File Browser and Screen
e .(To make vim act as a file browser) 
:split (To split the screen into seperate segments. Use Crtl+W and arrow keys to change screen)

5. UsingTab
# vim -p file1 file2 (2 file with tabs will show)

:tabn (next tab) 
:tabp (previous tab) 

6. Spell Check
: setlocal spell spelllang=en_us (enable spell checking)
: help spell (spell help)
]s (Go to the next misspelled word)
z= (Display suggestions for correct spelling)

Interesting Articles:
Vim Introduction and Tutorial

No comments: