How to work with command-line mode the vi way?

2018-04-30 14:31:08

Is there a way to interact with the command-line mode while always remaining in the home position?

In particular, the following two actions are cumbersome, requiring moving the fingers away to the arrow keys and sometimes worse, the mouse.

Moving around: Is there a way to move back and forth in the command-line mode while remaining in the usual position?

How can you copy and paste on the command-line? I mean copying both from part of the command-line itself to another part, or from the text or even clipboard.

There's the command-line (that you know), and there's the command-line window (the command-line in a special buffer, which you can edit just like any other). You enter this either via from the command-line (also for / searches etc.) when you feel the need for more "editing power", or directly from normal mode via the dedicated q:, q/, etc. commands.

Read more about this at :help command-line-window.

In addition to providing the command-line win

  • There's the command-line (that you know), and there's the command-line window (the command-line in a special buffer, which you can edit just like any other). You enter this either via from the command-line (also for / searches etc.) when you feel the need for more "editing power", or directly from normal mode via the dedicated q:, q/, etc. commands.

    Read more about this at :help command-line-window.

    2018-04-30 15:17:05
  • In addition to providing the command-line window, Vim also offers some limited features allowing you to interact with the command-line whilst in command-line mode (without using the arrow keys).

    Movement

    move the cursor to the beginning of the command-line

    move the cursor to the end of the command-line

    Editing

    delete the character before the cursor (like backspace)

    delete the word before the cursor

    delete all the way from the cursor back to the start of the command-line

    You could of course add command-line mappings with :cnoremap to emulate certain other programs' navigation keys. Or install Tim Pope's RSI plugin to use the de facto standard Readline bindings.

    Pasting

    You can paste the contents of any register into the command-line at the position of the cursor by pressing followed by the character specifying the register. e.g. ,+ will insert the contents of the clipboard into the command-line; ," will i

    2018-04-30 15:42:43