Sunday, August 17, 2008

Vim quick reference

The following content is excerpted from http://linuxconfig.org/Vim_Tutorial. It covers most of the essentials that one needs while editing code. One thing which i know and use and is not covered is :e < filename > to open multiple files without exiting vim and then navigating among the open files using :b < num > , where num is file buffer number for the open files . Other than that, there were quite a few points in the tutorial that were really good and i did not use/know them before. Also see other good links to learn more on vi/vim at http://delicious.com/rwatsh/vi.

Vim Tutorial Summary

VIM novice level Summary

  • 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 th end of the line with d operator and $ motion
  • Using operators, motions and counts:
    beginning of th 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, begging 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 ans 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

Popular micro services patterns

Here are some popular Microservice design patterns that a programmer should know: Service Registry  pattern provides a  central location  fo...