Thursday, December 30, 2010


Vim Text Editor

  • On every platform
  • 100% keyboard driven
  • Text surgery
  • powerful editing
  • Local and remote
  • Highly configurable
  • Extendable with plugins
  • Mac-friendly
  • Great Documentation
  • Long-terms skills
  • Undesirable defaults
  • Clunky scripting Language
  • Destructive tasks are too easy
  • Inconsistent regular expressions
Started in 1976 then 1991 and now it is called VIMproved (VIM)

Main modes of VI editor
  1. Normal
  2. Insert
  3. Visual
  4. Replace
  5. Command-line
Upper case commands are super sized versions of the lower case commands

i - Inserts text starting from the cursor
I - Inserts text starting from the beginning of the line.
w - moves forward one word
3w - moves forward 3 words
b - moves backware one word
W - moves contiguous code as one word and move forward to the next meaningful word
dd - deletes the line where the cursor is located
dw - deletes the word
d2w - delete two words
G - goes to the end of the file
gg - goes to the start of the file
:w - write file (save)
:w! - write without confirmation
:q! - quit vim
:wq! - write and quit
:e filename - opens a file to edit
code folding command starts with a z
cw - change word
3cw - change three words
:h - help:bd - buffer delete

yy - yank line (copy)
Y - yank line (copy)
p - paste below cursor
P - paste above cursor
a - append text after cursor
6l - Forward six letters
2j - Down two lines
fN - Jump forward to the first 'N'
3fN - Jump forward to third 'N'
n- Next 

u - undo
Ctrl+R - redo

vim -N (-N compatible with the latest version only)

Vim comes with 500 different syntax highlights.

:syntax enable
:set syntax=apache

:set hidden
:set syntax=python
:set syntax=cpp

:w !sudo tee %

:set incsearch
:set hlsearch

Search and replace


  % search the current buffer
  g - search for all occurance
  c - ask for confirmation on each match

e.g :%s/2.\2\.8/2.2.9/gc - this will replace all 2.2.8 occurances to 2.2.9 and will confirmation all occurances.

:set number
12G - go to line 12

:cd path
:e . - to find out the files in the directory

V - visual mode

:b name - Switch to buffer (try TAB and arrows as well)
:bp - Previous buffer

:set autochdir - Automatically use the current file's directory as the working directory

Check out the vim-rooter plugin.

:set wildmode=list:longest - Activate TAB auto-completion for file paths.

Directory listing.

i - thin, long, wide or tree listings
s - sort on name, time or file size
r - Reverse sort order
gh - Hide or unhide dot files
- Open the file or directory
x - View file with associated application
d - Make directory
D - delete the file or directory
R - Rename the directory or file
- <-- Go up a directory

Window Management

Ctrl+w s - split window horizontally
Ctrl+w v - split vertically
Ctrl+w j - Move focus down
Ctrl+w k - Move focus up
Ctrl+w h - Move focus left
Ctrl+w l - Move focus right

Ctrl+w J - Move buffer up one window
Ctrl+w K - Move buffer down one window
Ctrl+w H - Move buffer left one window
Ctrl+w L - Move buffer right one window

Ctrl+w c - Close window
Ctrl+w o - Close all but current
Ctrl+w w - Cycle focus
Ctrl+w p - Focus previous window

No comments: