2

I like using the Bash shortcuts while at the command line to move around and edit text. A sample of some commands from the link can be seen below:

Ctrl + a   Go to the beginning of the line (Home)
Ctrl + w   Cut the Word before the cursor to the clipboard.
Ctrl + e   Go to the End of the line (End)
Ctrl + p   Previous command (Up arrow)
Ctrl + n   Next command (Down arrow)
Alt + b    Back (left) one word
Alt + f    Forward (right) one word
Ctrl + f   Forward one character
Ctrl + b   Backward one character
Alt + d    Delete the Word after the cursor.
Ctrl + d   Delete character under the cursor
Ctrl + y   Paste the last thing to be cut (yank)

It seems like some of these work while in Insert mode; for example Ctrl + w or Ctrl + u. However some don't; for example Ctrl + y.

  • How do I enable Bash shortcuts while in insert mode?

I'm running macOS:

ProductName:    Mac OS X
ProductVersion: 10.12.1
BuildVersion:   16B2657

Vim:

VIM - Vi IMproved 8.0 (2016 Sep 12, compiled Feb 16 2017 06:36:51)
MacOS X (unix) version
Included patches: 1-329
Compiled by Homebrew
  • 1
    Those are not bash shortcuts, they're emacs-readline ones. If you are suing Vim you will probably do better with set -o vi in the shell, so the shell uses the Vi bindings (readline has Vi bindings too). If you really, really, really want them you should just :map (preferably :remap) them (<c-a>, <c-e>, ...). – grochmal Apr 5 '17 at 16:45
7

Type <c-o> to temporarily leave insert mode and use normal mode keys instead.

To create insert mode maps, read :h normal-index and :h insert-index. Then create insert maps that does about the same thing you want. For example:

inoremap <c-a> <c-o>0
inoremap <c-w> <c-o>db
inoremap <c-e> <c-o>$

The reason why Vim doesn't have insert mode keys for those operations is simple:

Vim is a modal editor

Alternate reason: Vim is not Emacs.

As @grochmal pointed out, these are actually Emacs bindings. In Emacs, you're in insert mode all the time. Those keys make sense in that context. In a terminal, you could say that you're in insert mode as well, so again, it makes sense there.

In Vim, you're either in insert mode, or not. Inserting text in Vim is a transaction. You begin a transaction by entering insert mode and end it by leaving insert mode. After a transaction is completed, the buffer's state is saved (undo, cursor position, etc). To use Vim as intended, you insert some text, leave insert mode, then move the cursor.

The distinct advantage of a modal text editor is that there's no "shortcuts" or "hotkeys". Your entire keyboard is used for text manipulation.

  • True, and a good answer, but.. there are plenty of standard mappings for motions and editing operations in insert mode (including most of the ones listed in the OP), so it is not necessarily "the Vim way" to always return to normal mode for anything but serial character input. The mentioned help content at :h insert-index is an excellent reference. I do like the analogy of a transaction, which is new to me. I look forward to exercising that language with my database developer friends: Vim is a transactional editor... Inserting/repeating/undoing are operations with transaction scope.... – jjaderberg Apr 5 '17 at 22:36
2

Tim Pope has made a plugin to do exactly that, the RSI shortcuts on insert mode:

https://github.com/tpope/vim-rsi

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

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