3

Often I need to search large xml mode files for the next occurrence of the word under the cursor but preferably not if it's a tag the closing tag

In the below example # is where the cursor is. Using * or # with iskeyword not including > or < will move between <Dealid> and </Dealid>.

<Deali#d>4444</Dealid>
... 50 lines
<Dealid>6666</Dealid>
... n lines
<Dealid>5643</Dealid>

I tried :set iskeyword+=< which worked fine for moving to the next match but it changed vey to include the < of the closing tag so moving to the start of 6666, for eg, and typing vey will yank 6666< rather than 6666.

Anyway of getting the best of both words or limit the iskeyword+=< to the * and # operators?

Steve
  • 388
  • 1
  • 3
  • 14

2 Answers2

5

This should do what you want.

nnoremap * :set iskeyword+=<<CR>*:set iskeyword-=<<CR>
nnoremap # :set iskeyword+=<<CR>#:set iskeyword-=<<CR>

It sets changes iskeyword before executing * or # and then resets it.

FDinoff
  • 30,689
  • 5
  • 75
  • 96
0

Instead of changing 'iskeyword' maybe use a visual star search. This will allow you to visually select the text and then hit *. e.g. va<*

If you don't want to use a plugin you can put the following mapping in your ~/.vimrc file:

xnoremap * y/\V<c-r>=escape(@", '\')<cr><cr>

Note: this mapping clobbers the unnamed register so it would probably be best to use a more advanced mapping or a plugin.

Peter Rincker
  • 43,539
  • 9
  • 74
  • 101
  • I had tried a visual search using * previously and didn't like it but thanks for the suggestion. I'll certainly look at the plugin – Steve Sep 25 '14 at 23:29