tags:

views:

176

answers:

3

If I do either of the following two:

call search("searchString")

exec "/ searchString"

From a script, then vim does the search but does not highlight the results, even though hlsearch. Doing the same searches from outside a script highlights the results.

Thanks

A: 

You could use :set hlsearch to enable and :set nohlsearch to disable highlighting.

The MYYN
This doesn't work, hlsearch is on before the script is called, and calling it in the script also doesn't change things. Thanks for replying.
tuxjay
-1 for not reading the question
kemp
A: 

You need to put this in your .vimrc file

" Switch syntax highlighting on, when the terminal has colors
" Also switch on highlighting the last used search pattern.
if &t_Co > 2 || has("gui_running")
  syntax on
  set hlsearch
endif

The .vimrc file is usually located in your home directory, or you can find it using "locate .vimrc"

Martin Andersson
This is about scripting in vim, not turning on highlighting searches and syntax highlighting in general.
tuxjay
+2  A: 

Just found out the answer myself:

call search(l:searchString)
call matchadd('Search', l:searchString)
tuxjay
Does this allow for the normal use of n/N for next/previous match?
alesplin
yes yes yes yes
tuxjay