1

I was wondering how can I enable VI normal mode when typing a colon (:) cmd in VIM or NeoVIM.

For example: If I type a long search and replace cmd and realized I made a mistake now I want to move back to the beginning of the line and fix it so I would want to be able to exit VI insert mode go to VI normal then type 0 and go back to the beginning of the (:) cmd

e.g.

:%s/add asserts for things you expectequal to the expected value thathappend/Trevor add asserts for expected values/g
7
  • Hit Ctrl-F and you'll enter a mode with full Vim edit capabilities of current and previous commands. :h c_CTRL-F ... I think there's already an answer for this somewhere...
    – B Layer
    Jun 3 at 13:51
  • You can use Ctrl-F from a command-line or search to open the "command window", where you can use Normal and Insert modes to edit your command. See :help c_CTRL-F. I believe there's a recent question that got the same answer recently, so I'm looking for that to mark this one as a duplicate... If I don't find it, I might post it as an answer here.
    – filbranden
    Jun 3 at 13:53
  • This is the one: vi.stackexchange.com/q/31387/18609 (see the second answer), but not sure if it's close enough of a duplicate...
    – filbranden
    Jun 3 at 13:55
  • 1
    The actual name is "command-line window" and it has its own tag...gotta be a suitable dupe somewhere around here I would think. Looking myself.
    – B Layer
    Jun 3 at 14:02
  • Thank you I am going to use it for a bit and see but it seems like it exactly or even better than what I was looking for. Thanks a lot :)
    – I J
    Jun 3 at 14:07
4

There's no inline, rich command-line editing within Vim in the way many might expect (i.e. like Bash command-line editing with "vi-mode") but you can edit commands with a feature that is arguably even better than that; a feature that even lets you yank/put parts of earlier commands into your in-progress command.

I'm talking about the command-line window.

To open this while in the middle of entering a command (after you hit :) type Ctrl+F

You will see your full Ex command history including your in-progress command. This window is just like any other Vim buffer. You'll start out in Normal mode and can edit your current command or any previous commands the same way you'd edit any other text.

When you're ready to submit a command make sure the cursor is on its line, and hit Enter. (Doesn't matter what mode you're in.)

If you want to bail out without submitting any command you can just use :Q to quit the command-line window (no ! necessary, even if you made changes).

Or, if you want to continue editing a command back on the regular command-line hit Ctrl+C with the cursor over the correct command.

BTW, you can also open this window from any buffer by entering Q: while in Normal mode.

Finally, you have this same capability for editing search patterns: Q/ or Q?.

See :h cmdwin for complete details.

This site is temporarily in read only mode and not accepting new answers.

Not the answer you're looking for? Browse other questions tagged .