ex commands ----------- $HOME/.vimrc start up options /\*\*\* search for *** (note each character must be escaped) /apple\|orange find line containing apple or orange /.*apple\&.*orange find line containing apple and orange = show total number of lines .= show line number of current line 30000 goto line 30000 ab ft foot ft expands to foot e #1 go to buffer 1 e #2 go to buffer 2 Explore explore files and directories s/logout/logoff/ change logout to logoff on current line 1,$ s/abc/xyz/g replace abc with xyz globally 1,$ s/abc/xyz/gc replace abc with xyz globally with confirmation %s/abc/xyz/g same but shorter %s/^M//g remove ^M (note that to enter ^M hit CTRL-V and hold CTRL and press M) 15,329 w goop.txt write range of lines to goop.txt 20,40 d delete range of lines 1,$!sort sort lines r goop.txt insert goop.txt into file r !date insert date into file args Show list of arguments as give ASCII code for character under cursor buffers show buffers bp previous buffer bn next buffer digraph show digraphs nohl turn off highlighting set all show all options set wm=0 set wrap margin to 0 set textwidth=90 set text width to 90 characters set ic set ignore case on set nu show line numbers set nonu turn off line numbers set ruler show ruler set noruler turn off ruler set encoding=utf-8 sets encoding to utf-8 set digraph turn on digraphs split split window hortizontally split file.txt split window, new window contains file.txt vsplit split window vertically syntax on turn on colours syntax off turn off colours g/^/mo0 reverse order of lines g/abc/d delete all lines containing abc 300,$ g/garbage/d delete from line 300 to end of line all lines matching garbage map! gatt General Agreement on Tariffs and Trade unmap! gatt ve display version information w !ispell -a spell check w! text.txt write file text.txt and overwrite if necessary w! ~/text.txt write file text.txt into the home directory with overwrite visual commands --------------- ~ toggle lower to upper case (or vice versa) and advance cursor `` move cursor back to previous position . repeat last command 6. repeat last command 6 times dG delete to end of file d1G delete from beginning of file to cursor dH delete from beginning of screen to cursor dL delete up to last line on screen dd delete current line d$ delete to end of line fc find a character, e.g. fc finds first c on current line G go to the last line 10G go to line 10 g?g? Rot13 entire current line H home cursor to top left of screen h j k l move cursor left, down, up, right respectively 100ihello insert hello 100 times R edit in typeover mode, esc to exit Q go into ex mode (vi returns to visual mode) u undo last command xp transpose two letters yy yank one line yG yank from cursor to end of file zt redraw window with current line at top 3zt redraw window with line 3 at top ctrl-g display filename, line number and percentage in file ctrl-h backspace ctrl-R redo last command ctrl-v set visual block, use cursor keys to resize ctrl-f page forward ctrl-b page backward ctrl-u scroll up ctrl-d scroll down ctrl-w v ctrl-w then hit v, makes window split vertically ctrl-w s makes window split hortizontally ctrl-w c close current window ctrl-w w jump to next window ctrl-w n split with new buffer ctrl-X subtract one from number under cursor ctrl-A add one to number under cursor (ctrl-a also works) \si invoke ispell (must be in ~/.vimrc) recording macros ---------------- hit q then m (this will map the macro to @m) o for insert type some stuff esc to end insert mode hit q to stop recording macro is used by typing @m files ----- /etc/vimrc ~/.vimrc command line ------------ vim -g start in graphics mode vim -R read only mode vim -r list swap files for possible recovery vim --version show version vim test.txt +/\lobby edit file test.txt putting cursor on first occurrence of lobby vim -O3 f1.txt f2.txt f3.txt edit 3 files each in a vertical window view file view file in read only mode When using ssh -------------- Sometimes when using ssh vi will work differently, that is the backspace key will only backspace and not delete. Use the del key instead.