【发布时间】:2014-04-26 16:54:03
【问题描述】:
我找到了有关如何获取 the word/WORD under the cursor 或 the character under the cursor 或整行 (getline(".")) 的答案。如何在光标下获取给定的文本对象?
更具体地说,我想得到 vi' 将选择的内容,并在函数中使用这些字符(不会弄乱寄存器)。
【问题讨论】:
标签: vim
我找到了有关如何获取 the word/WORD under the cursor 或 the character under the cursor 或整行 (getline(".")) 的答案。如何在光标下获取给定的文本对象?
更具体地说,我想得到 vi' 将选择的内容,并在函数中使用这些字符(不会弄乱寄存器)。
【问题讨论】:
标签: vim
最简单和最直接的方法确实是拉到一个寄存器;只需确保保存并恢复原始内容即可。
let l:save_clipboard = &clipboard
set clipboard= " Avoid clobbering the selection and clipboard registers.
let l:save_reg = getreg('"')
let l:save_regmode = getregtype('"')
normal! yi'
let l:text = @@ " Your text object contents are here.
call setreg('"', l:save_reg, l:save_regmode)
let &clipboard = l:save_clipboard
【讨论】:
expand("<cWORD>")之后,我期待着像那些特殊的表达。这个答案确实很简单直接,谢谢。