########################################################################## # Vi Notes # # Anuradha Weeraman, 23 November 2003 # # Note: This document is based on Vim by Bram Moolenaar # # $Id: vi-notes.txt,v 1.1 2004/06/02 21:17:54 anuradha Exp $ # ########################################################################## --- Count words To count words in a document, g _ To redistribute split windows evenly : = To increase the current split window by 1 row : + 5 rows... 5 + To decrease the current split window by 1 row : - 5 rows... 5 - ---------- --- Sourced scripts To find out the scripts that have already been sourced by vi : :scriptnames ---------- --- EasyVIM Vim also comes in a supposedly easy-to-use form called 'evim'. ---------- --- Explorer plugin To use the File Explorer plugin : :Explore To open the explorer in a new split window : :Sexplore You can see if the plugin has already been loaded by saying : :scriptnames If otherwise you can load it by : :runtime plugin/*.vim This will load all the plugins in the plugin directories in the 'runtimepath'. ---------- --- Vertical diffs Files can be split vertically by : :vnew # starts a new document in a vertically split window :vsplit :vertical Shortcuts New : v Resize : <, > (horizontally) +, - (vertically) ---------- --- Suspend To suspend Vim, in command mode : or :stop[!] or :supend[!] The exclamation prevents dirty buffers from being written to disk if the 'autowrite' option is set. ---------- --- Sessions To save a snapshot of what you are working right now to be restored later : :mksession # defaults to Session.vim :mksession SESSION-FILE-NAME (See also :mkvimrc) To restore it : vim -S SESSION-FILE-NAME ---------- --- Viminfo The viminfo file contains the following information : - The command line history. - The search string history. - The input-line history. - Contents of registers. - Marks for several files. - Contents of registers. - Marks for several files. - File marks, pointing to locations in files. - Last search/substitute pattern (for 'n' and '&'). - The buffer list. - Global variables. Its usually $HOME/.viminfo. Viminfo is slightly different to Session files in that it isn't focused on a particular set of files. Sessions and Viminfo can be used to customize your Vim work environment. To load a particular Viminfo file : :rviminfo! ~/.my_viminfo The ! makes sure that any marks, registers, etc that have already been set is overwritten. To write a Viminfo file : :wviminfo! ~/.my_viminfo If the ! is not specified, the new information is merged with the existing old information. These commands can be shortened to :rv and :wv respectively. ---------- --- Map To map a special key (such as function keys) to a particular action : :map GoDate: :read !datekJ You can also define mappings for other modes, such as Input mode : :imap Date: :read !datekJ Here is an overview of map commands and in which mode they work: :map Normal, Visual and Operator-pending :vmap Visual :nmap Normal :omap Operator-pending :map! Insert and Command-line :imap Insert :map! Insert and Command-line :imap Insert :cmap Command-line Operator-pending mode is when you typed an operator character, such as "d" or "y", and you are expected to type the motion command or a text object. Thus when you type "dw", the "w" is entered in operator-pending mode. ---------- --- C Editing w e b : to navigate the code { } : to jump from paragraph to paragraph [[ ]] : take you backwards and forwards in functions [] : end of previous function ][ : end of next function % : jump to the corresponding brace CTRL-] : jump to a function once tags are created CTRL-T : jump to the previous tag *note* : to make ctags ctags *.c ctags -R *.c ctags-exuberant -R m : mark a position ' : goto position CTRL-P : search backwards for autocompletion CTRL-N : search forward for autocompletion CTRL-X CTRL-F : autocomplete filenames. eg. header files :set dictionary=file CTRL-X CTRL-K : autocomplete from dictionary file :set textwidth=80 :set wrapwidth=60 :set cindent : automatically indent c code as you type vim file1 file2 file3 :n : next file :e# : previous file :split filename : open file in a split window :e filename : open a file concurrently CTRL-W CTRL-W : jump between split windows vim -q errorfile: open and position cursor on error :make : compiles program and position cursor on error :set makeprg=cc\ foo.c : if you are just compiling a single program :cn : goto the next error :cN : goto previous error ----------