[Mirrored from http://www.iol.ie/~padraiga/vim.tips, with thanks to Padraig Brady.] ---------------------------------------------------- Essential VIM ---------------------------------------------------- If you have the X Window System and are transitioning from Windows, I would recommend nedit instead of vim; alternatively you could use gvim, which is the graphics mode version of vim, which is easier to use. If you're stuck with text mode access, then vim is probably the best alternative, so you need this info (all of which applies to gvim also). vim file +54 opens file and positions cursor on line 54 Insert enter insert mode (so you can start typing) Esc leave insert mode (so you can issue commands) Note in VIM the cursor keys & {Home,End,Page{up,down}} and Delete and Backspace work as expected in any mode, so you don't need to go back to command mode nearly as much as the origonal vi. Note most commands take an optional number (of times to run) on front (e.g. 3. repeats the last action 3 times, or 3w moves forward 3 words etc.). :command runs named command, e.g :help :e file opens the file for editing :n when multiple files open, this moves to next file :prev when multiple files open, this moves to prev file :w save file :w filename save file as filename :q exit u undo CTRL+r redo . repeat gg Goto start of file G Goto end of file :54 Goto line 54 80| Goto column 80 CTRL+g Show file info (including your position in the file) w Goto next word b Goto previous word [{ Goto previous { of current scope % Goto matching #if #else,{},(),[],/* */ (must be one on line) v select visually (use cursor keys, home, end etc.) SHIFT+v line select (CTRL+v = column select) Delete cut selection CTRL+c copy selection p paste (after cursor (P is before)) gq reformat selection (useful with :set textwidth=70 (80 is default)) > indent selection (useful with SHIFT+v%) < unindent selection (remember . to repeat and u to undo) /regexp searches forwards for regexp (? reverses direction) n repeat previous search (N reverses direction) * searches forward for word under cursor (# reverses direction) :%s/1/2/gc search for regexp 1 and replace with 2 in file (c = confirm change) :s/1/2/g search for regexp 1 and replace with 2 in visual selection :%!filter put whole file through filter :!filter put visual selection through filter :,!command replace current line with command output You can put any command line commands, i.e. those starting with : in your ~/.vimrc (without the leading colon). This is especially useful for vi configuration options. I like to use the following (mainly whitespace handling) options when programming. They set the tab stop to 4, and always insert spaces rather than hard tabs. set nocompatible syntax on set background=dark #should be vim default IMHO set autoindent set softtabstop=4 set expandtab set shiftwidth=4 set shiftround set nojoinspaces