【问题标题】:How can I get the word under the cursor and the text of the current line in vim script?如何在vim脚本中获取光标下的单词和当前行的文本? 【发布时间】:2009-07-12 06:56:12 【问题描述】: 我正在尝试编写一个 vim 脚本。如何获取光标下的单词和当前行的文本?我想在我的脚本中使用它,谢谢。 【问题讨论】: 标签: vim scripting 【解决方案1】: 您可以使用expand 和getline: let wordUnderCursor = expand("<cword>") let currentLine = getline(".") 【讨论】: 使用help cword 获得更多选择。对于我的 vimrc,我需要 cWORD 来抓取光标下的空格分隔文本 对我来说getline(".") 给出了与expand("<cword>") 相同的结果。我想抓住光标下的整行。我该怎么做?