Question

I want to use registers value in command line and in function in GVIM.

More specificaly my goal is to ease the on-the-fly highlithing of my log file. I want to be able to hightlight by a simple command the selected string like the * touch do.

Currently I have these line in my vimrc

hi Hi1 guifg=#FFD000
hi Hi2 guifg=#FA0020
hi Hi3 guifg=#A5BB00

To highlith I write in the command line:

:syntax match Hi1 /MON_STRING/

and I obtain what I want. I would like to have a command like

noremap ,H1 :syntax math Hi1 "0

to do the same more easyly but I haven't find the right way to write "0

Any idea?

EDIT => Thanks to the answer I create the function that I was looking for:

let g:hicounter = 0
function TT(incr)
   if a:incr == 1
      let g:hicounter = g:hicounter + 1 
      let g:hicounter = g:hicounter % 18
   endif
    :exec 'syntax match Hi' . g:hicounter .'  /'.@/.'/'
    :echo "falue de incr a:incr " . a:incr . " :let  g:hicounter ="
endfunction

noremap <F3> *#:call TT(1)<CR>
noremap <s-F3> *#:call TT(0)<CR>
Was it helpful?

Solution

use execute

:exec 'your command'.@x
  • x is the reg
  • . concatenating the cmd strings

OTHER TIPS

Your approach uses :syntax match; that can interfere with the existing syntax (so sometimes, your highlighting won't match on existing syntax, or it prevents the existing syntax to properly highlight the file). For a more robust highlighting, :match / matchadd() is better (but more complex to manage).

If you're willing to install a plugin, my Mark plugin provides this functionality. (The plugin page has links to alternative plugins.)

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top