15

When I'm editing a Vim command, I would like to use the same shortcuts as in Bash and every other REPL: M-b to go back a word, M-Backspace to delete a previous word, M-u to convert the word to uppercase, C-k to cut until the end of the line, etc. I have been able to configure some of the commands, using :cmap, but not all.

Is there a plugin or setting which provides this?

I know about cedit, but I find it cumbersome when all I need is to enter a quick command.

  • Waitaminute, are you saying you use Bash in Emacs mode even though you use Vim as your editor? – Kyle Strand Jan 5 '16 at 20:14
  • 3
    @KyleStrand I've yet to see someone who used Bash in vi mode. It seems like most of the benefits of modal editors disappear when you're only limited to one line. – Mihai Jan 5 '16 at 20:41
  • 1
    Interesting. I only ever use Bash in Vi mode, though it does seem like Emacs mode supports some things that Vi mode doesn't. I just happen to know Vi keybindings while remaining almost completely ignorant of Emacs bindings, and I've never thought it a pressing enough issue to learn the defaults. – Kyle Strand Jan 5 '16 at 20:46
11

Is there a plugin or setting which provides this?

Yes, rsi.vim plugin:

Features

  • Readline mappings are provided in insert mode and command line mode. Normal mode is deliberately omitted.
  • Important Vim key bindings (like insert mode's C-n and C-p completion) are not overridden.
  • Meta key bindings are provided in a way that works in the terminal without the perils of remapping escape.
  • C-d, C-e, and C-f are mapped such that they perform the Readline behavior in the middle of the line and the Vim behavior at the end. (Think about it.)
1

Is there a plugin or setting which provides this?

There is also readline.vim.

It is a newer plug-in which focuses purely on the command-line. It also implements a larger subset of the Readline shortcuts and has the goal of implementing each shortcut exactly like in Readline.

What makes this plugin different from similar plugins is that it implements a larger subset of the Readline mappings, and that it does a better job of mimicking the Readline behavior for each command.

The word movement and deletion commands have different behavior between Vim and Readline. The biggest difference is that in Readline punctuation is always skipped when searching for a word boundary. Another difference is that _ (underscore) is treated as a word delimiter. This plugin implements the Readline behavior for word movement and deletion commands.

  • 1
    I'm surprised there's anyone looking for this kind of thing. It's so easy to use readline's vim mode that I'd think every regular vim user would do it. (I don't find the extra commands in emacs mode all that compelling.) But maybe the "how" is not that widely known (...and maybe I'm lucky that the very first bashrc I saw/copied...many more years ago than I care to admit...had set -o vim :) – B Layer May 11 at 13:41

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.