Vim:获取光标下语法元素的内容 [英] Vim: Get content of syntax element under cursor

查看:26
本文介绍了Vim:获取光标下语法元素的内容的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我在一个突出显示的复杂语法元素上,想获取它的内容.你能想到什么方法来做到这一点吗?

I'm on a highlighted complex syntax element and would like to get it's content. Can you think of any way to do this?

也许有某种方法可以搜索正则表达式以使其包含光标?

编辑

好的,举个例子.光标在一个字符串内,我想获取文本,即该句法元素的内容.考虑以下行:

Okay, example. The cursor is inside a string, and I want to get the text, the content of this syntactic element. Consider the following line:

String myString = "Foobar, [CURSOR]cool \"string\""; // And some other "rubbish"

我想写一个返回的函数

"Foobar, cool \"string\""

推荐答案

看到 nelstrom 提到的插件的工作方式与我原来的方法相似,我决定采用这个稍微优雅的解决方案:

Seeing that the plugin mentioned by nelstrom works similar to my original approach, I settled on this slightly more elegant solution:

fu s:OnLink()
    let stack = synstack(line("."), col("."))
    return !empty(stack)
endf

normal mc 

normal $
let lineLength = col(".")
normal `c

while col(".") > 1
    normal h
    if !s:OnLink()
        normal l
        break
    endif
endwhile
normal ma`c

while col(".") < lineLength
    normal l
    if !s:OnLink()
        normal h
        break
    endif
endwhile
normal mb`av`by

这篇关于Vim:获取光标下语法元素的内容的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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