aligning comments; struggle with determination whether quote is part of command or not

34 views
Skip to first unread message

tasch...@posteo.de

unread,
Aug 18, 2015, 1:03:45 PM8/18/15
to Vim_use
Hello,

i want to align all those vim comments, which are not the first
non-whitespace character on the line and also not part of an command,
etc.

Example:

" aligns all quotes which are not the first character at the
beginning of the line
nnoremap <Leader>a1 :Tabularize /^\@<!" <CR>
nnoremap <Leader>a2 :Tabularize /\(^\s*\)\@<!" <CR>


=> should not match, because the comment is alone on the first line and
the second and third quote are part of the command


Plug 'flazz/vim-colorschemes' " Vim colorschemes

=> should match, the comment has non-whitespace characters before it.


trying
====
:Tabularize /\(^\s*\)\@<! "

Orginal: http://ur1.ca/nh1ac
result: http://ur1.ca/nh1as


Orginal: (first example)
result: http://ur1.ca/nh1c2


in short:
======
how can i "parse" vim scripts in a regex, to determine, if the actual
matched quote is part of a command or a comment?

Paul Isambert

unread,
Aug 18, 2015, 2:10:19 PM8/18/15
to vim...@googlegroups.com
Try this pattern (replace “othercommandshere” by, well, other
commands):

\(\(\(nnoremap\|nmap\|othercommandshere\).*\)\|^\s*\)\@<!"

or in very magic form

\v(((nnoremap|nmap).*)|^\s*)@<!"

There might be a simpler/more robust solution but that just off my
head.

Best,
Paul
Reply all
Reply to author
Forward
0 new messages