如何找到(“超级明星”)光标下的单词而没有单词边界修饰符? [英] How to find ("super-star") the word under the cursor without the word boundary modifiers?
问题描述
有可能具有类似的功能,但是不带有w / o封闭的字边界括号?
更新:显然我发布这个问题太快了。看这里,有答案。
: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屋!