Enabling vi Mode
To enable vi mode in Bash, add the following line to your .bashrc file:
set -o vi
Then, reload your .bashrc file:
source ~/.bashrc
Basic Modes
- Command Mode: This is the default mode. You can navigate and edit the command line.
- Insert Mode: Enter this mode to insert text. Press
ito switch to Insert mode from Command mode.
Navigation
h,j,k,l: Move left, down, up, and right respectively.0: Move to the beginning of the line.$: Move to the end of the line.w: Move to the beginning of the next word.b: Move to the beginning of the previous word.
Editing
x: Delete the character under the cursor.dw: Delete from the cursor to the end of the word.dd: Delete the entire line.u: Undo the last change.Ctrl-r: Redo the last undone change.
Inserting Text
i: Insert text before the cursor.a: Insert text after the cursor.I: Insert text at the beginning of the line.A: Insert text at the end of the line.o: Open a new line below the current line and enter Insert mode.
Searching
/pattern: Search forward forpattern.?pattern: Search backward forpattern.n: Repeat the last search in the same direction.N: Repeat the last search in the opposite direction.
Miscellaneous
.: Repeat the last command.Ctrl-[: Exit Insert mode and return to Command mode.v: Open the current command in thevieditor.
No comments:
Post a Comment