如何找到(“超级明星”)光标下的单词而没有单词边界修饰符? [英] How to find ("super-star") the word under the cursor without the word boundary modifiers?

查看:316
本文介绍了如何找到(“超级明星”)光标下的单词而没有单词边界修饰符?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

Vim的超级明星操作(搜索并突出显示光标下的单词)非常方便。但它有搜索整个词的精确匹配的限制。

有可能具有类似的功能,但是不带有w / o封闭的字边界括号?



更新:显然我发布这个问题太快了。看这里,有答案。

g * 可能是最好的解决方案,但是对于新的vim用户来说,知道这可能是多么有趣从头开始:

:nnoremap< expr> */。expand(< cword>)。/ \< CR>
$ b

map< expr> 意味着不是映射到文字键序列,而是右边是每次映射发生时评估的表达式,并且结果字符串被视为RHS一个正常的映射。
$ b $ expand(< cword>)返回一个字符串,游标和\< CR>基本上只是表示输入键。



我们得到一个到 /<在光标下的词> / 输入的映射,其中在光标下面的词不被插入,直到使用映射。

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.

解决方案

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.

这篇关于如何找到(“超级明星”)光标下的单词而没有单词边界修饰符?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆