How to map keys in vim

Say you want to setup vim to have a certain key stroke, preform a desired operation You can use the map command to do this.

The file[s] to add the mappings are ~/.vimrc or /etc/vim/vimrc or you can add a map, temporarily, through vim command-line.

Basic mapping

 * Add to config file
 * map KEY_SEQUENCE OPERATION
 * Example: map  dd


 * Shift, Ctrl, Alt, Meta, Shift: 
 * Shift: 
 * Example: Shift s
 * 
 * Ctrl: 
 * Example: Ctrl s
 * 
 * Alt and Meta are the same:  
 * Example: Alt s
 *  or 

Special Characters
 * Basic
 *  through 
 * Enter:  or  or 
 * Space bar: 
 * Esc key: <Esc>


 * All Special keys
 * See: http://vimdoc.sourceforge.net/htmldoc/intro.html#keycodes

=Mapping in different modes= Keys can be mapped in all types of modes, all mapping syntaxes are the same as described above


 * Modes in vim
 * Normal mode: When typing commands.
 * Visual mode: When typing commands while the Visual area is highlighted.
 * Operator-pending mode: When an operator is pending (after "d", "y", "c", etc.). Example: ":omap { w" makes "y{" work like "yw" and "d{" like "dw".
 * Insert mode. These are also used in Replace mode.
 * Command-line mode: When entering a ":" or "/" command.
 * Lang-Arg: searching


 * mapping commands and their respective modes
 * map
 * Normal, Visual, Operator-pending
 * map!
 * Insert, Command-line
 * nmap
 * Normal
 * vmap
 * Visual
 * omap
 * Operator-pending
 * cmap
 * Command-line
 * imap
 * Insert
 * lmap
 * Insert, Command-line, Lang-Arg

Prevent recursive mapping (noremap)
You can prevent one mapping from using other map by using noremap. This is called recursion in programming

Example of a recursive mapping
 * You want the following
 * map <F5> c<Space>
 * and
 * map <Space> <PageDown>
 * But you don't want
 * map <F5>, c<Space> to turn into map <F5> c<PageDown>

To prevent this
 * Change
 * map <F5> c<Space>
 * to
 * noremap <F5> c<Space>

This works with all mapping types
 * nnoremap
 * inoremap
 * vnoremap
 * etc.