- Check if the vim version support plugin and script.
- Check if the directory
~/.vim/pluginexists.
curl -LO https://raw.githubusercontent.com/riku-ri/valign.nvim/main/plugin/valign.vim --output-dir ~/.vim/plugin- lazy.nvim
{"riku-ri/valign.nvim"}
Or any other similar plugin manager. Just add the full repository name without any options.
- In visual mode, select lines to be aligned
- Type
:to go into command mode with selected range, now the command line in vim should be with range, i.e. shows:'<,'>. In the next step, just type command after it - Run command for the range :
The indent at the head of each line should always be ignored, all words will be aligned as no indent and insert the indent later.
Valign: align all words splited by white spaceVsqueeze: make all words splited by single space character
This plugin has a basic syntax-align command Vsyntax0.
It groups each word splited by white space by thier syntax code
i.e. synID() :
synID()is0synID()is not0
And then align each group.
For C language code blocks :
int i = 8 * anot ;
static unsigned short cs = 26 + 8 - anot ; /**/
inline char gzjsyldpr[] = "uieiuhiongaiaoe" nocat ;In some version of (neo)vim,
C language operators were assigned to syntax code 0.
So :'<,'>Vsyntax will generate :
int i = 8 * anot ;
static unsigned short cs = 26 + 8 - anot ; /**/
inline char gzjsyldpr[] = "uieiuhiongaiaoe" nocat ;Here = * + is assigned to syntax code 0
so they were grouped with variables together.
And strings/numbers after them were another group
so they were at another align.
And if operators are set to cOperator highlight group :
:syntax match cOperator "?\|+\|-\|\*\|;\|:\|,\|<\|>\|&\||\|!\|\~\|%\|=\|)\|(\|{\|}\|\.\|\[\|\]\|/\(/\|*\)\@!":'<,'>Vsyntax will generate the expected block :
int i = 8 * anot ;
static unsigned short cs = 26 + 8 - anot ; /**/
inline char gzjsyldpr[] = "uieiuhiongaiaoe" nocat ;Follow strdisplaywidth() directly.
:help strdisplaywidth() for more ditailes.