Set selective key

Often I need to search for large size xml files for the next occurrence of the word under the cursor, but preferably if it is a closing tag

In the example below, # is the cursor. Use with *

either #

a key without a key >

or <

will move between <Dealid>

and </Dealid>


... 50 lines
... n lines


I tried it :set iskeyword+=<

, which worked great for going to the next match, but it changed vey

to include the <

closing tag, so moved to the beginning 6666

, for example, and typing vey

would be yank 6666<

, not 6666


Is there anyway to get the best of both words or to restrict the iskeyword+=<

operators *

and #



source to share

2 answers

This should do what you want.

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


It sets the changes iskeyword

before executing *

or #

and then discards it.



Instead of changing, 'iskeyword'

it is possible to use visual star search . This will allow you to visually select the text and then click *

. egva<*

If you don't want to use the plugin, you can put the ~/.vimrc

following mapping in your file :

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


Note: this collation captures unnamed case, so it is probably best to use a more advanced collation or plugin .



All Articles