Skip to content

Instantly share code, notes, and snippets.

Embed
What would you like to do?
console.log in vim
" Console log from insert mode; Puts focus inside parentheses
imap cll console.log();<Esc>==f(a
" Console log from visual mode on next line, puts visual selection inside parentheses
vmap cll yocll<Esc>p
" Console log from normal mode, inserted on next line with word your on inside parentheses
nmap cll yiwocll<Esc>p
@rodrigore

This comment has been minimized.

Copy link

@rodrigore rodrigore commented Dec 4, 2013

It dosn't work for me in terminal Vim, only Macvim(Gvim).

I use instead abbreviation:
:iab cl console.log();==f(a

Thanks BTW.

@judsonmitchell

This comment has been minimized.

Copy link

@judsonmitchell judsonmitchell commented Dec 11, 2013

Great stuff! Thank you.

@jorinvo

This comment has been minimized.

Copy link

@jorinvo jorinvo commented Nov 16, 2015

Awesome! Just found this now but still helpful!
I adjusted it a little to not block c in visual mode.

imap gll console.log()<Esc>==F(a
vmap gl cgll<Esc>p
@resoliwan

This comment has been minimized.

Copy link

@resoliwan resoliwan commented Feb 10, 2017

It is awesome! Thank you.

@sergeylukin

This comment has been minimized.

Copy link

@sergeylukin sergeylukin commented Aug 21, 2019

Amazing! love the visual mode support, also inserting currently cursor-pointed variable in normal mode as param of console.log() is impressive!

@rob137

This comment has been minimized.

Copy link

@rob137 rob137 commented Jul 8, 2020

Thank you!

@cmdcolin

This comment has been minimized.

Copy link

@cmdcolin cmdcolin commented Jul 14, 2020

Here is a modified console log vim inserter

imap cll console.log({});<Esc>==f{a  

this makes it so that you have

 console.log({})

With the cursor inside the curlies, because then if you type

console.log({myvariable})

Then the console log contains

{myvariable:3}

That way you don't have to do things like

console.log('myvariable', myvariable)
@7iibob

This comment has been minimized.

Copy link

@7iibob 7iibob commented Oct 30, 2020

nnoremap gll oconsole.log("LINE: =line('.')","")F"i

Then hit gll to produce console.log("LINE: line","").

@darkmasta

This comment has been minimized.

Copy link

@darkmasta darkmasta commented Apr 1, 2021

How to run this in VSCode VIm Plugin? @nervetattoo

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment