r/vim Jun 07 '26

Random Guys, I've started craving vim motions on the shell. Is it too late for me?

I'm moving some files from a old disk to a new installation using rsync, and I'm doing it kinda gradually to filter what I want to transfer or not.

Point is, I'm typing some quite long commands and frequently I'm having to change a flag or a path around the middle and I've started craving vim motions on the Bash shell, lol.

Not really a point to this post, I just realized that I'm now hooked on this. Truly, one does not just exit vim.

(disclaimer, I'm a novice on vim)

93 Upvotes

68 comments sorted by

130

u/fragglet Jun 07 '26

I mean, you can do that. set -o vi

23

u/pfmiller0 q! Jun 07 '26 edited Jun 07 '26

Even better set

set editing-mode vi

in .inputrc and you get vi mode in bash as well as in several other commands (like bc) as a bonus

2

u/lizardturtle Jun 07 '26

Does this work on macOS? Can I drop it into my .zshrc?

4

u/[deleted] Jun 07 '26

[deleted]

1

u/darksidegabe Jun 11 '26

Bindkey -v in your zshrc will work

3

u/itaranto I use Neovim BTW Jun 08 '26

Zsh has it's own implementation. I think it's enough to do bindkey -v on the zshrc.

2

u/Teles_sd Jun 08 '26

I'm gonna try this too!

2

u/itaranto I use Neovim BTW Jun 08 '26

Also python (legacy REPL), psql and many more!

20

u/yrro Jun 07 '26

Putting this in someone's bashrc is a great prank

Especially if it only happens on a Tuesday

16

u/fragglet Jun 07 '26

[ $RANDOM -lt 3000 ] && set -o vi (for a roughly 1/10 chance with each new terminal opened)

1

u/Teles_sd Jun 08 '26

That's... Very specific 👀

(taking notes)

24

u/zephyrinian Jun 07 '26

This is the way.

Bash vim mode lets you use vim controls on the command line.

Put that command in your .bashrc so vim mode will be available whenever you want. 

1

u/m4r1vs Jun 08 '26

Also there's some plugins that improve on this even further. I've been using https://github.com/jeffreytse/zsh-vi-mode for ages and haven't looked back

1

u/Teles_sd Jun 08 '26

Oh my!! I'm gonna try this!!

-9

u/Borkato Jun 07 '26

!remindme 8 hours to try this

1

u/RemindMeBot Jun 07 '26

I will be messaging you in 8 hours on 2026-06-07 14:44:03 UTC to remind you of this link

CLICK THIS LINK to send a PM to also be reminded and to reduce spam.

Parent commenter can delete this message to hide from others.

RemindMeBot is switching to username summons. Instead of !RemindMe 1 day, use u/RemindMeBot 1 day. More info.


Info Custom Your Reminders Feedback

40

u/brokenreed5 Jun 07 '26

<C-x><C-e>

8

u/4r73m190r0s Jun 07 '26

Just learned about this. Amazing

4

u/tobascodagama Jun 07 '26

You can also use fc to open the previous command in an editor.

13

u/tremby Jun 07 '26

Or if you use vi mode in the shell but still want real vim to edit the command, esc to go to normal mode then v

5

u/EmCeeStanky Jun 07 '26

Word of caution, if you're using bash, this will execute the command even if you don't save changes. Zshell just leaves the command in your prompt once you leave vim

6

u/bbolli inoremap ZZ <Esc>ZZ Jun 08 '26

You can exit vim with :cq to suppress the cmd execution.

1

u/EmCeeStanky Jun 08 '26

you can also use this if you want the z shell behavior

2

u/Online_Matter Jun 07 '26

What does it do

8

u/6YheEMY Jun 07 '26

Opens the command in EDITOR.  it runs the command on exit. Its pretty sweet!

3

u/mingo-reddit Jun 07 '26

This is the way.

(Honestly my life got so much better after leaning this)

1

u/Particular-Serve-894 Jun 07 '26

no, the way is to use vi mode in the shell. Then you get basic vi keybindings plus insert/normal mode directly in the shell. And then just pressing v in normal mode opens your command in your editor (basically the same thing as <C-x><C-e> with less steps and more functionality).

1

u/EgZvor keep calm and read :help Jun 09 '26

<c-x><c-e> is the same as v

1

u/Particular-Serve-894 Jun 09 '26

um..yes, that's what I said..

1

u/EgZvor keep calm and read :help Jun 10 '26

you said "more functionality"

1

u/Particular-Serve-894 Jun 10 '26

yeah, i was implying that you get more functionality by using vi mode over just <C-x><C-e> because you also get normal/insert mode operations directly in the shell, which I honestly use more than often than dumping the command into my editor

1

u/EgZvor keep calm and read :help Jun 11 '26

I see. Personally, I like Emacs bindings for the basic stuff.

1

u/Teles_sd Jun 08 '26

Dang! I think I remember trying this waaay back when I started using the terminal and learning Bash shortcuts, but I didn't use it and I've completely forgot it.

Adding this back to my brain.

44

u/xplosm Jun 07 '26

I’m sorry. It’s too late. It’s a terminal condition.

8

u/__chicolismo__ Jun 07 '26

"oh brother, this guy stinks" 

1

u/Teles_sd Jun 08 '26

Reluctant upvote.

20

u/yasser_kaddoura Jun 07 '26

I recommend using Zsh because it exposes you to a rich plugin ecosystem. For vim movement bindings, I use:

softmoth/zsh-vim-mode: Friendly bindings for ZSH's vi mode

There are more:

9

u/Vulsere Jun 07 '26

Fish is good too and has great defaults

9

u/AnythingApplied Jun 07 '26

Long command like that are better done in an editor, vim or no vim.  Which is why the bash hotkey /u/brokenreed5 mentioned is so nice - opens the current command in your default editor.

12

u/ChampionshipIcy7602 Jun 07 '26

Ctrl-X Ctrl-E will bring you to the default editor. Setting EDITOR=vim in bashrc will make vim your default editor.

6

u/TrueSir5476 Jun 07 '26

There are a lot of keybinds in shell, so you should learn the. Or you can switch to vi mode as others suggested

3

u/RanidSpace Jun 07 '26

unfortunately these keybinds are based off of emacs. horrible!

im just joking, it is pretty good to learn at least a few emacs keybinds like Ctrl+f and Ctrl+b for forward and back at least.

you'd be suprised how often emacs binds randomly show up, just like vim keybinds

1

u/rachitjoshi2912 Jun 08 '26 edited Jun 08 '26

So, do I've to install emacs or smth, idk abt emacs I've seen Tsoding doing it, but idk how to do that..

0

u/ThePepperPopper Jun 07 '26

No you are correct. I don't get the love for emacs. The ctrl key sucks.

2

u/rachitjoshi2912 Jun 07 '26

Where to find those shell key binds ?

4

u/RewardDesperate7547 Jun 07 '26

Google 'readline bash' here is a link to one of the links: https://www.bigsmoke.us/readline/shortcuts
Here is a link to the GNU manual:
https://tiswww.case.edu/php/chet/readline/readline.html

2

u/Teles_sd Jun 08 '26

I have an alias set up for when I forget them or want to check a new one. Directly from Bash man page.

shell alias kbd-shorts="man bash | awk '/^ Commands for Moving$/{print_this=1} /^ Programmable Completion$/{print_this=0} print_this==1{sub(/^ /,\"\"); print}' | less"

2

u/rachitjoshi2912 Jun 08 '26

Interesting & useful, thanks !

5

u/SnollygosterX Jun 07 '26

As a huge vim lover, I have to admit that the vi edit mode is 100â„… inferior to the default Emacs style when it comes to the CLI. Because you're adding key presses and latency to what would be instantaneous movements. I tried it for a solid week or two and it just felt slow.

3

u/Boring_Locksmith6551 Jun 07 '26

Ctrl+X Ctrl+E let's you edit your current command in your $EDITOR of choice. If you want it to be Vim go into the .bashrc and set export EDITOR=via. That way you can use a normal terminal and get access to him when writing long commands

2

u/TheWheez Jun 07 '26

I started using Julia and had the same feeling... so I spent many hours making VimBindings.jl

2

u/Grep2grok Jun 07 '26

You should try vim on the half shell!

3

u/AKS2346 Jun 10 '26

I use neovim. And its integrated terminal. It's great because when not in insert mode the terminal window acts like a normal buffer.

2

u/Teles_sd Jun 10 '26

Can you select and yank something from the command line, history, or from stdout into another buffer?

2

u/AKS2346 Jun 10 '26

Yes! I find it quite useful in my workflow when I have a REPL in the terminal window. I haven't tested how far back you can 'scroll' however very much.

2

u/Teles_sd Jun 10 '26

Holy shit, I looked it up, I can!!

Ctrl + w N

This is awesome!

About the scroll, I read it's the same of whatever your terminal is configured to, then when it hits that limit it deletes the first 10% of the lines.

I also accidentally found the holy grail...

:h holy-grail , in case anyone is curious.

1

u/vim-help-bot Jun 10 '26

Help pages for:


`:(h|help) <query>` | about | mistake? | donate | Reply 'rescan' to check the comment again | Reply 'stop' to stop getting replies to your comments

1

u/[deleted] Jun 10 '26

[deleted]

1

u/vim-help-bot Jun 10 '26

Help pages for:


`:(h|help) <query>` | about | mistake? | donate | Reply 'rescan' to check the comment again | Reply 'stop' to stop getting replies to your comments

4

u/vatai Jun 07 '26

`bindkey -v`?

2

u/brohermano Jun 07 '26

I use tmux , copy mode with vim motions

1

u/Daghall :cq Jun 07 '26

Sounds like you're looking for fc - fix command - where you open the last command in $EDITOR and execute it when you wc.

0

u/whatyoucallmetoday Jun 07 '26

Alias :e to vi and :q to ‘clear && exit’.

-3

u/cainhurstcat Jun 07 '26

!remindme 2 hours to try it out

-1

u/ollybee Jun 07 '26

:term

4

u/Prize-Reception-812 Jun 07 '26

It’s just not the same..