Vim command to format objects

Vim has a simple shortcut (or plugin) that can help with code formatting as follows:

var obj = {
    one: 1,
    two: 2,
    three: 3,
    four: 4
};

in it?

var obj = {
    one    : 1,
    two    : 2,
    three  : 3,
    four   : 4
};
+4
source share
2 answers

There are several alignment plugins that can handle such problems very easily:

https://github.com/junegunn/vim-easy-align

https://github.com/godlygeek/tabular

https://github.com/vim-scripts/Align

I personally use the latter (maybe the oldest?). for your need, I just V select these lines and <leader>t:done!

+3
source

vim. , ctrl-V ( V), :

:s;\v^(\s*)(\w+)\s*:\s*(\d+,*);\=printf("%s%-7s: %s", submatch(1), submatch(2), submatch(3));g

:s :'<,'>s - .

0

All Articles