Inline comments in vimrc mappings

(I asked the same question about superuser, but realized that this is not a suitable page for this question)

I clean the .vimrc configuration and notice that the mappings section is over-sparse due to some mappings containing comments (for maintainability and future references).

The problem is that you cannot add a comment to the same line as the display, because it will be interpreted as a continuation of the right side.

An example of the current state (sparse):

" Do foo nmap <Leader>f :foo<Return> " Do bar nmap <Leader>b :bar<Return> 

Desired state (wrong!):

 nmap <Leader>f :foo<Return> " Do foo nmap <Leader>b :bar<Return> " Do bar 

Is there a good way to keep a comment on the same line as the display?

+6
source share
2 answers

You can use this method, but should not include a space before | , because it will be part of the display:

 nmap <Leader>f :foo<Return>| " Do foo nmap <Leader>b :bar<Return>| " Do bar 

| separates commands in vim, so the lines above work like this:

 nmap <Leader>f :foo<Return> " Do foo nmap <Leader>b :bar<Return> " Do bar 

If you want to use | char in the map itself, see map_bar help for more information:

  *map_bar* Since the '|' character is used to separate a map command from the next command, you will have to do something special to include a '|' in {rhs}. There are three methods: use works when example ~ <Bar> '<' is not in 'cpoptions' :map _l :!ls <Bar> more^M \| 'b' is not in 'cpoptions' :map _l :!ls \| more^M ^V| always, in Vim and Vi :map _l :!ls ^V| more^M (here ^V stands for CTRL-V; to get one CTRL-V you have to type it twice; you cannot use the <> notation "<CV>" here). All three work when you use the default setting for 'cpoptions'. When 'b' is present in 'cpoptions', "\|" will be recognized as a mapping ending in a '\' and then another command. This is Vi compatible, but illogical when compared to other commands. 
+27
source

No, It is Immpossible.

From :help map-comments :

It is not possible to put a comment after these commands because the '' 'character is considered part of {lhs} or {rhs}.

+5
source

Source: https://habr.com/ru/post/972126/


All Articles