如何将当前行作为 Vim EX 命令执行? [英] How can I execute the current line as Vim EX commands?
问题描述
假设我正在编辑我的 _vimrc
文件并且我刚刚添加了几行,例如一个新的键映射.我不想重新加载 整个 文件 (:so %
),因为这会重置我正在尝试的许多临时内容.我只想运行我目前正在处理的两行.
Say I'm editing my _vimrc
file and I've just added a couple of lines, for instance a new key mapping. I don't want to reload the whole file (:so %
) since that will reset a lot of temporary stuff I'm experimenting with. I just want to run the two lines that I'm currently working on.
我在尝试将行复制/粘贴到命令缓冲区时没有运气,因为我无法在那里使用 put 命令.有什么办法可以将当前行(或当前选择)作为 EX 命令运行吗?
I'm having no luck trying to copy/paste the lines into the command buffer, since I can't use the put command in there. Is there any way I could run the current line (or current selection) as EX commands?
总结:
在 Anton Kovalenko 的回答和 Peter Rincker 的评论我最终得到了这些关键映射,它们要么执行当前行,要么在可视模式下执行当前选定的行:
After Anton Kovalenko's answer and Peter Rincker's comment I ended up with these key maps, which either executes the current line, or the current selected lines if in visual mode:
" Execute current line or current selection as Vim EX commands.
nnoremap <F2> :exe getline(".")<CR>
vnoremap <F2> :<C-w>exe join(getline("'<","'>"),'<Bar>')<CR>
推荐答案
要将当前行作为 ex 命令执行,您也可以使用:
To execute the current line as an ex command, you may also use:
yy:@"
这会将当前行拉到 "-register 并执行它.我不认为它打字太多.
This will yank the current line to the "-register and execute it. I don't think it is too much typing.
这篇关于如何将当前行作为 Vim EX 命令执行?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!