A quick hack for for debugging JS in Vim

1 min read Original article ↗
" If you frequently find yourself printing values to console in JS for
" debugging, add the line below to your .vimrc file. It sets you up
" so that if you do <Leader>d then whatever you had yanked to the
" default buffer will be put into a console.log statement.
" Trust me. It's hacky (and could be better written to handle quotes),
" but saves a ton of time.
"
" (For more info on leader keys, see: http://learnvimscriptthehardway.stevelosh.com/chapters/06.html)
"
" Example:
" If you had yanked `this.myVariable` and then type <Leader>d, it would
" paste the following into the next line:
"
" console.log('this.myVariable: ', this.myVariable)
"
autocmd BufEnter *.js :map <Leader>d <Esc>oconsole.log('<Esc>p$a:', <Esc>p$a)<Esc>