Is it possible to have vim key bindings in terminal?

34,718

It has insert and normal modes (the insert mode is default, and escape for normal mode).

When in vi normal mode, you can launch the full $EDITOR to edit the current line with v (the same can be achieved when bash is in emacs mode with C-x C-e).

In bash: set -o vi You can run it at the command line for just this session or add it to your .bashrc file.

Many programs use readline for input, and you can make any of them use vi-style keybindings by setting up your .inputrc with

set editing-mode vi
set keymap vi

In zsh, if you change your EDITOR environment variable, the shell will match it.

Share:
34,718

Related videos on Youtube

Somebody still uses you MS-DOS
Author by

Somebody still uses you MS-DOS

Updated on September 17, 2022

Comments

  • Somebody still uses you MS-DOS
    Somebody still uses you MS-DOS over 1 year

    I'm getting used to vim bindings (like pressing w to go to word, dw to delete a word, and such) and it's modes (insert, normal, visual), and, out of curiosity would like to know: is there some kind of implementation of this behaviour of modes and bindings from vim to my terminal?

    Have insert mode, normal mode and such...

  • Somebody still uses you MS-DOS
    Somebody still uses you MS-DOS over 13 years
    Pretty neat. Do you know if it's possible to have some kind of .vimrc as well, but for this uses? For example, adding different mappings to <ESC>...
  • Gilles 'SO- stop being evil'
    Gilles 'SO- stop being evil' over 13 years
    @Somebody: Not .vimrc since you're still using the shell's built-in editor, but you can configure key bindings in .inputrc for all readline applications (such as bash), in .bashrc for bash specifically, in .zshrc for zsh.
  • Shawn J. Goff
    Shawn J. Goff over 13 years
    Checkout the bind builtin
  • Matthew Hintzen
    Matthew Hintzen about 13 years
    Note that on OS X, you'll need to put the put -o vi in ~/.bash_profile instead of ~/.bashrc .
  • Matthew Hintzen
    Matthew Hintzen about 13 years
    I notice that the cursor appearance doesn't change in the different modes bash w/ vi key bindings. Is there any way to make it do that? It would be nice to have a visual indication of what mode I'm in.
  • Renat Zaripov
    Renat Zaripov about 7 years
    ^ Why put (and not set), does Mac have it's own version of bash?
  • Will
    Will over 6 years
    For a visual indicator you can put set show-mode-in-prompt on, set vi-ins-mode-string "+" and set-cmd-mode-string ":" in your .inputrc file.
  • Soap
    Soap over 4 years
    @Will That worked, with a few changes. Namely, I added: set show-mode-in-prompt on set vi-ins-mode-string "+" set vi-cmd-mode-string ":"
  • LRDPRDX
    LRDPRDX about 4 years
    How to paste a clipboard in terminal in this case? Neither the <C-v>, <C-S-v> nor vim registers work.
  • kevinnls
    kevinnls almost 3 years
    you can launch the full $EDITOR to edit the current line with v this doesn't seem to work with zsh. it is entering visual mode. any idea? i am using powerlevel10k theme, but i don't think that could be the reason right?
  • FriskySaga
    FriskySaga over 2 years
    On WSL, you'll need to restart the terminal to see the changes advised by @Soap take into affect.