Question

I've kind of become vim crazy these last few months, using plugins like Vimium to control chrome. I currently use iTerm2, but I was wondering if there were any terminal emulators or shells that use vim commands or could be configured to have vim like commands.

I'm mostly interested in selecting text (visual mode) from the buffer, yanking it, and pasting it somewhere on the command line below. It would be nice to be able to scroll up and down the buffer with j and k, and to edit your command with insert mode (currently have to use arrow keys)

Does such a beautiful thing exist?

Was it helpful?

Solution

Editing and executing commands through vim

  1. open vim, :r !history (or whatever), copying things, and executing it via :!<type your shell command here>. Use the last command :silent !<blah blah> if vim should stop bugging you with messages afterwards.

  2. If you stick to the regular emacs settings (if you don't change modes in either shell like i described, you actually can use ctrl+a, ctrl+e and all the like!), you might try writing your command and edit it in vim through CTRLXCTRLE.
    However this depends on the editor set via the EDITOR / VISUAL environment variable, which tells linux which editor the system should use usually!

    Here you can paste content if you have a vim that is compiled with the +clipboard or +xterm_clipboard flags!
    :wq and you are back at the prompt with the edits you have made.



Native bindings in the shell

bash: set -o vi

zsh: bindkey -v

Switching to normal mode with ESC or CTRL[, you can use movement like in vim (e w b h j k l ...) or open a vim with the current content using v.

The shells try their best to emulate the behaviour. Sadly you have no visual indicator wether you are inserting or not, besides the input changes when you type.

To have native bindings permanently, add the commands to either ~/.bashrc or ~/.zshrc, depending on the shell you use. If you just want to test things out, enter this on the shell directly, just don't forget the new setting will not stick this way.
This will also work on windows if you have a shell installed (be it through git's bash or via cygwin.).

OTHER TIPS

sjas is close but missing the critical component:

set -o vi gives you vim bindings

then press v to edit your current line in vim

the mouse is almost always more efficient for selecting text, vim or no vim, so us the mouse for that.

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top