Monday, August 9, 2010

Learn VIM in 15 mins :)


Vim although looks scary seems to be a handy tool if you just master it. I found the most used commands and just pointing them out so it would be easier for any to start working with vim right away......


Opening a VIM File

In the terminal type :: vim xxxxx.txt

THe filename xxxxx will be opened from vim. If you havenot installed vime, you may install by typing, ' sudo apt-get install vim '

VIM Basics ...

Moving around with cursor:
h key = LEFT, l key = RIGHT, k key = UP, j key = DOWN
Exiting vim editor without saving:
press ESC to get into command mode, enter :q! to exit.
Deleting characters in vim command mode:
delete with x key
Inserting / appending text:
Press i or a in command mode and type
Saving changes and exit:
in command mode :wq or SHIFT+zz



VIM Operators and Motions summary

Deleting words:
delete word with d operator and w or e motion
Deleting to the end of the line:

delete to the end of the line with d operator and $ motion
Using operators, motions and counts:

beginning of the line 0, end of the line $, end of the 2nd word 2e beginning of the 4th word 4w
Deleting multiple words:

to delete 3 words you would use d3w
Deleting lines:

to delete single line dd, delete n lines ndd
Undo changes:

undo changes with u



VIM apprentice user summary

Paste command:
paste your cache memory with p command
Replace characters:

rt replace current character with t
Change characters:

ce to change single word, c$ to change to the end of the line



VIM experienced user summary

Advanced Navigation:
end of the file G, beginning of the file gg or 1G, to get on line n use nG instruct vim display file information CTRL+g
Search text with vim:

search forward /, search backward ?, next search n , previous search N
Vim Substitution :

- first occurrence single line :s/bash/perl/
- all occurrences single line :s/bash/perl/g
- first occurrence between line range: :23,100s/bash/perl/
- all occurrences between line range: :23,100s/bash/perl/g
- first occurrence in whole text: :%s/bash/perl/

- all occurrences whole text: :%s/bash/perl/g VIM veteran user summary

Execute external commands on shell from vim:

:!ls will execute ls command on your shell
Writing to files advanced:
:w saves current file without quit, :w bash.sh whites to file bash.sh
Highlight text and save to different file:

highlight text with v operator and save it with :w
Retrieve text from different file:
:r will retrieve content of file



VIM expert user summary

Using o operator:
:o insert line bellow you cursor, O inserts line above your cursor
Copy and paste:

yank line with y and paste it with p
Customize vim's environment:

edit ~/.vimrc file to customize vim's environment




Hope this summary works !! For more information have a look at [1]

[1] http://www.linuxconfig.org/Vim_Tutorial







No comments:

Post a Comment