Skip to content
dougireton edited this page Nov 20, 2012 · 6 revisions

Key mappings

Exit Insert mode

kj  exit Insert mode

Make 'Y' yank from cursor pos to EOL

map Y y$			" Make 'Y' yank from cursor pos to EOL. This
			" makes 'Y' consistent with 'D' which deletes
			" from cursor pos to EOL.

Go visual

nmap gV `[v`]		" Visually select the text that was last
			" edited/pasted. From
			" http://vimcasts.org/episodes/bubbling-text/

Make it easier to switch between windows

From here: http://vimcasts.org/episodes/working-with-windows/

map <C-h> <C-w>h
map <C-j> <C-w>j
map <C-k> <C-w>k
map <C-l> <C-w>l

Use ^p and ^n to navigate and filter command-line history

From Practical Vim by Drew Neil, Tip 34

cnoremap <C-p> <Up>
cnoremap <C-n> <Down>

Repeat the last :substitute command and preserve flags

From Practical Vim by Drew Neil: 'Repeat the previous substitute command'

nnoremap & :&&<Enter>
xnoremap & :&&<Enter>

Swap mark motion commands to jump to mark's line and col with right pinky

See http://items.sjbach.com/319/configuring-vim-right

nnoremap ' `
nnoremap ` '

Paste fully-qualified path of current file into the command window

This is useful with ex commands like :write, :edit, etc. From Practical Vim by Drew Neil, pg 94

cnoremap <expr> %% getcmdtype() == ':' ? expand('%:h').'/' : '%%'

Delete trailing whitespace

nnoremap <silent> <leader>dw :call Preserve("%s/\\s\\+$//e")<CR>

Re-indent entire file

nnoremap <silent> <leader>= :call Preserve("normal gg=G")<CR>