ex commands ----------- $HOME/.vimrc start up options /usr/share/vim/vimrc system wide options %le remove all spaces from the beginning of every line "+yy yank to x windows clipboard /something search for something use n to search for next match use N to search for previous match /\*\*\* search for *** (note each character must be escaped) /\capple case insensitive search for apple /apple\|orange find line containing apple or orange /.*apple\&.*orange find line containing apple and orange %s/\\//g delete all backslashes from file = show total number of lines 30000 goto line 30000 ab ft foot ft expands to foot e #1 go to buffer 1 e #2 go to buffer 2 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) s/ /, /g replace space with comma for every occurrence in line :1,320s/^/start / add 'start ' to the beginning of all lines 1 through 320 15,329 w goop.txt write range of lines to goop.txt 20,40 d delete range of lines help sort get help on sort 50,60 sort u sort range of lines 1,$!sort sort lines r goop.txt insert goop.txt into file r !date insert date into file r !ls insert output of ls 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 syntax off turn off syntax hilighting 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 encoding=iso-8859-1 sets encoding to iso-8859-1 set digraph turn on digraphs set linebreak for text files with long lines split split window hortizontally split file.txt split window, new window contains file.txt vsplit split window vertically tabn switch to next tab tabp switch to previous tab g/^/mo0 reverse order of lines g/abc/d delete all lines containing abc g~~ toggle case for current line map! gatt General Agreement on Tariffs and Trade unmap! gatt 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 format line length to 80 characters ----------------------------------- set vim for 80 character lines: :set tw=80 then, highlight the line: V and make vim reformat it: gq visual commands --------------- ctrl-l redraw screen ~ 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 G go to the last line 10G go to line 10 10J join 10 lines together g?g? Rot13 entire current line 3gt switch to third tab gt switch to next tab gT switch to previous tab ga get ascii value of character under cursor H home cursor to top left of screen 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 select area then hit y (yank) move cursor to target area and hit p (paste) ctrl-d page down ctrl-u page up 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 while in insert mode -------------------- ctrl-v ctrl-h adds ascii 08 ctrl-q ctrl-h same 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 for sane colours in vim in .vimrc colorscheme elflord 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 -x test-001.txt automatically encrypt file test-001.txt 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.