Blog @ RohitRox

tips tricks tuts and everything learned

VIM Quick Tips

| Comments

Vim quick tips and tricks, listing some useful, essential and most often used Vim commands.

Moving Around

Command Action
j or Up Arrow Move the cursor up one line.
k or Down Arrow Down one line.
h or Left Arrow Left one character.
l or Right Arrow Right one character.
e To the end of a word.
E To the end of a whitespace-delimited word.
b To the beginning of a word.
B To the beginning of a whitespace-delimited word.
0 To the beginning of a line.
$ To the end of a line.
H To the first line of the screen.
M To the middle line of the screen.
L To the the last line of the screen.
:n Jump to line number n. For example, to jump to line 42, you’d type :42
gg Goto start of file
G Goto end of file
I go to the beginning of the line and go into insert
A go to the end of the line and go into insert
Ctrl+g Show file info including your position in the file
i Insert at cursor
a Append after cursor
A Append at end of line
ESC Terminate insert mode
u Undo last change
U Undo all changes to entire line
dd Delete line
3dd Delete 3 lines.
D Delete contents of line after cursor

Windows

Command Action
:sp new window above
:vs new window to left
:q close current window
:qa close all windows add trailing ! to force
Ctrl+w {left,right,up,down} move to window
Ctrl+w Ctrl+w toggle window focus

Vi/Vim modes

Turn on autoindent: :set autoindent

Turn off autoindent: :set noautoindent

Set indent width: set shiftwidth=4 Intelligent auto-indent: set smartindent Toggle autoindent on/off when pasting text (press F2 key to toggle mode after one is in “insert” mode): set pastetoggle=

:set tabstop=8 Tab key displays 8 spaces

:set syntax on :set syntax off Set syntax highlighting and color highlighting for a file type (eg XML, HTML, C++, Java, etc). Also cursor shows matching “)” and “}” Also can set syntax highlighting explicitly: :set syntax=html Syntax definition files: /usr/share/vim/vim73/syntax/

:set number Show line number

:set bg=dark :set bg=light VIM: choose color scheme for “dark” or “light” console background.

:help Vim has a extensive on-line help system. You can access this by using :help.

:set cindent This turns on C style indentation. Each new line will be automatically indented the correct amount according to the C indentation standard.

Word Completion When your typing and you enter a partial word, you can cause Vim to search for a completion by using the ^P (search for previous marching word) and ^N (search for next match).

Comments