3

Recently I've started using the vim keybinding in the terminal. I changed the keybinding of the terminal by adding the following line in the ~/.bashrc file.

set -o vi

But I've noticed an issue with it. When I go to the normal mode by pressing the "Escape" key and then press "v" it opens a file with the following name in the default editor.

/tmp/bash-fc.some_random_string_here

e.g., /tmp/bash-fc.PFb1Vy

I've tried checking all the terminal shortcuts but couldn't find anything with "v" there. Though I'm new to shell scripting, I checked the ~/.bashrc file but couldn't find anything related "bash-fc".

Could anyone of you kindly tell me what's the reason behind it? It's really annoying to accidentally open vim and quit vim every time :(

In normal mode(after pressing Escape)

And I press "v" and I'm in vim :(

Quasímodo
  • 2,104
h-sifat
  • 133

1 Answers1

2

There is no visual mode in Bash's Vi-mode. A v in normal mode dumps the current line in the user's preferred editor. One types/edits the command there and upon saving and quitting the editor (in Vim, :x or :wq), Bash issues the command.

To disable the binding you can rebind it to an unnoticeable operation. Just add this to the ~/.inputrc file:

set keymap vi-command
"v":redraw-current-line

That file only affects GNU Readline (the library that handles user input in Bash), never the Vim editor itself.


At the present time, Vi-mode users dwell mostly on undocumented grounds (v is not in Bash's manual nor in Readline's manual) and face some bugs. For example, if you type

a b b

at the prompt, put the cursor on the a and then try tb in normal mode, the cursor will jump to the first b, but then if you try to repeat the movement with ;, the cursor won't move.

Quasímodo
  • 2,104