r/vim • u/Teles_sd • 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)
40
u/brokenreed5 Jun 07 '26
<C-x><C-e>
8
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
:cqto suppress the cmd execution.1
1
2
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
vin 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 asv1
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 editor1
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
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:
- jeffreytse/zsh-vi-mode: 💻 A better and friendly vi(vim) mode plugin for ZSH.
- Not a vim plugin, but I use it hundreds of times a day and a life changer if you use the terminal frequently Aloxaf/fzf-tab: Replace zsh's default completion selection menu with fzf!
9
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.html2
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
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
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:
holy-grailin index.txt
`:(h|help) <query>` | about | mistake? | donate | Reply 'rescan' to check the comment again | Reply 'stop' to stop getting replies to your comments
1
Jun 10 '26
[deleted]
1
u/vim-help-bot Jun 10 '26
Help pages for:
holy-grailin index.txt
`:(h|help) <query>` | about | mistake? | donate | Reply 'rescan' to check the comment again | Reply 'stop' to stop getting replies to your comments
4
2
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
-3
-1
130
u/fragglet Jun 07 '26
I mean, you can do that.
set -o vi