Questions tagged [vi-mode]

Theses questions are about GNU Readline's vi mode providing vi-like commands inside your terminal. Use this tag for questions about configuring or operating vi mode (e.g., Bash integration, setting keybindings).

should be use for questions pertaining to the vi mode of the GNU command line editing library. Use this tag for questions about configuring or operating vi mode (e.g., using it with Bash, setting keybindings).

GNU Readline's vi mode provides vi-like commands for line-editing and history interaction in interactive programs with a command-line interface such as Bash or Python. Here is a list of some of the available commands:

  • ^ move cursor to start of line
  • $ move cursor to end of line
  • b move cursor back a word
  • w move cursor forward a word
  • e move cursor to the tend of next word

To use and configure vi mode in Bash and any other program that uses GNU Readlines you need to edit readline's config file: ~/.inputrc. See for questions and answer about its syntax. You should start by adding

set editing-mode vi

in your ~/.inputrc.

If you only want to use vi mode in Bash, you can activate it by adding

set -o vi

in your ~/.bashrc.

Further reading

Useful links

57 questions
76
votes
2 answers

How do I perform a reverse history search in ZSH's vi-mode?

I use vim for essentially all my editing needs, so I decided to once again try vi-mode for my shell (currently ZSH w/ oh-my-zsh on OS X), but I find myself trying (and failing) to use Ctrl-R constantly. What's the equivalent key-binding? And for…
Hank Gay
  • 3,489
  • 4
  • 24
  • 27
73
votes
5 answers

Why does '\r' (and not '\n') work to replace with a newline in 'vim'?

In vim editor, I want to replace a newline character (\n) with two new line characters (\n\n) using vim command mode. Input file content: This is my first line. This is second line. Command that I tried: :%s/\n/\n\n/g But it replaces the string…
Raghvendra
  • 1,002
  • 1
  • 7
  • 13
69
votes
2 answers

Is there any way to enable Ctrl+L to clear screen when 'set -o vi' is set?

When you press Ctrl+L in bash default mode the screen is cleared. But when I run set -o vi and press Ctrl+L the keystroke is printed (^L). Is there any way to keep this behavior?
David Martínez
  • 1,336
  • 2
  • 17
  • 25
38
votes
2 answers

What is meant by a shell is in "vi" mode or "emacs" mode?

This question follows directly from the answer. In this case I am specifically unable to understand the part which says: In that regard, its behaviour is closer to emacs' than with bash(readline)/ksh/zsh emacs mode, but departs from the terminal …
Geek
  • 6,548
  • 15
  • 46
  • 70
33
votes
2 answers

How to unset set -o vi?

I wanted to try vi mode in bash but now I would like to change it back to normal. How can I unset -o vi ?
Patryk
  • 13,556
  • 22
  • 53
  • 61
17
votes
4 answers

Bash vi mode configuration to default to command mode

Is it possible to configure bash vi mode so that initially it is in command mode instead on insert mode? I find that I have to press Esc far too much. It seems that there is possibility to specify this in zsh, but I have not found a way to do this…
Galisperis
  • 171
  • 3
15
votes
1 answer

Bash + urxvt: delay after ESC in Vi mode

I have enabled the mode prompt indicator in my ~/.inputrc with set show-mode-in-prompt on. There is a delay of about half a second in the indicator when switching to normal mode after pressing ESC but no delay in the indicator when entering insert…
ramblenode
  • 333
  • 2
  • 9
13
votes
1 answer

bind key sequence to Escape, zsh

How would I map jj to Esc in zsh? I'm trying to recreate a key-mapping that I have setup in vim, where I have jj mapped to ESC so that whenever I double-press j, it sends the an to vim--allowing me to enter normal mode with greater…
Alexej Magura
  • 4,356
  • 7
  • 26
  • 39
8
votes
1 answer

Going over start of insert action in Z shell vi-mode

Is it possible to configure the vi-mode of the Z shell so that backspace can delete characters before the position where the insert action was started? Basically the behavior of vim which can be achieved by adding the following line to ~/.vimrc set…
viuser
  • 2,564
  • 3
  • 29
  • 57
8
votes
1 answer

How to enable bash completion in vi mode on Synology DSM6

When I turned on vi mode in bash by setting set -o vi suddenly the tab completion was broken, and a literal tab was inserted. How can this be fixed?
Gerhard Burger
  • 333
  • 1
  • 8
7
votes
2 answers

Insert the last argument in bash in vi mode without inserting a leading space

Using bash in the default (emacs) mode I get the following behavior when I hit Esc, .. $ echo hello hello $ hello # I hit `.` to insert this Note there is no space before the word hello that is inserted when I hit Esc, .. If I switch to vi…
mike
  • 165
  • 1
  • 7
7
votes
1 answer

How can I get back into "normal" edit-mode after pressing esc in zsh (vi mode)?

I'm using zsh in vi-mode. When I go to normal mode with ESC and then back into insert mode (for example using i, a or s), the line editor kind of "protects" the part of the line in front of the char, at which I was when re-entering insert mode. I…
groxxda
  • 1,028
  • 1
  • 7
  • 11
7
votes
1 answer

How can I configure ZSH's vi mode to persist the state between commands?

I am aware how to set ZSH's default line editor to use vi-like keybindings... bindkeys -v ...and even to default each new prompt to be in command mode instead of insert mod by default... zle-line-init() { zle -K vicmd; } zle -N…
Caleb
  • 69,278
  • 18
  • 196
  • 226
6
votes
3 answers

Running external commands in vim

It seems that if I run the following inside the vim: :w !wc -w I get the word count of the file. But I don't understand the syntax. How does this work and how would I specify that I want the word count of a paragraph and not of the whole file?
Cratylus
  • 499
  • 3
  • 6
  • 12
6
votes
1 answer

How to configure the buffer used by vi-mode bash for yank and paste?

tldr: Does anyone know how to configure what buffer is used by vi-mode bash for yanking (copying) and pasting? Long version: I have set editing-mode vi in my .inputrc, so that programs using the readline library, namely bash, use vi-like key…
ummg
  • 261
  • 1
  • 7
1
2 3 4