How to find (“super-star”) the word under the cursor without the word boundary modifiers?

删除回忆录丶 提交于 2019-12-11 05:33:17

问题


Vim's "super-star" operation (search and highlight for the word under the cursor) is super-handy. But it has the limitation of searching for the exact match of the whole word.

Is it possible to have similar functionality, but w/o the enclosing word-boundary brackets?

Update: Apparently I was too quick to post the question. Looking here, there's the answer.


回答1:


using g * is probably the best solution, but for new vim users it might be interesting to know how this could be done pretty much from scratch:

:nnoremap <expr> * "/".expand("<cword>")."/\<CR>"

map <expr> means that instead of mapping to a literal key sequence, the right-hand side is an expression that is evaluated every time the mapping occurs and the resulting string is treated like the RHS of a normal mapping.

expand("<cword>") returns a string containing the word under the cursor, and "\<CR>" basically just means the enter key.

So in the end we get a mapping to /<word under cursor>/enter, where the word under cursor isn't inserted until the mapping is used.




回答2:


Answer is in this page: Instead of pressing *, use g*.



来源:https://stackoverflow.com/questions/47063402/how-to-find-super-star-the-word-under-the-cursor-without-the-word-boundary-m

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