Skip to content

Instantly share code, notes, and snippets.

@ehsan18t
Last active May 20, 2025 09:05
Show Gist options
  • Select an option

  • Save ehsan18t/43d6b1bff474f0de8d164697b506f684 to your computer and use it in GitHub Desktop.

Select an option

Save ehsan18t/43d6b1bff474f0de8d164697b506f684 to your computer and use it in GitHub Desktop.

Revisions

  1. ehsan18t revised this gist May 20, 2025. 1 changed file with 1 addition and 1 deletion.
    2 changes: 1 addition & 1 deletion vim-vscode.md
    Original file line number Diff line number Diff line change
    @@ -356,7 +356,7 @@ Folding allows you to collapse sections of text, making it easier to navigate la
    * **Cheat Sheet**: GitHub Gist with condensed commands
    * **vim-awesome.com**: directory of plugins

    --
    ---

    ## 13. VSCode Keybindings for NeoVim
    ```jsonc
  2. ehsan18t revised this gist May 20, 2025. 1 changed file with 1 addition and 1 deletion.
    2 changes: 1 addition & 1 deletion vim-vscode.md
    Original file line number Diff line number Diff line change
    @@ -359,7 +359,7 @@ Folding allows you to collapse sections of text, making it easier to navigate la
    --

    ## 13. VSCode Keybindings for NeoVim
    ```json
    ```jsonc
    // Custom Keybindings for VS Code

    [
  3. ehsan18t revised this gist May 20, 2025. 1 changed file with 111 additions and 0 deletions.
    111 changes: 111 additions & 0 deletions vim-vscode.md
    Original file line number Diff line number Diff line change
    @@ -355,3 +355,114 @@ Folding allows you to collapse sections of text, making it easier to navigate la
    * **Practical Vim** by Drew Neil: excellent book for intermediate users
    * **Cheat Sheet**: GitHub Gist with condensed commands
    * **vim-awesome.com**: directory of plugins

    --

    ## 13. VSCode Keybindings for NeoVim
    ```json
    // Custom Keybindings for VS Code

    [
    // === Text Transformation Commands ===
    {
    "key": "ctrl+alt+u",
    "command": "editor.action.transformToUppercase",
    "when": "editorTextFocus",
    "description": "Transform selected text to uppercase."
    },
    {
    "key": "ctrl+alt+l",
    "command": "editor.action.transformToLowercase",
    "when": "editorTextFocus",
    "description": "Transform selected text to lowercase."
    },
    {
    "key": "ctrl+alt+t",
    "command": "editor.action.transformToTitlecase",
    "when": "editorTextFocus",
    "description": "Transform selected text to title case."
    },

    // === Replace Functionality ===
    {
    "key": "ctrl+h",
    "command": "editor.action.startFindReplaceAction",
    "when": "editorTextFocus && !inDebugRepl",
    "description": "Open the find and replace dialog."
    },

    // === Line Movement Commands ===
    {
    "key": "alt+k",
    "command": "editor.action.moveLinesUpAction",
    "when": "editorTextFocus && !editorReadonly",
    "description": "Move the current line or selected lines up."
    },
    {
    "key": "alt+j",
    "command": "editor.action.moveLinesDownAction",
    "when": "editorTextFocus && !editorReadonly",
    "description": "Move the current line or selected lines down."
    },
    {
    "key": "alt+up",
    "command": "editor.action.moveLinesUpAction",
    "when": "editorTextFocus && !editorReadonly",
    "description": "Alternative keybinding to move lines up."
    },
    {
    "key": "alt+down",
    "command": "editor.action.moveLinesDownAction",
    "when": "editorTextFocus && !editorReadonly",
    "description": "Alternative keybinding to move lines down."
    },

    // === Editor Navigation Commands ===
    {
    "key": "alt+h",
    "command": "workbench.action.previousEditor",
    "when": "editorTextFocus && !editorReadonly",
    "description": "Switch to the previous editor tab."
    },
    {
    "key": "alt+l",
    "command": "workbench.action.nextEditor",
    "when": "editorTextFocus && !editorReadonly",
    "description": "Switch to the next editor tab."
    },

    // === File and Buffer Management ===
    {
    "key": "ctrl+s",
    "command": "workbench.action.files.save",
    "when": "neovim.mode == 'normal' && editorTextFocus",
    "description": "Save the current file (specific to Neovim mode)."
    },
    {
    "key": "space f",
    "command": "workbench.action.quickOpen",
    "when": "neovim.mode == 'normal' && editorTextFocus",
    "description": "Open the file finder (Space + F)."
    },
    {
    "key": "space b",
    "command": "workbench.action.showAllEditors",
    "when": "neovim.mode == 'normal' && editorTextFocus",
    "description": "Show all open buffers/tabs (Space + B)."
    },

    // === Clipboard and Selection Commands ===
    {
    "key": "ctrl+c",
    "command": "editor.action.clipboardCopyAction",
    "when": "editorTextFocus",
    "description": "Copy selected text to the clipboard."
    },
    {
    "key": "ctrl+a",
    "command": "editor.action.selectAll",
    "when": "editorTextFocus",
    "description": "Select all text in the current editor."
    }
    ]
    ```
  4. ehsan18t revised this gist May 20, 2025. 1 changed file with 92 additions and 28 deletions.
    120 changes: 92 additions & 28 deletions vim-vscode.md
    Original file line number Diff line number Diff line change
    @@ -75,6 +75,17 @@ Vim is a **modal editor**, meaning its behavior changes based on the current mod
    * `Ctrl+o` / `Ctrl+i`: jump backward/forward through positions
    * `:jumps`: display jump list

    ### 2.6 Advanced Navigation

    * `g;` / `g,`: jump to the last change (backward/forward)
    * `]m` / `[m`: jump to the start of the next/previous method or function
    * `]` / `[`: jump to the next/previous unmatched `[{` or `]}`
    * `:help motion.txt`: explore all motion commands in Vim's help system

    **Examples:**
    - After editing multiple lines, use `g;` to revisit the last change.
    - In a code file, use `]m` to jump to the next function definition.

    ---

    ## 3. Editing Basics
    @@ -172,19 +183,23 @@ Operate on **semantic blocks** using `operator + text-object`:

    ## 5. Search & Replace

    * `/pattern` / `?pattern`: search forward / backward
    * `n` / `N`: repeat search forward / backward
    * `*` / `#`: search for word under cursor forward / backward
    * `:%s/old/new/g`: replace all occurrences of 'old' with 'new'
    * `:%s/old/new/gc`: replace all with confirmation
    * `:%s/old/new/gi`: replace all, case insensitive
    Vim's search and replace feature is powerful and supports regular expressions.

    ### Basic Commands:
    * `/pattern` / `?pattern`: Search forward / backward for `pattern`.
    * `n` / `N`: Repeat the search forward / backward.
    * `:%s/old/new/g`: Replace all occurrences of `old` with `new` in the file.
    * `:%s/old/new/gc`: Replace all occurrences with confirmation.
    * `:%s/old/new/gi`: Replace all occurrences, case-insensitive.

    ### Advanced Examples:
    - `/\<word\>`: Search for the exact word `word` (not part of another word).
    - `/\d\+`: Search for one or more digits.
    - `/^\s*function`: Search for lines starting with `function` (ignoring leading spaces).
    - `:%s/\(\w\+\)/"\1"/g`: Surround every word with quotes.
    - `:g/TODO/d`: Delete all lines containing "TODO".

    **Advanced Search Examples:**
    - `/\<word\>`: search for exact word (not part of other words)
    - `/\d\+`: search for one or more digits
    - `/^\s*function`: search for function at start of line (possibly indented)
    - `:%s/\(\w\+\)/"\1"/g`: put quotes around words
    - `:g/TODO/d`: delete all lines containing "TODO"
    **Tip for Beginners**: Use `:set hlsearch` to highlight search results and `:noh` to clear the highlights.

    ---

    @@ -206,6 +221,25 @@ Operate on **semantic blocks** using `operator + text-object`:

    ## 7. Registers

    ### 7.1 Register Types

    Registers are like "named clipboards" in Vim. They store text for yanking, deleting, or copying. Here are the main types:

    * **Unnamed Register (`""`)**: Stores the last deleted or yanked text. This is the default register used when no specific register is mentioned.
    * **Numbered Registers (`"0` to `"9`)**:
    - `"0`: Stores the last yanked text.
    - `"1` to `"9`: Store the last nine deletions, with `"1` being the most recent.
    * **Named Registers (`"a` to `"z`)**: Manually store text using `"ay{motion}` (e.g., `"ayw` yanks a word into register `a`).
    * **System Clipboard (`"+`)**: Interact with the system clipboard. Use `"+y` to copy to the clipboard and `"+p` to paste from it.
    * **Black Hole Register (`"_`)**: Discards text without saving it to any register. Useful for deleting without overwriting the unnamed register.

    **Examples:**
    - Yank text into a named register: `"ayw` (yank a word into register `a`).
    - Paste from the system clipboard: `"+p`.
    - Delete without saving: `"_dd` (deletes the current line without affecting registers).

    ### 7.2 Register Commands

    * `"{reg}y{motion}`: yank into register {reg}
    * `"{reg}p`: paste from register {reg}
    * `"+y{motion}` / `"+p`: yank to / paste from system clipboard
    @@ -222,30 +256,61 @@ Operate on **semantic blocks** using `operator + text-object`:

    ## 8. Macros

    * `q{reg}`: start recording macro into register {reg}
    * `q`: stop recording
    * `@{reg}`: execute macro in register {reg}
    * `@@`: repeat last executed macro
    * `{count}@{reg}`: execute macro {count} times
    Macros allow you to record a sequence of commands and replay them.

    ### Commands:
    * `q{reg}`: Start recording a macro into register `{reg}` (e.g., `qa` starts recording into register `a`).
    * `q`: Stop recording.
    * `@{reg}`: Execute the macro stored in register `{reg}`.
    * `@@`: Repeat the last executed macro.
    * `{count}@{reg}`: Execute the macro `{count}` times.

    **Examples:**
    - `qa` โ†’ make changes โ†’ `q`: record macro in register `a`
    - `5@a`: execute macro `a` 5 times
    - `qbI// ^[j0q`: record macro to comment lines (`^[` means press `Esc`)
    1. **Add a prefix to multiple lines**:
    - `qa` โ†’ `I// ` โ†’ `Esc` โ†’ `j` โ†’ `q` (record macro to add `//` at the start of a line).
    - `@a` to apply the macro once, or `10@a` to apply it to 10 lines.

    2. **Format a list**:
    - `qa` โ†’ `0i- ` โ†’ `Esc` โ†’ `j` โ†’ `q` (record macro to add `-` at the start of a line).
    - Use `@a` to repeat for a list of items.

    **Tip for Beginners**: If you make a mistake while recording, press `q` to stop and start over.

    ### 8.1 Practical Macro Examples

    1. **Add a prefix to multiple lines**:
    - `qa` โ†’ `I// ` โ†’ `Esc` โ†’ `j` โ†’ `q`
    - `@a` to apply once, or `10@a` to apply to 10 lines.

    2. **Format a list**:
    - `qa` โ†’ `0i- ` โ†’ `Esc` โ†’ `j` โ†’ `q`
    - Use `@a` to repeat for a list of items.

    3. **Swap two words**:
    - `qa` โ†’ `diw` โ†’ `e` โ†’ `P` โ†’ `q`
    - Use `@a` to repeat the swap.

    ---

    ## 9. Folding

    * `zf{motion}`: create fold
    * `zo` / `zc`: open / close fold
    * `zr` / `zm`: reduce / more folding (entire file)
    * `zR` / `zM`: open / close all folds
    * `zj` / `zk`: move to next / previous fold
    Folding allows you to collapse sections of text, making it easier to navigate large files.

    ### Commands:
    * `zf{motion}`: Create a fold for the specified motion (e.g., `zf%` folds everything between matching brackets).
    * `zo` / `zc`: Open / close a fold.
    * `zr` / `zm`: Reduce / increase the fold level for the entire file.
    * `zR` / `zM`: Open / close all folds.
    * `zj` / `zk`: Move to the next / previous fold.

    **Examples:**
    - `zfa{`: create fold for current code block in curly braces
    - `zo` โ†’ make changes โ†’ `zc`: open fold, edit, close fold
    - To fold a function:
    1. Place the cursor at the start of the function.
    2. Use `zf%` to fold everything between the matching brackets.
    - To open all folds: `zR`.
    - To close all folds: `zM`.

    **Tip for Beginners**: If folding doesn't work, ensure `:set foldmethod=manual` or `:set foldmethod=syntax` is enabled.

    ---

    @@ -290,4 +355,3 @@ Operate on **semantic blocks** using `operator + text-object`:
    * **Practical Vim** by Drew Neil: excellent book for intermediate users
    * **Cheat Sheet**: GitHub Gist with condensed commands
    * **vim-awesome.com**: directory of plugins

  5. ehsan18t revised this gist May 20, 2025. 1 changed file with 251 additions and 230 deletions.
    481 changes: 251 additions & 230 deletions vim-vscode.md
    Original file line number Diff line number Diff line change
    @@ -4,269 +4,290 @@
    </div>

    &nbsp;
    ### ๐Ÿ’  Mode
    * `ESC` / `Ctrl + [` - Normal Mode
    * `a` - Insert Mode (After Current Char)
    * `i` - Insert Mode (Before Current Char)
    * `v` - Visual Mode / Selection Mode
    * `R` - Replace Mode
    * `:` - Command Mode

    &nbsp;
    ### ๐Ÿ’  Arrow
    * `h` - Left arrow
    * `l` - Right arrow
    * `j` - Down arrow
    * `k` - Up arrow
    ## 1. Vim Philosophy & Essential Modes

    &nbsp;
    ### ๐Ÿ’  Search
    * `/pattern` - Search forward
    * `?pattern` - Search backward
    * `n` - Repeat search forward
    * `N` - Repeat search backward
    Vim is a **modal editor**, meaning its behavior changes based on the current modeโ€”no mouse required!

    &nbsp;
    ### ๐Ÿ’  Jump
    **`๐Ÿ”น Char (Inside Current Line)`**
    * `fc` - Go forward to character `c`
    * `Fc` - Go backward to character `c`
    * `tc` - Go forward before character `c`
    * `Tc` - Go backward before character `c`
    * `;` - Go forward next
    * `,` - Go backward next

    <br>

    **`๐Ÿ”น Word`**
    * `e` - Last char before space
    * `w` - Next word (first char)
    * `b` - Previous word (first char)
    * `ge` - Previous Word (last char)
    * `*` - Next same word
    * `#` - Previous same word

    <br>

    **`๐Ÿ”น Current Line`**
    * `0` - Start of the line
    * `^` - Start of the line (after whitespace)
    * `I` - Start of the line and insert (after whitespace)
    * `$` - End of the line
    * `A` - End of the line and insert

    <br>

    **`๐Ÿ”น Line`**
    * `o` - Next line and insert
    * `O` - Previous line and insert
    * `gg` - First line
    * `G` - Last line
    * `:n` - Goto n line
    * `nG` - Goto n line

    <br>

    **`๐Ÿ”น Block / Paragraph`**
    * `{` - Move up
    * `}` - Move down
    * `%` - Jump between braces (`(` `)`, `{` `}`, `[` `]`)

    <br>

    **`๐Ÿ”น Window / Page`**
    * `zz` - Center this line
    * `zt` - Top this line
    * `zb` - Bottom this line
    * `H` - Top of screen
    * `M` - Middle of screen
    * `L` - Bottom of screen
    * `Ctrl + u` - Page up (Half page)
    * `Ctrl + d` - Page down (Half page)

    <br>

    **`๐Ÿ”น Tab`**
    * `:tabclose` - Close current tab
    * `:tabfirst` - First tab
    * `:tablast` - Last tab
    * `:tabn` - Next tab
    * `tabp` - Previous tab
    ### Modes Overview

    &nbsp;
    | Mode | Enter | Exit | Purpose |
    | ----------- | ------------------ | ------- | ------------------------------- |
    | **Normal** | `Esc` / `Ctrl+[` | โ€” | Navigation & commands (default) |
    | **Insert** | `i`, `a`, `o` | `Esc` | Typing text |
    | **Visual** | `v`, `V`, `Ctrl+V` | `Esc` | Text selection |
    | **Replace** | `R` | `Esc` | Overwrite existing text |
    | **Command** | `:` | `Enter` | Ex commands (`:w`, `:q`, etc.) |

    ### ๐Ÿ’  Select
    * `ve` - Select until next space
    * `vw` - Select until next word (Highlight word)
    * `V` - Select current line
    * `v` - Select current char (Highlight char)
    **Mode Context Examples:**
    - Normal mode: `dd` deletes a line, but in Insert mode types "dd"
    - Visual mode: select text with movement keys, then operate on selection
    - Replace mode: typing replaces existing characters (useful for tables)

    &nbsp;
    ---

    ### ๐Ÿ’  Copy
    * `y` - Copy selected (Only in visual mode)
    * `yy` - Copy current line
    * `yw` - Copy current word
    * `yj` - Copy current and previous line
    * `yk` - Copy current and next line
    ## 2. Basic Navigation

    &nbsp;
    ### 2.1 Character & Word Motions

    ### ๐Ÿ’  Editing
    **`๐Ÿ”น Paste`**
    * `p` - Paste next
    * `P` - Paste Previous
    * `h`/`j`/`k`/`l`: โ† โ†“ โ†‘ โ†’
    * `w`: jump to **start** of next word
    * `b`: jump to **start** of previous word
    * `e`: move to **end** of current word
    * `ge`: move to **end** of previous word
    * `*` / `#`: search forward/backward for word under cursor
    * `W`/`B`/`E`: same as `w`/`b`/`e` but for WORDS (space-separated)

    <br>
    **Examples:**
    - In `hello_world` with cursor at `h`, `w` jumps to `_`, but `W` jumps to next space

    **`๐Ÿ”น Delete`**
    * `x` - Delete current char
    * `s` - Delete current char and insert
    * `cw` - Delete all char before space and insert (from cursor)
    * `dw` - Delete until next word
    * `diw` - Delete current word
    * `X` - Delete current word and insert (Custom `bdwi`)
    * `dd` - Delete current line
    * `S` - Delete current line and insert
    * `D` - Delete the rest of the line
    * `C` - Delete the rest of the line and insert
    ### 2.2 Line & File Navigation

    * `0` / `^` / `$`: line start / first non-blank / line end
    * `gg` / `G`: first line / last line
    * `:n` / `nG`: go to line n (e.g. `:5` or `10G`)
    * `%`: jump to matching bracket (`()`, `{}`, `[]`)
    * `{` / `}`: jump to previous/next paragraph
    * `H` / `M` / `L`: jump to Home/Middle/Last line of visible screen

    <br>
    **Examples:**
    - In ` function() {`, pressing `^` from start jumps to `f`
    - With cursor on `{`, press `%` to jump to matching `}`

    **`๐Ÿ”น Replace`**
    * `r` - Replace one character
    * `R` - Replace multiple character (Replace Mode)
    ### 2.3 Screen Scrolling & Positioning

    * `Ctrl+u` / `Ctrl+d`: scroll up/down half-page
    * `Ctrl+b` / `Ctrl+f`: scroll up/down full-page
    * `zt` / `zz` / `zb`: move current line to top / center / bottom of screen

    <br>
    ### 2.4 Jump to Character

    **`๐Ÿ”น Undo/Redo`**
    * `u` - Undo changes
    * `Ctrl + r` - Redo
    * `f{c}` / `F{c}`: forward/backward to `{c}` on line
    * `t{c}` / `T{c}`: forward/backward until before `{c}`
    * `;` / `,`: repeat last `f`/`t` forward/backward

    **Examples:**
    - In `function(arg)`, with cursor at `f`, type `f(` to jump to `(`
    - Then `;` to jump to next `(` if any on the line

    <br>
    ### 2.5 Jump List Navigation

    ### ๐Ÿ’  Exit
    * `:q` - Close file
    * `:q!` - Close file, abandon changes
    * `:qa` - Close all files
    * `:qa!` - Close all files, abandon changes
    * `:w` - Save changes
    * `:wq` / `:x` - Save and close file
    * `ZZ` - Save and quit
    * `ZQ` - Quit without checking changes
    * `Ctrl+o` / `Ctrl+i`: jump backward/forward through positions
    * `:jumps`: display jump list

    <br>
    ---

    ## 3. Editing Basics

    ### ๐Ÿ’  Notes & Combos
    * All keys mentioned above can be combined with one another.
    * Example: `ct)` can delete everything until `)`. That means it can be used for clear function parameter or something like that. Here `c` means `cut` and `t)` means forward until char `)`.
    * `di{` - Delete everything inside `{}`
    * `d2i{` - Delete everything inside `{}` and its surround `{}`.
    * `ct}` - Delete everything until `}` and insert.
    * `d5$` - Delete next 5 lines after cursor.
    * `0d5$` - Delete next 5 lines including current.
    * `cip` - Delete paragraph and insert
    * `di(` - Delete everything inside `()`
    * `yi(` - Copy everything inside `()`
    * `vi(` - Highlight everything inside `()`
    * `diw` - Delete current word
    ### 3.1 Inserting

    &nbsp;
    ### ๐Ÿ’  Important VSCode Configurations for New Users
    * `i` / `I`: insert before cursor / at first non-blank
    * `a` / `A`: insert after cursor / at end of line
    * `o` / `O`: open new line below / above
    * `gi`: resume insert at last insertion point

    &nbsp;
    **Examples:**
    - `A` + type `;` + `Esc`: add semicolon at end of line
    - `O` + type `// Comment` + `Esc`: add comment above current line

    **๐Ÿ”น Disable Vim `ctrl+c` `ctrl+v` `ctrl+x` commands**
    ```json
    "vim.useCtrlKeys": true,
    "vim.handleKeys": {
    "<C-c>": false,
    "<C-x>": false,
    "<C-v>": false
    }
    ```
    ### 3.2 Deleting

    &nbsp;
    * `x` / `X`: delete character under/before cursor
    * `dw` / `db`: delete to start of next/previous word
    * `dd` / `D`: delete entire line / to end of line
    * `d{motion}`: delete text covered by `{motion}`
    * `di{` / `da{`: delete inside/around curly braces (works with `()[]<>"'`)

    **๐Ÿ”น Disable Vim arrow controls**
    ```json
    "vim.handleKeys": {
    "<": false,
    ">": false
    }
    ```
    **Examples:**
    - `d$`: delete from cursor to end of line
    - `d2j`: delete current line and 2 lines below
    - `dit`: delete inside HTML/XML tag

    &nbsp;
    ### 3.3 Yanking & Pasting

    **๐Ÿ”น Enable `jj` to `Normal Mode`**
    ```json
    "vim.insertModeKeyBindingsNonRecursive": [
    {
    "before": ["j", "j"],
    "after": ["<esc>"]
    }
    ]
    ```
    &nbsp;
    * `y{motion}` / `yy` or `Y`: yank text or line
    * `p` / `P`: paste after / before cursor
    * `"ay{motion}` / `"ap`: yank to register 'a' / paste from register 'a'
    * `:reg`: view all registers
    * `"0p`: paste from yank register (not affected by deletes)

    **๐Ÿ”น Enable `X` to `Delete Current Word and Insert`**
    ```json
    "vim.normalModeKeyBindings": [
    {
    "before": ["X"],
    "after": ["b","d","w","i"]
    }
    ]
    ```
    &nbsp;
    **Examples:**
    - `yiw` then move cursor and `p`: duplicate word
    - `"ay3w` then `"ap`: yank 3 words into register 'a', then paste them

    **๐Ÿ”น Enable vim to use `System Clipboard`**
    ```json
    "vim.useSystemClipboard": true
    ```
    ### 3.4 Changing & Replacing

    &nbsp;
    * `c{motion}` / `C`: change text or to end of line
    * `s` / `S`: substitute char & insert / substitute line
    * `r{c}`: replace character under cursor with `{c}`
    * `R`: enter replace mode
    * `~`: toggle case of character under cursor

    **๐Ÿ”น Fix buggy `undo` `redo` and make it like vscode**
    ```json
    "vim.normalModeKeyBindingsNonRecursive": [
    {
    "before": ["u"],
    "after": [],
    "commands": [
    {
    "command": "undo",
    "args": []
    }
    ]
    },
    {
    "before": ["<C-r>"],
    "after": [],
    "commands": [
    {
    "command": "redo",
    "args": []
    }
    ]
    }
    ]
    ```
    **Examples:**
    - `ct)`: change text until next `)` (excl.)
    - `cw`: change word (like `dw` then `i`)
    - `cc`: change entire line (like `dd` then `i`)

    &nbsp;
    ### 3.5 Undo & Redo

    * `u` / `Ctrl+r`: undo / redo changes
    * `U`: undo all changes on line
    * `.`: repeat last change

    ---

    ## 4. Visual Mode & Text Objects

    ### 4.1 Entering Visual Mode

    * `v` / `V` / `Ctrl+V`: character / line / block selection
    * `gv`: reselect last visual selection

    **Visual Block Examples:**
    - `Ctrl+V` โ†’ select multiple lines โ†’ `I` โ†’ type text โ†’ `Esc`: insert at beginning of multiple lines
    - `Ctrl+V` โ†’ select block โ†’ `d`: delete block
    - `Ctrl+V` โ†’ select block โ†’ `r{c}`: replace with character

    ### 4.2 Text Objects

    Operate on **semantic blocks** using `operator + text-object`:

    | Object | Inner (`i`) | Around (`a`) |
    | ----------- | ----------- | ------------ |
    | Word | `iw` | `aw` |
    | Sentence | `is` | `as` |
    | Paragraph | `ip` | `ap` |
    | Quotes `"` | `i"` | `a"` |
    | Parentheses | `i(` | `a(` |
    | Tags | `it` | `at` |

    **Examples:**
    - `ci"` changes inside quotes (`"hello"` โ†’ `""` with cursor between quotes)
    - `dap` deletes around paragraph (including trailing blank line)
    - `vib` visually select inside parentheses
    - `ya]` yank around square brackets (including the brackets)
    - `dit` delete inside HTML/XML tag (leaves the tags intact)

    ---

    ## 5. Search & Replace

    * `/pattern` / `?pattern`: search forward / backward
    * `n` / `N`: repeat search forward / backward
    * `*` / `#`: search for word under cursor forward / backward
    * `:%s/old/new/g`: replace all occurrences of 'old' with 'new'
    * `:%s/old/new/gc`: replace all with confirmation
    * `:%s/old/new/gi`: replace all, case insensitive

    **Advanced Search Examples:**
    - `/\<word\>`: search for exact word (not part of other words)
    - `/\d\+`: search for one or more digits
    - `/^\s*function`: search for function at start of line (possibly indented)
    - `:%s/\(\w\+\)/"\1"/g`: put quotes around words
    - `:g/TODO/d`: delete all lines containing "TODO"

    ---

    ## 6. Marks & Jumps

    * `ma`: set mark `a` at cursor
    * `` `a`` / `'a`: jump to exact position / line of mark `a`
    * `` `. `` / `'.`: jump to last edit position / line
    * `` `[ `` / `` `] ``: jump to start/end of last change or yank
    * `` `< `` / `` `> ``: jump to start/end of last visual selection
    * `` `0 `` through `` `9 ``: jump to position when Vim was last closed

    **Examples:**
    - `ma` at start of function, `mz` at end, then `` `a`` and `` `z`` to navigate
    - `d'a`: delete from current line to line marked with `a`
    - `y`a'b`: yank text from mark `a` to mark `b`

    ---

    ## 7. Registers

    * `"{reg}y{motion}`: yank into register {reg}
    * `"{reg}p`: paste from register {reg}
    * `"+y{motion}` / `"+p`: yank to / paste from system clipboard
    * `"_d{motion}`: delete without saving to register (black hole)
    * `"0p`: paste from yank register (not affected by `d` or `c`)
    * `:reg`: view register contents

    **Examples:**
    - `"ayy` then `"ap`: copy line to register `a`, then paste it
    - `"+yG`: yank from cursor to end of file to system clipboard
    - `"_dd`: delete line without affecting registers (useful before pasting)

    ---

    ## 8. Macros

    * `q{reg}`: start recording macro into register {reg}
    * `q`: stop recording
    * `@{reg}`: execute macro in register {reg}
    * `@@`: repeat last executed macro
    * `{count}@{reg}`: execute macro {count} times

    **Examples:**
    - `qa` โ†’ make changes โ†’ `q`: record macro in register `a`
    - `5@a`: execute macro `a` 5 times
    - `qbI// ^[j0q`: record macro to comment lines (`^[` means press `Esc`)

    ---

    ## 9. Folding

    * `zf{motion}`: create fold
    * `zo` / `zc`: open / close fold
    * `zr` / `zm`: reduce / more folding (entire file)
    * `zR` / `zM`: open / close all folds
    * `zj` / `zk`: move to next / previous fold

    **Examples:**
    - `zfa{`: create fold for current code block in curly braces
    - `zo` โ†’ make changes โ†’ `zc`: open fold, edit, close fold

    ---

    ## 10. Multiple Windows & Buffers

    * `:split` / `:vsplit`: horizontal / vertical split
    * `Ctrl+w` + `h`/`j`/`k`/`l`: navigate between windows
    * `Ctrl+w` + `_`/`|`: maximize height/width of current window
    * `Ctrl+w` + `=`: make all windows equal size
    * `:e file`: edit file in new buffer
    * `:ls`: list buffers
    * `:bn` / `:bp`: next / previous buffer
    * `:bd`: delete (close) buffer

    **Examples:**
    - `:vsplit index.js` โ†’ `Ctrl+w l` โ†’ edit in right window
    - `:e` in insert mode completes filenames

    ---

    ## 11. Practice Exercises

    1. **Delete a word**: `This is a test|` โ†’ `dw` โ†’ `This is a |`
    2. **Change inside quotes**: `"Learn Vim|"` โ†’ `ci"` โ†’ type `Master` โ†’ `"Master"`
    3. **Jump to line 5**: `5G` or `:5`
    4. **Visual delete paragraph**: place cursor in paragraph โ†’ `vap` โ†’ `d`
    5. **Search & replace**: `/foo` โ†’ `:%s/foo/bar/gc`
    6. **Multi-line edit**: `Ctrl+V` โ†’ select multiple lines โ†’ `I` โ†’ type โ†’ `Esc`
    7. **Macro for formatting**: `qa` โ†’ `0i- [ ] ^[j` โ†’ `q` โ†’ `10@a` (adds checkboxes)
    8. **Double quoted string**: `Hello` โ†’ `viw` โ†’ `S"` โ†’ `"Hello"`
    9. **swap two words**: `one two` โ†’ `dwelp` โ†’ `two one`
    10. **Sort lines**: `:'<,'>sort` in visual selection

    ---

    ## 12. Further Resources

    * **vimtutor**: built-in interactive tutorial (`vimtutor`)
    * **Vim Adventures**: gamified learning at vim-adventures.com
    * **Vimcasts**: free screencasts by Drew Neil for step-by-step demos (vimcasts.org)
    * **vim-wiki**: comprehensive wiki at vimhelp.org
    * **Practical Vim** by Drew Neil: excellent book for intermediate users
    * **Cheat Sheet**: GitHub Gist with condensed commands
    * **vim-awesome.com**: directory of plugins

    **๐Ÿ”น Enable move cursor to each wrapped line (if wrap line enable)**
    ```json
    {
    "before": ["j"],
    "after": ["g", "j"]
    },
    {
    "before": ["k"],
    "after": ["g", "k"]
    }
    ```
  6. ehsan18t revised this gist May 3, 2021. 1 changed file with 15 additions and 1 deletion.
    16 changes: 15 additions & 1 deletion vim-vscode.md
    Original file line number Diff line number Diff line change
    @@ -245,7 +245,7 @@
    ]
    },
    {
    "before": ["<C-r>"],
    "before": ["<C-r>"],
    "after": [],
    "commands": [
    {
    @@ -256,3 +256,17 @@
    }
    ]
    ```

    &nbsp;

    **๐Ÿ”น Enable move cursor to each wrapped line (if wrap line enable)**
    ```json
    {
    "before": ["j"],
    "after": ["g", "j"]
    },
    {
    "before": ["k"],
    "after": ["g", "k"]
    }
    ```
  7. ehsan18t revised this gist Apr 30, 2021. 1 changed file with 0 additions and 1 deletion.
    1 change: 0 additions & 1 deletion vim-vscode.md
    Original file line number Diff line number Diff line change
    @@ -256,4 +256,3 @@
    }
    ]
    ```

  8. ehsan18t revised this gist Apr 28, 2021. 1 changed file with 40 additions and 2 deletions.
    42 changes: 40 additions & 2 deletions vim-vscode.md
    Original file line number Diff line number Diff line change
    @@ -9,6 +9,7 @@
    * `a` - Insert Mode (After Current Char)
    * `i` - Insert Mode (Before Current Char)
    * `v` - Visual Mode / Selection Mode
    * `R` - Replace Mode
    * `:` - Command Mode

    &nbsp;
    @@ -130,6 +131,14 @@
    * `D` - Delete the rest of the line
    * `C` - Delete the rest of the line and insert


    <br>

    **`๐Ÿ”น Replace`**
    * `r` - Replace one character
    * `R` - Replace multiple character (Replace Mode)


    <br>

    **`๐Ÿ”น Undo/Redo`**
    @@ -139,7 +148,6 @@

    <br>


    ### ๐Ÿ’  Exit
    * `:q` - Close file
    * `:q!` - Close file, abandon changes
    @@ -159,7 +167,8 @@
    * `di{` - Delete everything inside `{}`
    * `d2i{` - Delete everything inside `{}` and its surround `{}`.
    * `ct}` - Delete everything until `}` and insert.
    * `v5$d` - Delete next 5 lines including current.
    * `d5$` - Delete next 5 lines after cursor.
    * `0d5$` - Delete next 5 lines including current.
    * `cip` - Delete paragraph and insert
    * `di(` - Delete everything inside `()`
    * `yi(` - Copy everything inside `()`
    @@ -219,3 +228,32 @@
    ```json
    "vim.useSystemClipboard": true
    ```

    &nbsp;

    **๐Ÿ”น Fix buggy `undo` `redo` and make it like vscode**
    ```json
    "vim.normalModeKeyBindingsNonRecursive": [
    {
    "before": ["u"],
    "after": [],
    "commands": [
    {
    "command": "undo",
    "args": []
    }
    ]
    },
    {
    "before": ["<C-r>"],
    "after": [],
    "commands": [
    {
    "command": "redo",
    "args": []
    }
    ]
    }
    ]
    ```

  9. ehsan18t created this gist Apr 28, 2021.
    221 changes: 221 additions & 0 deletions vim-vscode.md
    Original file line number Diff line number Diff line change
    @@ -0,0 +1,221 @@
    <div align="center">
    <h1 align="center">Vim Cheatsheet for Beginners</h1>
    <Strong>These commands are tested in VSCode with Vim plugin.</strong>
    </div>

    &nbsp;
    ### ๐Ÿ’  Mode
    * `ESC` / `Ctrl + [` - Normal Mode
    * `a` - Insert Mode (After Current Char)
    * `i` - Insert Mode (Before Current Char)
    * `v` - Visual Mode / Selection Mode
    * `:` - Command Mode

    &nbsp;
    ### ๐Ÿ’  Arrow
    * `h` - Left arrow
    * `l` - Right arrow
    * `j` - Down arrow
    * `k` - Up arrow

    &nbsp;
    ### ๐Ÿ’  Search
    * `/pattern` - Search forward
    * `?pattern` - Search backward
    * `n` - Repeat search forward
    * `N` - Repeat search backward

    &nbsp;
    ### ๐Ÿ’  Jump
    **`๐Ÿ”น Char (Inside Current Line)`**
    * `fc` - Go forward to character `c`
    * `Fc` - Go backward to character `c`
    * `tc` - Go forward before character `c`
    * `Tc` - Go backward before character `c`
    * `;` - Go forward next
    * `,` - Go backward next

    <br>

    **`๐Ÿ”น Word`**
    * `e` - Last char before space
    * `w` - Next word (first char)
    * `b` - Previous word (first char)
    * `ge` - Previous Word (last char)
    * `*` - Next same word
    * `#` - Previous same word

    <br>

    **`๐Ÿ”น Current Line`**
    * `0` - Start of the line
    * `^` - Start of the line (after whitespace)
    * `I` - Start of the line and insert (after whitespace)
    * `$` - End of the line
    * `A` - End of the line and insert

    <br>

    **`๐Ÿ”น Line`**
    * `o` - Next line and insert
    * `O` - Previous line and insert
    * `gg` - First line
    * `G` - Last line
    * `:n` - Goto n line
    * `nG` - Goto n line

    <br>

    **`๐Ÿ”น Block / Paragraph`**
    * `{` - Move up
    * `}` - Move down
    * `%` - Jump between braces (`(` `)`, `{` `}`, `[` `]`)

    <br>

    **`๐Ÿ”น Window / Page`**
    * `zz` - Center this line
    * `zt` - Top this line
    * `zb` - Bottom this line
    * `H` - Top of screen
    * `M` - Middle of screen
    * `L` - Bottom of screen
    * `Ctrl + u` - Page up (Half page)
    * `Ctrl + d` - Page down (Half page)

    <br>

    **`๐Ÿ”น Tab`**
    * `:tabclose` - Close current tab
    * `:tabfirst` - First tab
    * `:tablast` - Last tab
    * `:tabn` - Next tab
    * `tabp` - Previous tab

    &nbsp;

    ### ๐Ÿ’  Select
    * `ve` - Select until next space
    * `vw` - Select until next word (Highlight word)
    * `V` - Select current line
    * `v` - Select current char (Highlight char)

    &nbsp;

    ### ๐Ÿ’  Copy
    * `y` - Copy selected (Only in visual mode)
    * `yy` - Copy current line
    * `yw` - Copy current word
    * `yj` - Copy current and previous line
    * `yk` - Copy current and next line

    &nbsp;

    ### ๐Ÿ’  Editing
    **`๐Ÿ”น Paste`**
    * `p` - Paste next
    * `P` - Paste Previous

    <br>

    **`๐Ÿ”น Delete`**
    * `x` - Delete current char
    * `s` - Delete current char and insert
    * `cw` - Delete all char before space and insert (from cursor)
    * `dw` - Delete until next word
    * `diw` - Delete current word
    * `X` - Delete current word and insert (Custom `bdwi`)
    * `dd` - Delete current line
    * `S` - Delete current line and insert
    * `D` - Delete the rest of the line
    * `C` - Delete the rest of the line and insert

    <br>

    **`๐Ÿ”น Undo/Redo`**
    * `u` - Undo changes
    * `Ctrl + r` - Redo


    <br>


    ### ๐Ÿ’  Exit
    * `:q` - Close file
    * `:q!` - Close file, abandon changes
    * `:qa` - Close all files
    * `:qa!` - Close all files, abandon changes
    * `:w` - Save changes
    * `:wq` / `:x` - Save and close file
    * `ZZ` - Save and quit
    * `ZQ` - Quit without checking changes

    <br>


    ### ๐Ÿ’  Notes & Combos
    * All keys mentioned above can be combined with one another.
    * Example: `ct)` can delete everything until `)`. That means it can be used for clear function parameter or something like that. Here `c` means `cut` and `t)` means forward until char `)`.
    * `di{` - Delete everything inside `{}`
    * `d2i{` - Delete everything inside `{}` and its surround `{}`.
    * `ct}` - Delete everything until `}` and insert.
    * `v5$d` - Delete next 5 lines including current.
    * `cip` - Delete paragraph and insert
    * `di(` - Delete everything inside `()`
    * `yi(` - Copy everything inside `()`
    * `vi(` - Highlight everything inside `()`
    * `diw` - Delete current word

    &nbsp;
    ### ๐Ÿ’  Important VSCode Configurations for New Users

    &nbsp;

    **๐Ÿ”น Disable Vim `ctrl+c` `ctrl+v` `ctrl+x` commands**
    ```json
    "vim.useCtrlKeys": true,
    "vim.handleKeys": {
    "<C-c>": false,
    "<C-x>": false,
    "<C-v>": false
    }
    ```

    &nbsp;

    **๐Ÿ”น Disable Vim arrow controls**
    ```json
    "vim.handleKeys": {
    "<": false,
    ">": false
    }
    ```

    &nbsp;

    **๐Ÿ”น Enable `jj` to `Normal Mode`**
    ```json
    "vim.insertModeKeyBindingsNonRecursive": [
    {
    "before": ["j", "j"],
    "after": ["<esc>"]
    }
    ]
    ```
    &nbsp;

    **๐Ÿ”น Enable `X` to `Delete Current Word and Insert`**
    ```json
    "vim.normalModeKeyBindings": [
    {
    "before": ["X"],
    "after": ["b","d","w","i"]
    }
    ]
    ```
    &nbsp;

    **๐Ÿ”น Enable vim to use `System Clipboard`**
    ```json
    "vim.useSystemClipboard": true
    ```