Sometimes a regular expression starts to get pretty complex, and it's hard to edit in Vim's commandline.

It seems the obvious way is to edit the search term as though it's a file and be able to switch between editing it and testing it as an actual search.

How do I accomplish this?

  • You can paste into the command line with <Ctrl-R> followed by the name of the register you want to paste from (e.g. * for the Windows clipboard.)
    – Rich
    Mar 27, 2015 at 15:40
  • Actually I can paste into the commandline with Ctrl-V but copying from it is harder. Specifically it's hard to copy or paste just part of it. Mar 27, 2015 at 15:44
  • 1
    @hippietrail It feels more to me (and I presume @Carpetsmoker) that the abstract problem is "I want to be able to edit regular expressions more powerfully" and two different specific approaches to this are 1. Copy/paste in the commandline 2. Edit the regex as if it's a file.
    – Rich
    Mar 27, 2015 at 16:24
  • 1
    Well that's a generalization of my problem I suppose (-: The specific power was long subparts of search strings used more than one, but the full power of an edit buffer seemed like something I thought must be in Vim though my Googling failed probably because I didn't know the key jargon... Ah I see the specific part about reusing subexpressions was edited out... Mar 27, 2015 at 16:27
  • 1
    Both the title and the question itself ask "How can I edit a regular expression search string as if it were a file?" ;-) The Windows copy/paste thing just seemed like an off-hand remark to me. You can always revert my edit, or make more edits to your question ;-) Mar 27, 2015 at 17:40

1 Answer 1


Use <C-f> from the command-line or q/ from normal mode to open the command-line window.

Note that q/ specifically opens your command-line history in the command-line window but <C-f> is contextually aware: it will open the right history for the current command-line and is thus the exact answer to your question.

See this documentation from :help cmdline-window:

There are two ways to open the command-line window:

  1. From Command-line mode, use the key specified with the 'cedit' option. The default is CTRL-F when 'compatible' is not set.
  2. From Normal mode, use the q:, q/ or q? command. This starts editing an Ex command-line (q:) or search string (q/ or q?). Note that this is not possible while recording is in progress (the q stops recording then).
  • I guess I don't know my Vim jargon. Is something called the "command-line window" that is not the single line at the bottom of Vim where I type commands? \-: Mar 27, 2015 at 15:47
  • 4
    For searches started with /, you'd want to use q/ instead of q:
    – Matt Boehm
    Mar 27, 2015 at 15:49
  • @hippietrail No, that's the command line. As @romainl suggests, you should read :help cmdline-window. (Or just try it out!)
    – Rich
    Mar 27, 2015 at 15:49
  • 1
    If you type q/ instead of / vim will open a new window with your search history that you can edit as if it were a file.
    – Matt Boehm
    Mar 27, 2015 at 15:57
  • 1
    The answer would be better too if it somehow introduced the concept and/or jargon "command-line" window" since I suppose others will be like me in that though they've used Vim for years never had to use this feature before. Mar 27, 2015 at 16:14

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.