Skip to content

Instantly share code, notes, and snippets.

@sebastiancarlos
Last active May 3, 2024 18:10
Show Gist options
  • Save sebastiancarlos/b3668160d793d7cb3552cef57000755a to your computer and use it in GitHub Desktop.
Save sebastiancarlos/b3668160d793d7cb3552cef57000755a to your computer and use it in GitHub Desktop.
Add vi mode to your Bash prompt.
# All my gist code is licensed under the terms of the MIT license.
# Video demo: https://www.youtube.com/shorts/7IEfnUqjaSk
# add the contents of this file to ~/.inputrc
# this is where the magic happens
set editing-mode vi
# vi INSERT prompt
set vi-ins-mode-string "\1\e[30;44m\2 INS \1\e[0m\2 "
# vi NORMAL prompt
set vi-cmd-mode-string "\1\e[30;47m\2 NOR \1\e[0m\2 "
# bash is a nice place to mix and match vim and emacs, to find your personal style
$if mode=vi
# bind substring history commands to j and k on vi's command mode
set keymap vi-command
"k": history-substring-search-backward
"j": history-substring-search-forward
# I can't live without C-l to clear the screen
set keymap vi-insert
"\C-l": clear-screen
$endif
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment