From df87654d814da8fe1c59f3b5ec17eb8634f8c6ee Mon Sep 17 00:00:00 2001 From: piccihud Date: Sun, 30 Jul 2023 15:10:15 +0200 Subject: [PATCH] added bash-vi-mode.md --- linux/bash/bash-vi-mode.md | 68 ++++++++++++++++++++++++++++++++++++++ 1 file changed, 68 insertions(+) create mode 100644 linux/bash/bash-vi-mode.md diff --git a/linux/bash/bash-vi-mode.md b/linux/bash/bash-vi-mode.md new file mode 100644 index 0000000..3bea0c0 --- /dev/null +++ b/linux/bash/bash-vi-mode.md @@ -0,0 +1,68 @@ +# VI mode + +Nel file `.bashrc` aggiungere: + +```bash +set -o vi +``` + +Nel file `.inputrc`, invece, aggiungere: + +```bash +#"\e[5~": history-search-backward +#"\e[6~": history-search-forward + +set editing-mode vi +# SHOW THE VIM MODE IN THE PROMPT (COMMAND OR INSERT) +set show-mode-in-prompt on + +# SET THE MODE STRING AND CURSOR TO INDICATE THE VIM MODE +# FOR THE NUMBER AFTER `\e[`: +# 0: blinking block +# 1: blinking block (default) +# 2: steady block +# 3: blinking underline +# 4: steady underline +# 5: blinking bar (xterm) +# 6: steady bar (xterm) + +set vi-ins-mode-string (ins)\1\e[5 q\2 +set vi-cmd-mode-string (cmd)\1\e[1 q\2 + +$if mode=vi + set keymap vi-command + "k": history-substring-search-backward + "j": history-substring-search-forward +# + set keymap vi-insert + "\C-l": clear-screen +$endif +``` + +Quindi per visualizzare immediatamente gli effetti: + +```bash +source .bashrc +``` + +## Comandi principali + +Si possono utilizzare tutti i comandi e le modalità di VIM, tra cui: + +| Emacs | Vim | Result | +| --- | --- | --- | +| Ctrl+A | 0 | Move cursor to beginning of line. | +| Ctrl+E | $ | Move cursor to end of line. | +| Alt+B | b | Move cursor back one word. | +| Alt+F | w | Move cursor right one word. | +| Ctrl+B | h | Move cursor back one character. | +| Ctrl+F | l | Move cursor right one character. | +| Ctrl+P | k | Move up in Bash command history. | +| Ctrl+R | j | Move down in Bash command history. | + + +## Collegamenti + +- [https://stackoverflow.com/questions/1039713/different-bash-prompt-for-different-vi-editing-mode](https://stackoverflow.com/questions/1039713/different-bash-prompt-for-different-vi-editing-mode) +- [https://www.reddit.com/r/commandline/comments/1526ck1/how_to_add_vim_to_your_bash_prompt/](https://www.reddit.com/r/commandline/comments/1526ck1/how_to_add_vim_to_your_bash_prompt/) +- [https://dev.to/brandonwallace/how-to-use-vim-mode-on-the-command-line-in-bash-fnn](https://dev.to/brandonwallace/how-to-use-vim-mode-on-the-command-line-in-bash-fnn)