Home > Enterprise >  How to use visual mode under bash vim mode?
How to use visual mode under bash vim mode?

Time:12-18

I'm trying to work under bash vim mode by setting

set -o vi

And most of the vim commands work well. But when I tried to enter visual mode by pressing v, then GNU nano is opened and showing the command line I'm editing with in bash.

I don't know if this is a common problem. I tried in virtual machine and wsl2 and both happeded.

So is it possible to enter visual mode under bash vim mode? Or could you please tell me how to select and copy some texts without using visual mode?

And may I ask if there is any way to paste the copied text in vim to other programs? It seems that no text is bufferd in the clipboard.

CodePudding user response:

So is it possible to enter visual mode under bash vim mode?

It is "vi mode", not "vim mode". There was no visual mode in vi so there is no visual mode in "vi mode".

In "vi mode", v is used to open the current command-line in the default text editor. It is usually set via the $EDITOR environment variable, which is likely set to nano in your case.

You can add the line suggested in the comments to your bash configuration file (~/.bashrc, ~/.bash_profile, ~/.profile, your mileage may vary) to open Vim instead of nano.

Or could you please tell me how to select and copy some texts without using visual mode?

If you can't intuit a way to do that, then why enable "vi mode" to begin with? You do it just like in vi: y<motion>.

  • To learn vi, read its manual.
  • To learn readline's "vi mode", read $ man readline.

And may I ask if there is any way to paste the copied text in vim to other programs?

You can't, because a) neither bash nor the readline library are or can be connected to your system clipboard, and b) neither bash nor the readline library maintain an internal clipboard that could be accessed by external programs.

My advice: you don't seem to know vi well enough for "vi mode" to make a difference so, stick to the default "emacs mode" and use your pointing device to select the text to copy.

  • Related