CeDeT: OUR (Often Used Reference) #5

Vi(m) Quick Key Reference

VI

USER FRIENDLY - 'SIX' EDITOR
SOURCES
Miracle
The "vi" Editor - A Survival Kit!

UserFriendly.org

Steve Oualline Home Page

Links


Quick Keys

Normal mode

Cursor movement
KeysActions
↑, ↓, ←, → Move up, down, left and right
k, j, h, l Move up, down, left and right
w, b Scroll by word foward, backward
(, ) Scroll by sentence forward, backward
0, $ Go to beginning, end of line
Ctrl+u, Ctrl+d Scroll up, down half screen
Ctrl+f, Ctrl+b Scroll forward, backward full screen
G, n G Go to last, n'th line

Deleting, copying and pasting text
KeysAction
x Delete text at cursor
dw Delete word under cursor
r Replace character under cursor
dd, yy Delete, copy line
n dd, yy Delete, copy n lines
p, P Paste after, before
J Join lines
guw Change word under cursor to lower case (vim)
gUw Change word under cursor to Upper case (vim)

Misc
KeysAction
u Undo previous command
U Undo all changes to line
n Find next, previous search pattern occurrence

Insert mode

Inserting text
KeysAction
i, IInsert text at cursor, beginning of line
a, AAppend text at cursor, end of line
o, OOpen line below, above cursor
cw Change word under cursor
Esc End insert mode (return to normal)

Command-line mode

Command modes
CommandAction
:, ! commandEnter ex, filter command
/, ? patternSearch forward, backward for pattern
EnterExecute command or search (return to normal)

Delete, copy and paste
CommandAction
:m,n d Delete lines m-n
:m,n t p Copy lines m to n, paste after line p
:m,n m p Delete lines m to n, paste after line p

Files
CommandAction
:w Write (save changes)
:w file Write to (new) file
:m,n w file Save lines m-n to (new) file
:q Quit
:wq Write and quit
:q! Force quit (discarding changes)
:e file Edit (new) file
:e! file Force edit (new) file (discarding changes)

Search and replace
Command :%s/search-pattern/replace-pattern/cg
Action Search all lines (%) globally (g) for search-pattern and confirm (c) replace with replace-pattern

Options
CommandAction
:set all Displays all options
:set noopt Toggles option (opt) off
:set nu Displays line numbers
:set ic Ignores case during search
:set showmode Displays insert mode
:set expandtab Expand to tab position with spaces, not the tab character
:set guifont=font-name:hheight-in-pts Sets the specified font (choose a monospaced one),
example (vim) set guifont=Consolas:h9
Hint
The settings you want enabled/disabled by default can be set in the vim configuration file - on my machine (for vim version 6.4) it is C:\Programmer\Vim\vim64\vimrc_example.vim