VIM
Despite the learning curve, the goal is to save milliseconds of time for each action. Before, my typical way to write a GitHub issue was editing its body and title on a web browser only after hundreds of milliseconds of HTTP requests. I want to finish the content, then submit, and while it is being uploaded, I move on to the next task. Minimize the time between creativity and documentation.
Configuration
- Set VIM as default editor
Run
gh config set editor vimto set VIM as the default editor for GitHub CLI.- Enable line numbers
Type
:set numberand press Enter. To make this permanent, addset numberto~/.vimrc.
Editing modes
- Insert mode
i: Insert before the cursora: Insert after the cursorI: Insert at the beginning of the lineA: Insert at the end of the lineo: Insert a new line below and enter insert modeO: Insert a new line above and enter insert mode
- Visual mode
v: Enter character-wise visual modeV: Enter line-wise visual modectrl-v: Enter block-wise visual mode
Deleting text
- Character deletion
x: Delete the character under the cursorX: Delete the character before the cursor<number>x: Delete multiple characters (e.g.,3xdeletes 3 characters)dh: Delete one character to the leftdl: Delete one character to the right3dh: Delete 3 characters to the left5dl: Delete 5 characters to the right
- Word deletion
dw: Delete from the cursor to the start of the next wordde: Delete from the cursor to the end of the current worddb: Delete from the cursor to the start of the previous worddW,dE,dB: Same as above, but skip punctuation marksdf<char>: Delete from the cursor to the next<char>dt<char>: Delete from the cursor to just before the next<char>
- Line deletion
dd: Delete the entire current lineD: Delete from the cursor to the end of the linedj: Delete the current line and the line belowdk: Delete the current line and the line above
Changing text
- Replace and change
r<char>: Replace the character under the cursor with<char>cw: Change from the cursor to the start of the next word (enters insert mode)cc: Change the entire line (enters insert mode)C: Change from the cursor to the end of the line (enters insert mode)
Copy and paste
- Copying (yanking)
yy: Copy the current liney: Copy selected text in visual modeyw: Copy from the cursor to the start of the next word
- Pasting
p: Paste after the cursor or below the current lineP: Paste before the cursor or above the current line
Undo and redo
u: Undo the last change
<number>u: Undo multiple changes (e.g.,3uundoes the last 3 changes)
ctrl-r: Redo the last undone change
Advanced operations
- Search
/pattern: Search forward for pattern?pattern: Search backward for patternn: Jump to next search resultN: Jump to previous search result
- Repeat command
.: Repeat the last change command
- Join lines
J: Join the current line with the line below (removes line break)
- Indent
>>: Indent the current line to the right<<: Indent the current line to the left==: Auto-indent the current lineIn visual mode, use
>or<to indent selected lines
- Case change
~: Toggle case of the character under the cursorgU: Change selected text to uppercase (in visual mode)gu: Change selected text to lowercase (in visual mode)
- Screen positioning
zt: Move current line to top of screenzb: Move current line to bottom of screen
- Marks
m<char>: Set a mark at the current position (e.g.,masets mark ‘a’)'<char>: Jump to the line of mark (e.g.,'ajumps to mark ‘a’)`` <char>`: Jump to the exact position of mark
- Swap lines
Type
:m+1to move the current line down one position.- Search and replace
:%s/old/new/g: Replace all occurrences of “old” with “new” in the file:s/old/new/g: Replace all occurrences on the current line:%s/old/new/gc: Replace all with confirmation
Saving and exiting
:w: Save the file
:w <filename>: Save as a new filename
:q: Quit (only if no unsaved changes)
:q!: Quit without saving
:wqor:x: Save and quit
ZZ: Save and quit (shortcut)
ZQ: Quit without saving (shortcut)