Editable vimgrep string in command line

自古美人都是妖i 提交于 2019-12-20 05:18:31

问题


I use vimgrep a lot to navigate in files and usually use the last search from the history to modify the search pattern and run it again.

Is there a way to display in the command line an editable string like the one below, with the cursor already positioned between the two search pattern slashes (and the pattern being empty)?

:vimgrep // **/*[ch]|copen

I don't want to use a constant mapping (like the one at this vim tip) since I want to be able to add/change options (\c etc.).


回答1:


I'd recommend using the command-line window for this (q: opens it from normal mode), since you can edit the command with the regular normal mode keystrokes (and you get syntax highlighting too).

You can also move around in your history just like in a normal buffer. So ?vimgrep<Enter>nnn... will search for and move you to all your old vimgrep commands.

Just hit <Enter> as normal when you are done editing, or :q<Enter> to abort the command and quit the window like you would any other.

Finally, here's a mapping to quickly bring up your empty vimgrep template in the command-line window.

:nnoremap \v q:ivimgrep<Space>//<Space>**/*[ch]<Bar>copen<Esc>F/;i


Reference: :help cmdline-window



来源:https://stackoverflow.com/questions/17535424/editable-vimgrep-string-in-command-line

标签
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!