views:

807

answers:

1

Hello,

here what I am trying to do, a simple function to increment a global variable. It works fine.

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 a map

map <C-h> :call IncHighlightInd() <CR> :Highlight g:high_ind <CR>

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

Or more interesting, is it possible to do something like:

map <C-h> :Highlight IncHighlightInd() <CR>
+5  A: 

You have to use :exe or c_CTRL-R_=:

nnoremap <c-h> :exe ":Highlight ".IncHighLightInd()<cr>
nnoremap <c-h> :Highlight <c-r>=IncHighLightInd()<cr><cr>

BTW, I suspect you should have a look at this page: Highlight multiple words on vim.wikia.

Luc Hermitte