To be able to paste something to vim's command line is a feature makes our life a lot easier. For instance, say we want to change a frequently used variable name in c source file from a_super_long_inproper_variable_for_caching_bank_account_balance to balance . To replace all of the variable's occurrence, we plan to use following replace command:
Without paste capability, we have to type the variable name ourself, maybe several times because we doom to type the name wrong.
Luckily, vim has at least two ways to rescue us from having to type the name.
1. command-line window
command-line window is a separate window that enables us editing command just like working in a normal window. Plus, it lists command history. So, we can easily copy the variable name via yank command and paste it to command-line window. To open the command-line window, we can type q: while in normal mode. For more information about command-line window, see help q: in vim.
2. paste with Ctrl+R shortcut key combination
Instead of opening a separate command-line window, we can also paste directly in vim command line. While editing within command line, we can use Ctrl+R, Ctrl+W key combination to paste the word currently under cursor in last window to command line. Beside the forgoing shortcut key, vim features a lot of key combination that let us paste from different sources, like registers, file name, etc. Run :help c_CTRL-R to find more out its real power.
Reference:
Vim documentation: cmdline

本文介绍在Vim中如何高效地进行查找与替换操作,特别是针对长变量名的替换。通过使用命令行窗口和快捷键组合(如Ctrl+R和Ctrl+W),可以轻松复制并粘贴长字符串,从而提高编辑效率。
3865

被折叠的 条评论
为什么被折叠?



