20

I want to use w for next word and b for previous word. If I could do more than that I would be even happier.

I use bash if that matters.

5 Answers 5

28

I'm surprised you haven't yet found out about

set -o vi

This enables the vi editing mode in Bash (to make this permanent put the command in your ~/.bashrc file). Greg's Wiki has a short summary, and here's a Unix & Linux question about its advantages.

This setting is for the Bash shell, regardless of the terminal (who's purpose is to provide a container for typing and seeing text (plus selecting and pasting with the mouse) - apart from tabbed windows and some global window management, it shouldn't interfere with what's running inside it).

To enable this for some more (terminal-based) applications that use the readline library for input, you can put this into ~/.inputrc

# Do what "set -o vi" does in Bash to whatever uses readline.
set editing-mode vi
2
  • It's 2023, I've been using the terminal for 15 years now and I find this out....only now?
    – pyronaur
    Feb 13, 2023 at 20:22
  • @pyronaur Better late than never ;-) Feb 14, 2023 at 11:47
3

I'm surprised it is mentioned here, so I'll mention it for completeness' sake. Also for the zsh shell, the way of setting vi keybinding is different from bash.

In zsh vi keybinding are set with:

bindkey -v

For a gentle introduction, you can read here. After which, the official documentation should look less intimidating.

2

For zsh users that use vim(not vi):

In addition to adding the vi keybinding, you should avoid the vi-related backspace issue(backspace stops working) by putting the following two statements in your ~/.zshrc:

# use vi key bindings
bindkey -v
# avoid the annoying backspace/delete issue 
# where backspace stops deleting characters
bindkey -v '^?' backward-delete-char

The backspace issue has been discussed here in more detail.

0

For Fish shell users, put the command fish_vi_key_bindings into your config. Default location is: ~/.config/fish/config.fish

For more details, see answer: https://stackoverflow.com/a/28445450

0

Best option I found

After googling for many hours, and came across this amazing zhs-shell plugin called https://github.com/jeffreytse/zsh-vi-mode

It got so many cool features like delete between brackets, quotations ..etc. These features not available in the original vim-mode plugin that comes with oh-my-zsh (without tweaking and configuring of course). simply add it to your zsh-shell script plugin manger in your .zshrc that's all. I hope this would be useful for anyone wish to have vim-command in his iTerm, or any other terminal application. tested for both Alacrity and iTerm2 btw.

1
  • As it’s currently written, your answer is unclear. Please edit to add additional details that will help others understand how this addresses the question asked. You can find more information on how to write good answers in the help center.
    – Community Bot
    Aug 8, 2022 at 13:23

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .