Easily print-debug any text object in Vim
vim, linux
First things first, dependencies:
And add this to your vim config:
VIM
function! LogInline(text)return 'console.log(' . a:text . ')'endfunctionfunction! LogBelow(text)let endPos = g:TextTransformContext['endPos']let lineNumber = endPos[1]call append(lineNumber, split('console.log(' . a:text . ')', "\n"))endfunctioncall TextTransform#MakeMappings('', '<Leader>l', 'LogInline')call TextTransform#MakeMappings('', '<Leader>L', 'LogBelow')
Examples
First lets try doing an inline log.
JS
"hello world"
JS
console.log("hello world")
Next we'll log an existing variable.
JS
const myvar = "hello world"console.log(myvar)
It even works on more complex text objects like HTML
JS
<div><p>hello</p></div>console.log(<div><p>hello</p></div>)
Hopefully this saves someone's fingers.
Subscribe