My most-used command in Vim is <Leader>cp
: it add a new line with console.log('var', var)
with the var
at the cursor position.
Simply add this to your .vimrc
:
imap <Leader>cp oconsole.log('p$a', p$a)
nmap <leader>cp yiwi<Leader>cp
vmap <leader>cp yi<Leader>cp
Alternative to log multiple vars at once as an object (useful for function parameters in visual mode):
imap <Leader>co oconsole.log({ p$a })
nmap <leader>co yiwi<Leader>co
vmap <leader>co yi<Leader>co
I have a similar command for pp in Ruby.