Skip to content

Instantly share code, notes, and snippets.

@jcmuller
Created August 9, 2011 14:59
Show Gist options
  • Save jcmuller/1134279 to your computer and use it in GitHub Desktop.
Save jcmuller/1134279 to your computer and use it in GitHub Desktop.
Useful vim key mappings
""""""""""""""""""""""""
" Useful maps
""""""""""""""""""""""""
" Map <C-L> (redraw screen) to also turn off search highlighting until the
" next search
nnoremap <C-L> :nohl<CR><C-L>
" Don't use arrow keys
map <up> <nop>
map <down> <nop>
map <left> <nop>
map <right> <nop>
nmap <Leader>a :Ack
" Run ack against the visually selected text
nmap <Leader>A vaw"ay:Ack <C-R>a
" Automatically add closing ( { [ ' " `
inoremap {<cr> {<cr>}<ESC>kA<CR>
inoremap { {}<ESC>i
inoremap ( ()<ESC>i
inoremap [ []<ESC>i
au FileType html,vim,xhtml,xml inoremap < <lt>><ESC>i| inoremap > <c-r>=ClosePair('>')<CR>
" Search
noremap ;; :%s:::g<Left><Left><Left>
noremap ;' :%s:::gc<Left><Left><Left><Left>
" Select previously pasted text
nnoremap <expr> gp '`[' . strpart(getregtype(), 0, 1) . '`]'
" Emacs motion commands
noremap! <C-A> <Home>
noremap! <C-E> <End>
cnoremap <C-K> <C-U>
noremap! <C-F> <Right>
noremap! <C-B> <Left>
" Saving quicker
" Normal mode
nnoremap ;w :w<cr>
" Insert mode: Ctrl-S
inoremap <C-S> <Esc>:w<cr>i
""""""""""""""""""""""""""""""""""""""""""""""""""""""""""
" Search visually selected text
""""""""""""""""""""""""""""""""""""""""""""""""""""""""""
vmap * :<C-u>call <SID>VSetSearch()<CR>/<CR>
vmap # :<C-u>call <SID>VSetSearch()<CR>?<CR>
func! s:VSetSearch()
let temp = @@
norm! gvy
let @/ = '\V' . substitute(escape(@@, '\'), '\n', '\\n', 'g')
let @@ = temp
endf
Copy link

ghost commented Jul 10, 2020

can you map newtabe?

@IamJimbus
Copy link

IamJimbus commented Jul 20, 2023

I'd be interested in your thought on html tags like
<div class="container">
<div class="row">
<div class="col-12">
I'm thinking:
<dd
<dr
<dc

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment