Skip to content

Instantly share code, notes, and snippets.

@nbardiuk
Last active January 30, 2020 21:09
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save nbardiuk/58d342e085f4f1ad2fa4d193097526e6 to your computer and use it in GitHub Desktop.
Save nbardiuk/58d342e085f4f1ad2fa4d193097526e6 to your computer and use it in GitHub Desktop.
Vim escape javascript string
" paste escaped java/javascript string
nmap <leader>jp :call setreg('e', json_encode(@+))\| normal "ep<CR>
xmap <leader>jp :<C-U>call setreg('e', json_encode(@+))\| normal gv"ep<CR>
nmap <leader>jP :call setreg('e', json_encode(@+))\| normal "eP<CR>
" yank unescaped java/javascript string
xmap <leader>jy :<C-U>execute 'normal! gv"ey'\| :call setreg('+', json_decode(@e))<CR>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment