Vim: how to use variables in vimrc?

here is what i am trying to do, a simple function to increment a global variable. It works great.

let g:high_ind = 1 fun! IncHighlightInd() let g:high_ind = (g:high_ind + 1) %10 return g:high_ind endf 

I want to use this variable in map

 map <Ch> :call IncHighlightInd() <CR> :Highlight g:high_ind <CR> 

But g:high_ind not recognized as a variable. How to use this variable?

Or more interestingly, is it possible to do something like below?

 map <Ch> :Highlight IncHighlightInd() <CR> 
+7
variables vim
source share
1 answer

You need to use: exe or c_CTRL-R _ =:

 nnoremap <ch> :exe ":Highlight ".IncHighLightInd()<cr> nnoremap <ch> :Highlight <cr>=IncHighLightInd()<cr><cr> 

By the way, I suspect you should take a look at this page: Highlight a few words on vim.wikia.

+8
source share

All Articles