vim - 获取光标下的整个字符串文字

标签 vim

Vim 有 expand("<cword>")获取光标下的“单词”。如果光标位于带引号的字符串文字上,您将如何定义一个函数来获取引号之间的所有内容?

考虑到这种情况:

foo = "this string has spaces"
          ^ cursor is here

I want to do

:echo GetStringUnderCursor()

看看

this string has spaces


EDIT: I see you can check if the cursor is on a string region with this incantation

synIDattr(synIDtrans(synID(line("."), col("."), 1)), "name") == "String"

我只是还没有找到一种方法来查找给定语法区域的开始和结束位置(行和列)。

最佳答案

例如:

vi"    ->    visual select all inside the quotes
ci"    ->    change all inside the quotes
yi"    ->    yank all inside the quotes

如果你猛拉它,你可以这样做:

echo @"    ->     prints register " (default)

关于vim - 获取光标下的整个字符串文字,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/12964573/

相关文章:

vim - 在 Vim 可视化模式下转换为小写,直到特定分隔符

regex - ag Silver Searcher : rules for lookahead/lookbehind patterns?

vim - 替代 vim 中的 taglist

php - Vim : What are the required lines in ~/. vimrc 的语法? (PHP 错误检查)

gcc - 为什么在 vim 和 emacs 中使用 clang 进行自动完成?

html - 如何强制 vim 将文件语法高亮显示为 html?

vim - 是否有类似于fuzzyfinder_textmate 和Command-T 的Vim 插件_not_ 需要Ruby 支持?

vim - gVim 在 ""、$$、() 等序列之后放置额外的 <++>。

vim - 如何从一个拆分中复制并粘贴到byobu中?

Linux gvim 与 vim