Editing and executing commands through vim
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.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.).