Set iskeyword selectively

一笑奈何 提交于 2020-01-01 15:55:30

问题


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?


回答1:


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.




回答2:


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.



来源:https://stackoverflow.com/questions/26007655/set-iskeyword-selectively

标签
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!