Skip to content

Instantly share code, notes, and snippets.

@summivox
Last active December 12, 2015 08:38
Show Gist options
  • Save summivox/4745235 to your computer and use it in GitHub Desktop.
Save summivox/4745235 to your computer and use it in GitHub Desktop.
VIM mapping for quick replacing of keyword under cursor
" quick refactoring: replace keyword under cursor
" `<leader>s`: main mapping
" `<SID>R`: arbitrary local mapping
" stores original position into `s before action
function! My_refactor(prefix)
return ':' . a:prefix . '%s/\<' . @" . '\>//g'
endfunction
nnoremap <special> <expr> <SID>refactor My_refactor('')
nmap <special> <leader>s msyiw<SID>refactor<left><left>
" delete trailing space in all lines
nnoremap <silent> <leader>dt :%s/\s\+$/<CR>:noh<CR>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment