Keep on loggin' in the free world
It's a plugin aiming to help us developers to save time in writing all that console.log
;)
This goal is pursue basically adding a couple of mappings for you.
At the moment, only JavaScript
and TypeScript
environments are supported, but in the future it's not excluded support for other languages.
Variable | Type | Default Value | Meaning |
---|---|---|---|
g:lognroll#enable_insert_mode | number | 1 | Define wether the mappings should be active also in insert mode or not |
g:lognroll#enable_brackets | number | 1 | Define wether the variable should be logged inside curly brackets or not |
g:lognroll#lognroll_js_console | string | 'console' | Define the console function to call |
g:lognroll#lognroll_js_actions | string[] | [ 'log', 'info', 'warn', 'error' ] | Define the method of the console the user wants to map |
One of the core concept behind this plugin, is to expose mnemonic key combination.
For this reason, every mapping, both in INSERT
and NORMAL
mode, begin with:
co
, that stands for console
Followed by the action you want to perform, in a vimish way. So, for example, in case of log
:
l
, that stands for log
Therefore the complete mapping will be:
col
By default, you will find 4 levels of logging for JS: log, info, warn, error
, which bring these mappings:
col
, console.logcoi
, console.infocow
, console.warncoe
, console.error
INSERT
mode, just add this line to your .vimrc
:
let g:lognroll#enable_insert_mode = 0
By default, the variable will be surrounded by curly brackets, for example, if you have the cursor on the word dumbString
, and type col
, the variable will be logged one line below, like this:
const dumbString = "I'm a string";
console.log({ dumbString })
.vimrc
:
let g:lognroll#enable_brackets = 0
Yes.
Maybe you don't want to rely on default console, and you prefer tools like PinoJS
. Well, just specify in the .vimrc
the name of the console you want to use like this:
let g:lognroll_js_console = 'pino'
Now typing col
will produce the following output:
pino.log({ dumbString })
Yes.
If you want to use also console.dir()
besides the default methods, you just have to enumerate in the .vimrc
all the methods you want to use, like this:
let g:lognroll_js_actions = [ 'log', 'info', 'warn', 'error', 'dir' ]
Now typing cod
will produce the following output:
console.dir({ dumbString })
let g:lognroll_js_actions = [ 'dir' ]
will leave you with only the cod
mappings, and nothing else. Be sure to enumerate all the methods you want to use.
Also, be aware that all the new methods you add will have as mappings the same root of default ones co
, and the first letter of the method as ending. So, if you add table
to lognroll_js_actions
, the mapping will be:
cot
Yes.
While col
will log only the word
you are on, cola
will log all the arguments of the function. The result will be the following:
function sum(a, b) {
return a + b
}
console.log({ a, b })
yi(
, that yanks everything inside the brackets.
Yes.
The following is the table of the available <Plug>
command:
Plug command | Mode | Default Map |
---|---|---|
(lnr_insert_log) | insert |
col |
(lnr_insert_info) | insert |
coi |
(lnr_insert_warn) | insert |
cow |
(lnr_insert_error) | insert |
coe |
(lnr_normal_log) | normal |
col |
(lnr_normal_info) | normal |
coi |
(lnr_normal_warn) | normal |
cow |
(lnr_normal_error) | normal |
coe |
(lnr_normal_logargs) | normal |
cola |
(lnr_normal_infoargs) | normal |
coia |
(lnr_normal_warnargs) | normal |
cowa |
(lnr_normal_errorargs) | normal |
coea |
For example, If you want to remap the mapping in NORMAL
mode for console.log
from col
to ll
, add this line to your .vimrc
:
nmap ll <Plug>(lnr_normal_log)
console.dir
, the <Plug>
function will be:
(lnr_normal_dir)
becasue:
lnr
stands forlognroll
and is always the first wordinsert
ornormal
, specify theMODE
you want to map- the last word is the name of the console method you are calling, so
log
,warn
etc.
At the moment, only JavaScript
and TypeScript
(also *.jsx
and *.tsx
), but I think that in some basic way, this plugin could be extended to other languages too.
Contributions are welcome!
If you want to add support for a specific language, just add an issue with some details about the ideas and the goals you have, and don't hesitate to open a pull request. As soon as I can, work and life permitting, I will check it out.
The only constraint is to follow the same mnemonic way of defining mappings, possibly starting with co
.
-
Vundle, add the following line to your
~/.vimrc
:Bundle 'glippi/lognroll-vim'
$ vim +'PluginInstall! lognroll-vim' +qall
-
vim-plug, add the following to your plugin section:
Plug 'glippi/lognroll-vim'
$ vim +PlugInstall
-
NeoBundle, add the following line to your
~/.vimrc
:NeoBundle 'glippi/lognroll-vim'
$ vim +NeoBundleInstall +qall
-
Pathogen, execute the following in your shell:
$ cd ~/.vim/bundle
$ git clone https://github.com/glippi/lognroll-vim.git
If you are not using a package manager, download the tarball and execute the following steps:
$ cp lognroll-vim-master.tar.gz ~/.vim
$ cd ~/.vim
$ tar --strip-components=1 --overwrite -zxf lognroll-vim-master.tar.gz
$ rm lognroll-vim-master.tar.gz
Copyright (c) Gabriele Lippi. Distributed under the same terms as Vim itself. See :help license
.