Skip to content

Instantly share code, notes, and snippets.

@damienbutt
Forked from dmsul/vim_crash_course.md
Created June 5, 2024 15:32
Show Gist options
  • Save damienbutt/f9ec69641f202aad9c1510d3500d86dd to your computer and use it in GitHub Desktop.
Save damienbutt/f9ec69641f202aad9c1510d3500d86dd to your computer and use it in GitHub Desktop.

Revisions

  1. @dmsul dmsul revised this gist Dec 29, 2017. 1 changed file with 7 additions and 5 deletions.
    12 changes: 7 additions & 5 deletions vim_crash_course.md
    Original file line number Diff line number Diff line change
    @@ -42,11 +42,13 @@ These commands can be combined, e.g.
    `G` - go to end of file
    `[#]|` - go to column `[#]` on current line, e.g. `10|` goes to col 10.

    `f(F)<char>` - "find"/put cursor on next (previous) instance of `<char>` in line
    `t(T)` - "to"/ like f, but put cursor right before the character
    `f<char>` - "find"/put cursor on next instance of `<char>` in line
    `F<char>` - `f` but backwards search
    `t` - "to"/ like `f`, but put cursor right before the character
    `T` - `t` but backwards search
    `;(,)` - move to next (previous) instance of `<char>` from most recent `f` or `t`

    `/<RegEx><Enter>` - next (previous) instance of `<RegEx>` (uses full Regular Expression matching)
    `/<RegEx><Enter>` - next instance of `<RegEx>` (uses full Regular Expression matching)
    `?` - Same as `/` but reverse search
    `n(N)` - next (previous) instance of recent search
    `*` - Do `/`" search for word under cursor
    @@ -124,8 +126,8 @@ More generally, the composability of editing commands and motion is what makes V
    `y$` - yank from here to end of line
    *Note*: To make it consistent with `D`, it's common to add a mapping for `Y` in your vimrc, like so: `nnoremap Y y$`

    `p` - paste after cursor location (like "after" command, a)
    `P` - paste before cursor location (like i)
    `p` - paste after cursor location (like `a`)
    `P` - paste before cursor location (like `i`)

    ## Registers (for yank and paste).
    `"\<char>y` - yank to register `<char>`.
  2. @dmsul dmsul revised this gist Dec 29, 2017. 1 changed file with 2 additions and 0 deletions.
    2 changes: 2 additions & 0 deletions vim_crash_course.md
    Original file line number Diff line number Diff line change
    @@ -1,3 +1,5 @@
    **NOTE**: Specific examples given for options, flags, commands variations, etc., are not comprehensive.

    # NORMAL MODE
    Vim has 2 main "modes", that chance the behavior of all your keys. The default mode of Vim is Normal Mode and is mostly used for moving the cursor and navigating the current file.

  3. @dmsul dmsul revised this gist Dec 29, 2017. 1 changed file with 1 addition and 1 deletion.
    2 changes: 1 addition & 1 deletion vim_crash_course.md
    Original file line number Diff line number Diff line change
    @@ -163,7 +163,7 @@ NOTE: deleting text puts that text into the default register, so if you `yy`, mo
    `u` - undo
    `c-r` - redo

    `.` - repeat last edit (including insert, replace, indent, etc.) **Note: EXTREMELY useful.**
    `.` - repeat last edit (including insert, replace, indent, etc.) **Note: EXTREMELY useful.**
    `A;;<Esc>j.` - Enter insert mode at end of line (`A`), type two semi-colons (`;;`), exit Insert Mode (`<Esc>`), move down one line (`j`), and add two semi-colons to the end of this new line (`.`)
    `>>...` - Indent this line `>>`, then indent it another three times (`...`)

  4. @dmsul dmsul revised this gist Dec 29, 2017. 1 changed file with 13 additions and 16 deletions.
    29 changes: 13 additions & 16 deletions vim_crash_course.md
    Original file line number Diff line number Diff line change
    @@ -171,18 +171,18 @@ NOTE: deleting text puts that text into the default register, so if you `yy`, mo
    # Substitution
    `:<range>s/<re>/<str>/<flags>` - substitute first instance of `<re>` in each line in `<range>` with `<str>`. `<flags>` change default behavior.

    `<range>`:
    default range is this line only
    `%` - global (whole file)
    `<a>,<b>` - between lines/markers/etc
    `.` - current line
    `$` - last line in file (so `:.,$s` is "from here to end of file")
    *Note*: There are other `<range>` things, most common is just `%`.

    `<flags>`:
    `g` - global/all instances of `<re>` on line (not just first instance on line)
    `c` - confirm (will highlight next instance of `<re>` and ask you to press "y" to execute change
    `i` - case insensitive
    - `<range>`:
    - default range is this line only
    - `%` - global (whole file)
    - `<a>,<b>` - between lines/markers/etc
    - `.` - current line
    - `$` - last line in file (so `:.,$s` is "from here to end of file")
    - *Note*: There are other `<range>` things, most common is just `%`.

    - `<flags>`:
    - `g` - global/all instances of `<re>` on line (not just first instance on line)
    - `c` - confirm (will highlight next instance of `<re>` and ask you to press "y" to execute change
    - `i` - case insensitive

    Specific sub: Use `\zs` and `\ze` to demark a sub-RegEx within the matched RegEx that should be substituted. Example:

    @@ -262,10 +262,7 @@ Lower case are local, upper case are global (across files). Jumping to a mark is
    `'a` - jump to line of "a" (first non-blank character of line)
    `` `a `` - jump to position of "a" (line and col)
    `:marks` - lists all current marks
    `:delmarks <args>`
    - `a` - delete a
    - `a-d` - delete a through d
    - `abxy` - delete this list
    `:delmarks <args>` - delete specific marks
    `:delmarks!` - delete all lowercase in buffer
    `]'`, `['` - jump to next (previous) line with a lowercase mark
    `` ]` ``, `` [` `` - jump to next (previous) lowercase mark
  5. @dmsul dmsul revised this gist Dec 29, 2017. 1 changed file with 3 additions and 3 deletions.
    6 changes: 3 additions & 3 deletions vim_crash_course.md
    Original file line number Diff line number Diff line change
    @@ -263,9 +263,9 @@ Lower case are local, upper case are global (across files). Jumping to a mark is
    `` `a `` - jump to position of "a" (line and col)
    `:marks` - lists all current marks
    `:delmarks <args>`
    `a` - delete a
    `a-d` - delete a through d
    `abxy` - delete this list
    - `a` - delete a
    - `a-d` - delete a through d
    - `abxy` - delete this list
    `:delmarks!` - delete all lowercase in buffer
    `]'`, `['` - jump to next (previous) line with a lowercase mark
    `` ]` ``, `` [` `` - jump to next (previous) lowercase mark
  6. @dmsul dmsul revised this gist Dec 29, 2017. 1 changed file with 1 addition and 1 deletion.
    2 changes: 1 addition & 1 deletion vim_crash_course.md
    Original file line number Diff line number Diff line change
    @@ -275,7 +275,7 @@ Lower case are local, upper case are global (across files). Jumping to a mark is
    jump to beginning of file using `gg`, hitting `''` will take you right back to
    line 57.
    `.` - last edit in current buffer
    `` `` `` - jump back to position (line and col) where just jumped from
    ``` `` ``` - jump back to position (line and col) where just jumped from
    `` `[ ``, `` `] `` - jump to beg/end of last changed or yanked text

    ## Spellcheck
  7. @dmsul dmsul revised this gist Dec 29, 2017. 1 changed file with 2 additions and 2 deletions.
    4 changes: 2 additions & 2 deletions vim_crash_course.md
    Original file line number Diff line number Diff line change
    @@ -268,15 +268,15 @@ Lower case are local, upper case are global (across files). Jumping to a mark is
    `abxy` - delete this list
    `:delmarks!` - delete all lowercase in buffer
    `]'`, `['` - jump to next (previous) line with a lowercase mark
    ``]```, ``[``` - jump to next (previous) lowercase mark
    `` ]` ``, `` [` `` - jump to next (previous) lowercase mark

    ### Special Marks (Most useful when beginning)
    `'` - The line you were on before making a "jump". So if you're on line 57 and
    jump to beginning of file using `gg`, hitting `''` will take you right back to
    line 57.
    `.` - last edit in current buffer
    `` `` `` - jump back to position (line and col) where just jumped from
    ```[``, ```]`` - jump to beg/end of last changed or yanked text
    `` `[ ``, `` `] `` - jump to beg/end of last changed or yanked text

    ## Spellcheck

  8. @dmsul dmsul revised this gist Dec 29, 2017. 1 changed file with 1 addition and 1 deletion.
    2 changes: 1 addition & 1 deletion vim_crash_course.md
    Original file line number Diff line number Diff line change
    @@ -260,7 +260,7 @@ Lower case are local, upper case are global (across files). Jumping to a mark is

    `ma` - sets mark on current cursor location (line and column), WLOG, called "a"
    `'a` - jump to line of "a" (first non-blank character of line)
    ```a`` - jump to position of "a" (line and col)
    `` `a `` - jump to position of "a" (line and col)
    `:marks` - lists all current marks
    `:delmarks <args>`
    `a` - delete a
  9. @dmsul dmsul revised this gist Dec 29, 2017. 1 changed file with 5 additions and 5 deletions.
    10 changes: 5 additions & 5 deletions vim_crash_course.md
    Original file line number Diff line number Diff line change
    @@ -260,27 +260,27 @@ Lower case are local, upper case are global (across files). Jumping to a mark is

    `ma` - sets mark on current cursor location (line and column), WLOG, called "a"
    `'a` - jump to line of "a" (first non-blank character of line)
    `\`a` - jump to position of "a" (line and col)
    ```a`` - jump to position of "a" (line and col)
    `:marks` - lists all current marks
    `:delmarks <args>`
    `a` - delete a
    `a-d` - delete a through d
    `abxy` - delete this list
    `:delmarks!` - delete all lowercase in buffer
    `]'`, `['` - jump to next (previous) line with a lowercase mark
    `]\``, `[\`` - jump to next (previous) lowercase mark
    ``]```, ``[``` - jump to next (previous) lowercase mark

    ### Special Marks (Most useful when beginning)
    `'` - The line you were on before making a "jump". So if you're on line 57 and
    jump to beginning of file using `gg`, hitting `''` will take you right back to
    line 57.
    `.` - last edit in current buffer
    `\`\`` - jump back to position (line and col) where just jumped from
    `\`[`, `\`]` - jump to beg/end of last changed or yanked text
    `` `` `` - jump back to position (line and col) where just jumped from
    ```[``, ```]`` - jump to beg/end of last changed or yanked text

    ## Spellcheck

    Turn on with ":set spell", turn off with ":set nospell".
    Turn on with `:set spell`, turn off with `:set nospell`.

    `z=` - Suggest correctly spelled words
    `]s`, `[s` - Move to next/previous mispelled word (use `S` for "bad words only")
  10. @dmsul dmsul revised this gist Dec 29, 2017. 1 changed file with 1 addition and 1 deletion.
    2 changes: 1 addition & 1 deletion vim_crash_course.md
    Original file line number Diff line number Diff line change
    @@ -262,7 +262,7 @@ Lower case are local, upper case are global (across files). Jumping to a mark is
    `'a` - jump to line of "a" (first non-blank character of line)
    `\`a` - jump to position of "a" (line and col)
    `:marks` - lists all current marks
    `:delmarks <args>`
    `:delmarks <args>`
    `a` - delete a
    `a-d` - delete a through d
    `abxy` - delete this list
  11. @dmsul dmsul revised this gist Dec 29, 2017. 1 changed file with 24 additions and 22 deletions.
    46 changes: 24 additions & 22 deletions vim_crash_course.md
    Original file line number Diff line number Diff line change
    @@ -3,11 +3,11 @@ Vim has 2 main "modes", that chance the behavior of all your keys. The default m

    Some important (or longer) commands begin with ":" and you will see the text you enter next at the bottom left of the screen.

    `:q\[uit]` - quit (the current window of) Vim. ("Window" here is internal to Vim, not if you have multiple OS-level windows of Vim open at once.)
    `:q[uit]` - quit (the current window of) Vim. ("Window" here is internal to Vim, not if you have multiple OS-level windows of Vim open at once.)
    `:q!` - force quit (if the current buffer has been changed since the last save)
    `:e\[dit] {filename}` - read file {filename} into a new buffer.
    `:e[dit] {filename}` - read file {filename} into a new buffer.
    Vim doesn't "open" files like MS Word does. Instead, it reads the contents of a file into RAM and then you edit the "buffer" in RAM. Other programs may access and change the underlying file you originally opened (Vim will notice this and issue a warning).
    `:w\[rite] {filename}` - write the current buffer to {filename}. If no filename passed (i.e., `:w`) and the buffer already has an associated filename (the one used with `:e {filename}`, that associated filename will be used.
    `:w[rite] {filename}` - write the current buffer to {filename}. If no filename passed (i.e., `:w`) and the buffer already has an associated filename (the one used with `:e {filename}`, that associated filename will be used.
    A simple `:w` is like MS Word "save" and `:w {new_filename}` is "save a copy as `{new_filename}` but keep the current buffer.
    `:save {filename}` - Save as (and change current buffer to {filename})
    `:w!` - force write (e.g., even if the underlying file has been been changed by another program and this write will overwrite those changes)
    @@ -27,7 +27,7 @@ These commands can be combined, e.g.
    `$` - Move to end of line
    *Note*: `^` and `$` are Regular Expression shortcuts for beginning and end of a string, respectively

    `%` - If cursor inside parens (or similar), move to opening paren. If cursor on paren, move to partner paren. If not between parens, do nothing. \[Can do weird stuff with unmatched parens.]
    `%` - If cursor inside parens (or similar), move to opening paren. If cursor on paren, move to partner paren. If not between parens, do nothing. (Can do weird stuff with unmatched parens.)

    `w` - forward one word (alphanumeric or \_; or consective chars that are not those)
    `e` - end of current word (or next word if currently at end of word)
    @@ -141,42 +141,44 @@ NOTE: deleting text puts that text into the default register, so if you `yy`, mo

    ## Change case
    `~` - toggle the case of this character
    `\[#]~` - toggle case of `[#]` next character(s)
    `g~\[m]` - toggle case with motion [m]
    `gU\[m]` - uppercase
    `gu\[m]` - lowercase
    `[#]~` - toggle case of `[#]` next character(s)
    `g~[m]` - toggle case with motion [m]
    `gU[m]` - uppercase
    `gu[m]` - lowercase

    ## Indentation
    `\>\[m]` - indent current line through motion \[m]
    `\>5j` - indent this and next 5 lines
    `\>G` - indent to end of file
    `\>\>` - indent this line (like dd, yy, etc.)
    `\<\[m]` - un-indent (same as indent, but in reverse)
    `>[m]` - indent current line through motion `[m]`
    `>5j` - indent this and next 5 lines
    `>G` - indent to end of file
    `>>` - indent this line (like `dd`, `yy`, etc.)
    `<[m]` - un-indent (same as indent, but in reverse)


    ## Misc useful commands
    `J` - Take the next line and move it to the end of this line.

    `gq\[m]` - Format the text between here and `[m]` (usually just breaks overly long lines to smaller lines, by default 80 characters).
    `gq[m]` - Format the text between here and `[m]` (usually just breaks overly long lines to smaller lines, by default 80 characters).
    `gqq` - Format the current line

    `u` - undo
    `c-r` - redo

    `.` - repeat last edit (including insert, replace, indent, etc.) \[EXTREMELY useful]
    `A;;\<Esc>j.` - Enter insert mode at end of line (`A`), type two semi-colons (`;;`), exit Insert Mode (`<Esc>`), move down one line (`j`), and add two semi-colons to the end of this new line (`.`)
    `\>\>...` - Indent this line `>>`, then indent it another three times (`...`)
    `.` - repeat last edit (including insert, replace, indent, etc.) **Note: EXTREMELY useful.**
    `A;;<Esc>j.` - Enter insert mode at end of line (`A`), type two semi-colons (`;;`), exit Insert Mode (`<Esc>`), move down one line (`j`), and add two semi-colons to the end of this new line (`.`)
    `>>...` - Indent this line `>>`, then indent it another three times (`...`)


    # Substitution
    `:\<range>s/\<re>/\<str>/\<flags>` - substitute first instance of \<re> in each line in \<range> with \<str>. \<flags> change default behavior.
    `:<range>s/<re>/<str>/<flags>` - substitute first instance of `<re>` in each line in `<range>` with `<str>`. `<flags>` change default behavior.

    `<range>`:
    default range is this line only
    `%` - global (whole file)
    `<a>,<b>` - between lines/markers/etc
    `.` - current line
    `$` - last line in file (so `:.,$s` is "from here to end of file")
    *Note*: There are other `<range>` things, most common is just `%`.

    `<flags>`:
    `g` - global/all instances of `<re>` on line (not just first instance on line)
    `c` - confirm (will highlight next instance of `<re>` and ask you to press "y" to execute change
    @@ -207,7 +209,7 @@ A shortcut around this is these motion-like object commands.
    `ya(` - Yank a parenthetical. If cursor between (), yank everything between those parens and the parens themselves. Else do Nothing.
    `yi(` - Yank inner parenthetical. Like `ya(`, but excluding the parens.
    `ya)` - `ya(`
    `ya\[` - Same as `ya(` but for brackets `[]`.
    `ya[` - Same as `ya(` but for brackets `[]`.
    `ya"` - Same

    `da(` - Deletes a parenthetical.
    @@ -268,7 +270,7 @@ Lower case are local, upper case are global (across files). Jumping to a mark is
    `]'`, `['` - jump to next (previous) line with a lowercase mark
    `]\``, `[\`` - jump to next (previous) lowercase mark

    ### Special Marks \[Most useful when beginning]
    ### Special Marks (Most useful when beginning)
    `'` - The line you were on before making a "jump". So if you're on line 57 and
    jump to beginning of file using `gg`, hitting `''` will take you right back to
    line 57.
    @@ -281,7 +283,7 @@ line 57.
    Turn on with ":set spell", turn off with ":set nospell".

    `z=` - Suggest correctly spelled words
    `]s`, `\[s` - Move to next/previous mispelled word (use `S` for "bad words only")
    `]s`, `[s` - Move to next/previous mispelled word (use `S` for "bad words only")
    `zq` - Add word under cursor as good word to first name in 'spellfile'
    `zw` - Mark as bad word
    `zu[q,w]` - Undo marking
    `zu[q,w]` - Undo marking
  12. @dmsul dmsul revised this gist Dec 29, 2017. 1 changed file with 152 additions and 140 deletions.
    292 changes: 152 additions & 140 deletions vim_crash_course.md
    Original file line number Diff line number Diff line change
    @@ -25,7 +25,7 @@ These commands can be combined, e.g.
    `0` - Move to beginning of line
    `^` - Move to first character (non-space or tab) in line (same as "0" if the line starts with a non-space character)
    `$` - Move to end of line
    *Note*: `^` and `$` are Regular Expression shortcuts for beginning and end of a string, respectively]
    *Note*: `^` and `$` are Regular Expression shortcuts for beginning and end of a string, respectively

    `%` - If cursor inside parens (or similar), move to opening paren. If cursor on paren, move to partner paren. If not between parens, do nothing. \[Can do weird stuff with unmatched parens.]

    @@ -36,68 +36,69 @@ These commands can be combined, e.g.
    `{` - Move back a paragraph.

    `gg` - go to beginning of file
    `[#]gg` - go to line [#] (Example 20gg goes to line 20)
    `[#]gg` - go to line `[#]` (Example `20gg` goes to line 20)
    `G` - go to end of file
    `[#]|` - go to column [#] on current line, e.g. 10| goes to col 10.
    `[#]|` - go to column `[#]` on current line, e.g. `10|` goes to col 10.

    `f(F)<char>` - "find"/put cursor on next (previous) instance of \<char> in line
    `f(F)<char>` - "find"/put cursor on next (previous) instance of `<char>` in line
    `t(T)` - "to"/ like f, but put cursor right before the character
    ;(,) - move to next(previous) instance of \<char> from most recent f,F,t, or T
    `;(,)` - move to next (previous) instance of `<char>` from most recent `f` or `t`

    /(?)\<RegEx>\<Enter> - next (previous) instance of \<RegEx> (uses full Regular Expression matching)
    n(N) - next instance of recent search
    \* - Do "/" search for word under cursor
    \[This is basic search functionality. "/gen\<Enter>" will go to the next instance of the string "gen", and then hitting "n" will move to the next instance, etc. When you get to the end of the file, it will cycle back to the beginning. Using "?" instead of "/" is just a backwards search.\]
    `/<RegEx><Enter>` - next (previous) instance of `<RegEx>` (uses full Regular Expression matching)
    `?` - Same as `/` but reverse search
    `n(N)` - next (previous) instance of recent search
    `*` - Do `/`" search for word under cursor
    *Note*: This is basic search functionality. `/gen<Enter>` will go to the next instance of the string "gen", and then `n` will move to the next instance, etc. When you get to the end of the file, it will cycle back to the beginning. Using `?` instead of `/` is just a backwards search.

    c-u - move cursor Up full page
    c-d - move cursor Down full page
    _Note: "c-u" in Vim mappings means "Ctrl-u"_
    `c-u` - move cursor Up full page
    `c-d` - move cursor Down full page
    *Note*: `c-u` in Vim mappings means `Ctrl+u`

    c-e - scroll forward, keeping cursor in place
    e-y - scroll backward, keeping cursor in place
    `c-e` - scroll forward, keeping cursor in place
    `e-y` - scroll backward, keeping cursor in place

    c-f - Forward half-page
    c-b - Back half-page
    `c-f` - Forward half-page
    `c-b` - Back half-page

    H - highest line on screen (home)
    M - middle line on screen
    L - lowest line on screen
    `H` - highest line on screen (home)
    `M` - middle line on screen
    `L` - lowest line on screen


    **Note:** Most motion commands can take a number before them to execute that number of times.
    4j - move cursor down 4 times
    10w - move forward 10 "words"
    `4j` - move cursor down 4 times
    `10w` - move forward 10 "words"

    # VISUAL "MODE"
    v[m] - Go into visual (highlight) mode to select characters. Use usual motion commands to add to selection as cursor moves.
    V[m] - Visual mode, but grab whole lines at a time, not characters.
    c-v[m] - Visual mode, but select vertically (by columns) instead of horizontally
    `v[m]` - Go into visual (highlight) mode to select characters. Use usual motion commands to add to selection as cursor moves.
    `V[m]` - Visual mode, but grab whole lines at a time, not characters.
    `c-v[m]` - Visual mode, but select vertically (by columns) instead of horizontally

    ggvG - Highlight whole file, i.e., go to beginning of file (gg), enter visual mode (v), go to end of file (G).
    `ggvG` - Highlight whole file, i.e., go to beginning of file (`gg`), enter visual mode (`v`), go to end of file (`G`).

    Once a selection has been made, you can use an edit command (see below) on that selection and it will (usually) behave as you'd expect.


    # INSERT MODE
    Most commands are executed in Normal Mode. If you actually want to add to the text (type a "j" instead of moving down one line) you need to enter Insert Mode. There are several ways to do this.

    i - Enter insert mode before the current character
    a - Enter insert mode After the current character
    \<Esc\> - Exit Insert Mode (go back to Normal Mode).
    [Note: Because \<Esc> is a little out of the way, it's common to remap a more convenient keybinding to also exit Insert Mode. For example, "inoremap
    jk \<Esc>" in vimrc will allow you to use a quick jk instead of \<Esc>]
    `i` - Enter insert mode before the current character
    `a` - Enter insert mode After the current character
    `<Esc>` - Exit Insert Mode (go back to Normal Mode).
    *Note*: Because `<Esc>` is a little out of the way, it's common to remap a more convenient keybinding to also exit Insert Mode. For example, `inoremap
    jk <Esc>` in your vimrc will allow you to use a quick `jk` instead of `<Esc>`.

    I - Enter insert mode at the beginning of the current line's text (same as doing ^ then i)
    A - Enter insert mode After the end of th current line (like $ then a)
    o - Add a new line after the current line and enter insert mode (like doing A\<Enter>)
    O - Add a new line before the current line and enter insert mode
    `I` - Enter insert mode at the beginning of the current line's text (same as doing `^` then `i`)
    `A` - Enter insert mode After the end of th current line (like `$` then `a`)
    `o` - Add a new line after the current line and enter insert mode (like doing `A<Enter>`)
    `O` - Add a new line before the current line and enter insert mode

    c[m] - Change text from here to [m]. "Change" deletes the text and immediately enters insert mode.
    cc - Change this whole line.
    C - Changes from here to end of line.
    `c[m]` - Change text from here to [m]. "Change" deletes the text and immediately enters insert mode.
    `cc` - Change this whole line.
    `C` - Changes from here to end of line.

    r - replace the current character with the next character typed (only one character allowed)
    R - Replace characters until \<Esc> (like replace/overwrite mode in Word)
    `r` - replace the current character with the next character typed (only one character allowed)
    `R` - Replace characters until \<Esc> (like replace/overwrite mode in Word)


    # Edit commands for Normal Mode
    @@ -107,136 +108,146 @@ shift + command: execute command from cursor to end of current line

    More generally, the composability of editing commands and motion is what makes Vim particularly powerful. If you know 5 editing commands and 5 motion commands, you actually know 25 specific and easy to remember commands.

    [#]d[m] - delete over [m] (do this [#] times)
    dw - delete from here (location of cursor) to beginning of next word (includes character under the cursor)
    d4w - delete from here to beginning of 4th word forward
    dtT - deletes "to" (up to but not including) the next instance of "T" on this line
    df) - deletes to ("finds") the next instance of ")" on this line
    `[#]d[m]` - delete over [m] (do this [#] times)
    `dw` - delete from here (location of cursor) to beginning of next word (includes character under the cursor)
    `d4w` - delete from here to beginning of 4th word forward
    `dtT` - deletes "to" (up to but not including) the next instance of "T" on this line
    `df)` - deletes to ("finds") the next instance of ")" on this line

    dd - delete this entire line 4dd - delete this line and next 3 (4 total)
    D - delete from here to end of line
    `dd` - delete this entire line 4dd - delete this line and next 3 (4 total)
    `D` - delete from here to end of line

    y[m] - yank (copy). Same behavior as d (delete).
    yw - yank from here to beginning of next word
    y$ - yank from here to end of line
    [Note: To make consistent with D, it's common to add a mapping for Y in your vimrc, like so:
    nnoremap Y y$
    ]
    `y[m]` - yank (copy). Same behavior as d (delete).
    `yw` - yank from here to beginning of next word
    `y$` - yank from here to end of line
    *Note*: To make it consistent with `D`, it's common to add a mapping for `Y` in your vimrc, like so: `nnoremap Y y$`

    p - paste after cursor location (like "after" command, a)
    P - paste before cursor location (like i)
    `p` - paste after cursor location (like "after" command, a)
    `P` - paste before cursor location (like i)

    ## Registers (for yank and paste).
    "\<char>y - yank to register \<char>.
    `"\<char>y` - yank to register `<char>`.
    This allows you to have multiple things in your clipboard. Note the Vim clipboard is separate from the OS clipboard. To move between the two (copy/paste between Vim and another program) use the * register, so:

    y$ - yanks to end of line, puts in default register
    "a$ - yank to register "a"
    "*yG - yanks to end of file, puts in OS register
    p - pastes what's in the default register (after the cursor, like "a")
    P - paste before cursor (like command "i")
    "*p - pastes what's in the OS register (i.e., if you already yanked to * or you did a Ctrl+C copy in another program)
    `y$` - yanks to end of line, puts in default register
    `"a$` - yank to register "a"
    `"*yG` - yanks to end of file, puts in OS register
    `p` - pastes what's in the default register (after the cursor, like `a`)
    `P` - paste before cursor (like command `i`)
    `"*p` - pastes what's in the OS register (i.e., if you already yanked to * or you did a Ctrl+C copy in another program)

    NOTE: deleting text puts that text into the default register, so if you "yy", move to another line, then "dd", you'll lose whatever whatever you yanked with "yy". There is a plugin to override this behavior (I think by Tim Pope).
    NOTE: deleting text puts that text into the default register, so if you `yy`, move to another line, then `dd`, you'll lose whatever whatever you yanked with `yy`. There is a plugin to override this behavior (I think by Tim Pope).


    ## Change case
    \[#]~ - toggle case of \[#] character(s)
    g~\[m] - toggle case with motion [m]
    gU\[m] - uppercase
    gu\[m] - lowercase
    `~` - toggle the case of this character
    `\[#]~` - toggle case of `[#]` next character(s)
    `g~\[m]` - toggle case with motion [m]
    `gU\[m]` - uppercase
    `gu\[m]` - lowercase

    ## Indentation
    \>\[m] - indent current line through motion \[m]
    \>5j - indent this and next 5 lines
    \>G - indent to end of file
    \>\> - indent this line (like dd, yy, etc.)
    \<\[m] - un-indent (same as indent, but in reverse)
    `\>\[m]` - indent current line through motion \[m]
    `\>5j` - indent this and next 5 lines
    `\>G` - indent to end of file
    `\>\>` - indent this line (like dd, yy, etc.)
    `\<\[m]` - un-indent (same as indent, but in reverse)


    ## Misc useful commands
    J - Take the next line and move it to the end of this line.
    `J` - Take the next line and move it to the end of this line.

    gq\[m] - Format the text between here and [m] (usually just breaks overly long lines to smaller lines, by default 80 characters).
    gqq - Format the current line
    `gq\[m]` - Format the text between here and `[m]` (usually just breaks overly long lines to smaller lines, by default 80 characters).
    `gqq` - Format the current line

    u - undo
    c-r - redo
    `u` - undo
    `c-r` - redo

    . - repeat last edit (including insert, replace, indent, etc.) \[EXTREMELY useful]
    A;;\<Esc>j. - Enter insert mode at end of line (A), type two semi-colons [;;], exit Insert Mode \[\<Esc>], move down one line \[j], and add two semi-colons to the end of this new line \[.]
    \>\>... - Indent this line \[\>\>], then three more times [...]
    `.` - repeat last edit (including insert, replace, indent, etc.) \[EXTREMELY useful]
    `A;;\<Esc>j.` - Enter insert mode at end of line (`A`), type two semi-colons (`;;`), exit Insert Mode (`<Esc>`), move down one line (`j`), and add two semi-colons to the end of this new line (`.`)
    `\>\>...` - Indent this line `>>`, then indent it another three times (`...`)


    # Substitution
    :\<range>s/\<re>/\<str>/\<flags> - substitute first instance of \<re> in each line in \<range> with \<str>. \<flags> change default behavior.
    \<range>
    `:\<range>s/\<re>/\<str>/\<flags>` - substitute first instance of \<re> in each line in \<range> with \<str>. \<flags> change default behavior.
    `<range>`:
    default range is this line only
    % - global (whole file)
    \<a\>,\<b\> - between lines/markers/etc
    . - current line
    $ - last line in file (so :.,$s is "from here to end of file")
    \[There are other \<range> things, most common is just %.]
    \<flags>
    g - global/all instance of \<re> on line (not just first instance on line)
    c - confirm (will highlight next instance of \<re> and ask you to press "y" to execute change
    i - case insensitive
    `%` - global (whole file)
    `<a>,<b>` - between lines/markers/etc
    `.` - current line
    `$` - last line in file (so `:.,$s` is "from here to end of file")
    *Note*: There are other `<range>` things, most common is just `%`.
    `<flags>`:
    `g` - global/all instances of `<re>` on line (not just first instance on line)
    `c` - confirm (will highlight next instance of `<re>` and ask you to press "y" to execute change
    `i` - case insensitive

    Specific sub: Use "\zs" and "\ze" to demark a sub-RegEx within the matched RegEx that should be substituted. Example:
    Specific sub: Use `\zs` and `\ze` to demark a sub-RegEx within the matched RegEx that should be substituted. Example:

    :%s/Year \zs2007\ze is over/2008/g
    `:%s/Year \zs2007\ze is over/2008/g`

    This changes all instances of "Year 2007 is over" to "Year 2008 is over", but not all "2007" to "2008".


    # Advanced motion(ish) commands
    There are "motion" commands that can be used with delete, yank, etc., that can be used to target specific text objects. "dw" will delete from cursor to beginning of next word, so will not delete the entire current word under the cursor unless the cursor happens to be at the beginning of the wordSo "bdw" will delete the whole word and the space(s) after it (unless the cursor is already at the beginning of the word).
    There are "motion" commands that can be used with delete, yank, etc., that can
    be used to target specific text objects. `dw` will delete from cursor to
    beginning of next word, so will not delete the entire current word under the
    cursor unless the cursor happens to be at the beginning of the word. So `bdw`
    will delete the whole word and the space(s) after it (unless the cursor is
    already at the beginning of the word).

    A shortcut around this is these motion-like object commands.

    daw - Delete "a" "word". Deletes the current word and space(s) after it.
    diw - Delete "inner" "word". Deletes current word but not trailing space(s).
    dap - Delete a paragraph. A "paragraph" to Vim is a group of consecutive lines of text between an empty line(s).
    yaw - Yanks a word.
    yiw - Yanks inner word.
    ya( - Yank a parenthetical. If cursor between (), yank everything between those parens and the parens themselves. Else do Nothing.
    yi( - Yank inner parenthetical. Like ya(, but excluding the parens.
    ya) - ya(
    ya\[ - Same as ya( but for brackets \[].
    ya" - Same
    `daw` - Delete "a" "word". Deletes the current word and space(s) after it.
    `diw` - Delete "inner" "word". Deletes current word but not trailing space(s).
    `dap` - Delete a paragraph. A "paragraph" to Vim is a group of consecutive lines of text between an empty line(s).
    `yaw` - Yanks a word.
    `yiw` - Yanks inner word.
    `ya(` - Yank a parenthetical. If cursor between (), yank everything between those parens and the parens themselves. Else do Nothing.
    `yi(` - Yank inner parenthetical. Like `ya(`, but excluding the parens.
    `ya)` - `ya(`
    `ya\[` - Same as `ya(` but for brackets `[]`.
    `ya"` - Same

    da( - Deletes a parenthetical.
    di( - Deletes within parenthetical.
    `da(` - Deletes a parenthetical.
    `di(` - Deletes within parenthetical.

    g~i( - Toggles the case of the inner parenthetical.
    `g~i(` - Toggles the case of the inner parenthetical.

    ciw - Change inner word
    ci[ - Change inner (within) brackets (delete text within brackets and enter Insert Mode).
    `ciw` - Change inner word
    `ci[` - Change inner (within) brackets (delete text within brackets and enter Insert Mode).


    # Other very useful stuff

    ## Predictive completion (while in Insert Mode)
    c-p - predictive completion (word)
    c-x c-l predictive completion (line)
    `c-p` - predictive completion (word)
    `c-x c-l` - predictive completion (line)

    This takes what you've already typed (either word or line) and uses the text in the rest of any open buffers to predict what will come next. If there's only one possibility, it will be filled in. If there are several possibilities, it will give you the choices.
    This takes what you've already typed (either word or line) and uses the text in
    the rest of any open buffers to predict what will come next. If there's only
    one possibility, it will be filled in. If there are several possibilities, it
    will give you the choices.

    Vim autocomplete is pretty nice, but there are better, automated predictive text solutions (specifcally, the package YouCompleteMe). However, I've found they're a bit too demanding for most laptops and only useful on desktop computers.
    Vim autocomplete is pretty nice, but there are better, automated predictive
    text solutions (specifcally, the package YouCompleteMe). However, I've found
    they're a bit too demanding for most laptops and only useful on desktop
    computers.

    ## Global command by line
    :g/\<RegEx>/\<edit command> - perform the edit command on every line that matches RegEx
    :g!/... or :v/... -- the same but for lines that don't match
    `:g/<RegEx>/<edit command>` - perform the edit command on every line that matches RegEx
    `:g!/...` or `:v/...` - the same but for lines that don't match
    Examples:
    :g/DEL THIS/d deletes every line that contains "DEL THIS"
    :g/ $/d deletes every line that ends with a space.
    `:g/DEL THIS/d` deletes every line that contains "DEL THIS"
    `:g/ $/d` deletes every line that ends with a space.

    ## Macros

    Hit 'q' then a letter 'a' to begin recording macro 'a'.
    Hit `q` then some letter, WLOG `a` to begin recording macro "a".
    Do your thing.
    Hit 'q' to stop recording.
    @a to repeat the new macro. [#]@a repeats a # times.
    Hit `q` to stop recording.
    `@a` to repeat the new macro. `[#]@a` repeats a `[#]` times.


    # Other moderately useful stuff
    @@ -245,31 +256,32 @@ Hit 'q' to stop recording.

    Lower case are local, upper case are global (across files). Jumping to a mark is a standard motion command for deleting, yanking, etc.

    ma - sets mark on current cursor location (line and column), WLOG, called "a"
    'a - jump to line of "a" (first non-blank character of line)
    \`a - jump to position of "a" (line and col)
    :marks - lists all current marks
    :delmarks \<args>
    a - delete a
    a-d - delete a through d
    abxy - delete this list
    :delmarks! - delete all lowercase in buffer
    ]', [' - jump to next (previous) line with a lowercase mark
    ]\`, [\` - jump to next (previous) lowercase mark
    `ma` - sets mark on current cursor location (line and column), WLOG, called "a"
    `'a` - jump to line of "a" (first non-blank character of line)
    `\`a` - jump to position of "a" (line and col)
    `:marks` - lists all current marks
    `:delmarks <args>`
    `a` - delete a
    `a-d` - delete a through d
    `abxy` - delete this list
    `:delmarks!` - delete all lowercase in buffer
    `]'`, `['` - jump to next (previous) line with a lowercase mark
    `]\``, `[\`` - jump to next (previous) lowercase mark

    ### Special Marks \[Most useful when beginning]
    ' - The line you were on before making a "jump". So if you're on line 57 and jump to beginning of file using "gg", hitting '' will take you right back to line 57.
    . - last edit in current buffer
    \`\` - jump back to position (line and col) where just jumped from
    \`\[, \`] - jump to beg/end of last changed or yanked text
    \`<, \`> - jump to beg/end of last visual selection
    `'` - The line you were on before making a "jump". So if you're on line 57 and
    jump to beginning of file using `gg`, hitting `''` will take you right back to
    line 57.
    `.` - last edit in current buffer
    `\`\`` - jump back to position (line and col) where just jumped from
    `\`[`, `\`]` - jump to beg/end of last changed or yanked text

    ## Spellcheck

    Turn on with ":set spell", turn off with ":set nospell".

    z= Suggest correctly spelled words
    ]s/\[s Move to next/previous mispelled word (use S for "bad words only")
    zq Add word under cursor as good word to first name in 'spellfile'
    zw Mark as bad word
    zu(q,w) Undo marking
    `z=` - Suggest correctly spelled words
    `]s`, `\[s` - Move to next/previous mispelled word (use `S` for "bad words only")
    `zq` - Add word under cursor as good word to first name in 'spellfile'
    `zw` - Mark as bad word
    `zu[q,w]` - Undo marking
  13. @dmsul dmsul revised this gist Dec 29, 2017. 1 changed file with 40 additions and 40 deletions.
    80 changes: 40 additions & 40 deletions vim_crash_course.md
    Original file line number Diff line number Diff line change
    @@ -1,49 +1,47 @@
    # NORMAL MODE
    Vim has 2 main "modes" that are used to change the behavior of all the keys on your keyboard. The default mode of Vim is Normal Mode and is mostly used for moving the cursor and navigating the current file.
    Vim has 2 main "modes", that chance the behavior of all your keys. The default mode of Vim is Normal Mode and is mostly used for moving the cursor and navigating the current file.

    Some important (or longer) commands begin with ":" and you will see the text you enter next at the bottom left of the screen.

    `:q\[uit]` - quit (the current window of) Vim. ("Window" here is internal to Vim, not if you have multiple OS-level windows of Vim open at once.)
    :q! - force quit (if the current buffer has been changed since the last save)
    :e\[dit] {filename} - read file {filename} into a new buffer.

    *Note*: Vim doesn't "open" files like MS Word does. Instead, it reads the contents of a file into RAM and then you edit the "buffer" in RAM. Other programs may access and change the underlying file you originally opened (Vim will notice this and issue a warning).

    :w\[rite] {filename} - write the current buffer to {filename}. If no filename passed (i.e., ":w") and the buffer already has an associated filename (the one used with ":e {filename}", that associated filename will be used.
    A simple ":w" is like MS Word "save" and ":w {new_filename}" is "save a copy as {new_filename} but keep the current buffer".

    :save {filename} - Save as (and change current buffer to {filename})
    :w! - force write (e.g., even if the underlying file has been been changed by another program and this write will overwrite those changes)
    `:q!` - force quit (if the current buffer has been changed since the last save)
    `:e\[dit] {filename}` - read file {filename} into a new buffer.
    Vim doesn't "open" files like MS Word does. Instead, it reads the contents of a file into RAM and then you edit the "buffer" in RAM. Other programs may access and change the underlying file you originally opened (Vim will notice this and issue a warning).
    `:w\[rite] {filename}` - write the current buffer to {filename}. If no filename passed (i.e., `:w`) and the buffer already has an associated filename (the one used with `:e {filename}`, that associated filename will be used.
    A simple `:w` is like MS Word "save" and `:w {new_filename}` is "save a copy as `{new_filename}` but keep the current buffer.
    `:save {filename}` - Save as (and change current buffer to {filename})
    `:w!` - force write (e.g., even if the underlying file has been been changed by another program and this write will overwrite those changes)

    These commands can be combined, e.g.
    :wq - write the buffer and quit
    :wq! - force write and quit
    `:wq` - write the buffer and quit
    `:wq!` - force write and quit

    ## Basic motion commands move cursor...
    j - down
    k - up
    h - left
    l - right

    0 - Move to beginning of line
    ^ - Move to first character (non-space or tab) in line (same as "0" if the line starts with a non-space character)
    $ - Move to end of line
    \[Note: ^ and $ are Regular Expression shortcuts for beginning and end of a string, respectively]

    % - If cursor inside parens (or similar), move to opening paren. If cursor on paren, move to partner paren. If not between parens, do nothing. \[Can do weird stuff with unmatched parens.]

    w - forward one word (alphanumeric or \_; or consective chars that are not those)
    e - end of current word (or next word if currently at end of word)
    b - to beginning of word (or previous word if currently at beginning)
    }({) - Move forward (back) a paragraph.

    gg - go to beginning of file
    \[#]gg - go to line [#] (Example 20gg goes to line 20)
    G - go to end of file
    \[#]| - go to column [#] on current line, e.g. 10| goes to col 10.

    f(F)\<char> - "find"/put cursor on next (previous) instance of \<char> in line
    t(T) - "to"/ like f, but put cursor right before the character
    `j` - down
    `k` - up
    `h` - left
    `l` - right

    `0` - Move to beginning of line
    `^` - Move to first character (non-space or tab) in line (same as "0" if the line starts with a non-space character)
    `$` - Move to end of line
    *Note*: `^` and `$` are Regular Expression shortcuts for beginning and end of a string, respectively]

    `%` - If cursor inside parens (or similar), move to opening paren. If cursor on paren, move to partner paren. If not between parens, do nothing. \[Can do weird stuff with unmatched parens.]

    `w` - forward one word (alphanumeric or \_; or consective chars that are not those)
    `e` - end of current word (or next word if currently at end of word)
    `b` - to beginning of word (or previous word if currently at beginning)
    `}` - Move forward a paragraph.
    `{` - Move back a paragraph.

    `gg` - go to beginning of file
    `[#]gg` - go to line [#] (Example 20gg goes to line 20)
    `G` - go to end of file
    `[#]|` - go to column [#] on current line, e.g. 10| goes to col 10.

    `f(F)<char>` - "find"/put cursor on next (previous) instance of \<char> in line
    `t(T)` - "to"/ like f, but put cursor right before the character
    ;(,) - move to next(previous) instance of \<char> from most recent f,F,t, or T

    /(?)\<RegEx>\<Enter> - next (previous) instance of \<RegEx> (uses full Regular Expression matching)
    @@ -86,7 +84,7 @@ Most commands are executed in Normal Mode. If you actually want to add to the te
    i - Enter insert mode before the current character
    a - Enter insert mode After the current character
    \<Esc\> - Exit Insert Mode (go back to Normal Mode).
    \[Note: Because \<Esc> is a little out of the way, it's common to remap a more convenient keybinding to also exit Insert Mode. For example, "inoremap
    [Note: Because \<Esc> is a little out of the way, it's common to remap a more convenient keybinding to also exit Insert Mode. For example, "inoremap
    jk \<Esc>" in vimrc will allow you to use a quick jk instead of \<Esc>]

    I - Enter insert mode at the beginning of the current line's text (same as doing ^ then i)
    @@ -121,7 +119,9 @@ D - delete from here to end of line
    y[m] - yank (copy). Same behavior as d (delete).
    yw - yank from here to beginning of next word
    y$ - yank from here to end of line
    *Note*: To make consistent with D, it's common to add a mapping for Y in your vimrc, i.e., "nnoremap Y y$"
    [Note: To make consistent with D, it's common to add a mapping for Y in your vimrc, like so:
    nnoremap Y y$
    ]

    p - paste after cursor location (like "after" command, a)
    P - paste before cursor location (like i)
    @@ -272,4 +272,4 @@ z= Suggest correctly spelled words
    ]s/\[s Move to next/previous mispelled word (use S for "bad words only")
    zq Add word under cursor as good word to first name in 'spellfile'
    zw Mark as bad word
    zu(q,w) Undo marking
    zu(q,w) Undo marking
  14. @dmsul dmsul revised this gist Dec 29, 2017. 1 changed file with 1 addition and 1 deletion.
    2 changes: 1 addition & 1 deletion vim_crash_course.md
    Original file line number Diff line number Diff line change
    @@ -3,7 +3,7 @@ Vim has 2 main "modes" that are used to change the behavior of all the keys on y

    Some important (or longer) commands begin with ":" and you will see the text you enter next at the bottom left of the screen.

    :q\[uit] - quit (the current window of) Vim. ("Window" here is internal to Vim, not if you have multiple OS-level windows of Vim open at once.)
    `:q\[uit]` - quit (the current window of) Vim. ("Window" here is internal to Vim, not if you have multiple OS-level windows of Vim open at once.)
    :q! - force quit (if the current buffer has been changed since the last save)
    :e\[dit] {filename} - read file {filename} into a new buffer.

  15. @dmsul dmsul revised this gist Dec 29, 2017. 1 changed file with 2 additions and 4 deletions.
    6 changes: 2 additions & 4 deletions vim_crash_course.md
    Original file line number Diff line number Diff line change
    @@ -86,7 +86,7 @@ Most commands are executed in Normal Mode. If you actually want to add to the te
    i - Enter insert mode before the current character
    a - Enter insert mode After the current character
    \<Esc\> - Exit Insert Mode (go back to Normal Mode).
    [Note: Because \<Esc> is a little out of the way, it's common to remap a more convenient keybinding to also exit Insert Mode. For example, "inoremap
    \[Note: Because \<Esc> is a little out of the way, it's common to remap a more convenient keybinding to also exit Insert Mode. For example, "inoremap
    jk \<Esc>" in vimrc will allow you to use a quick jk instead of \<Esc>]

    I - Enter insert mode at the beginning of the current line's text (same as doing ^ then i)
    @@ -121,9 +121,7 @@ D - delete from here to end of line
    y[m] - yank (copy). Same behavior as d (delete).
    yw - yank from here to beginning of next word
    y$ - yank from here to end of line
    [Note: To make consistent with D, it's common to add a mapping for Y in your vimrc, like so:
    nnoremap Y y$
    ]
    *Note*: To make consistent with D, it's common to add a mapping for Y in your vimrc, i.e., "nnoremap Y y$"

    p - paste after cursor location (like "after" command, a)
    P - paste before cursor location (like i)
  16. @dmsul dmsul revised this gist Dec 29, 2017. 1 changed file with 4 additions and 1 deletion.
    5 changes: 4 additions & 1 deletion vim_crash_course.md
    Original file line number Diff line number Diff line change
    @@ -6,9 +6,12 @@ Some important (or longer) commands begin with ":" and you will see the text you
    :q\[uit] - quit (the current window of) Vim. ("Window" here is internal to Vim, not if you have multiple OS-level windows of Vim open at once.)
    :q! - force quit (if the current buffer has been changed since the last save)
    :e\[dit] {filename} - read file {filename} into a new buffer.
    Vim doesn't "open" files like MS Word does. Instead, it reads the contents of a file into RAM and then you edit the "buffer" in RAM. Other programs may access and change the underlying file you originally opened (Vim will notice this and issue a warning).

    *Note*: Vim doesn't "open" files like MS Word does. Instead, it reads the contents of a file into RAM and then you edit the "buffer" in RAM. Other programs may access and change the underlying file you originally opened (Vim will notice this and issue a warning).

    :w\[rite] {filename} - write the current buffer to {filename}. If no filename passed (i.e., ":w") and the buffer already has an associated filename (the one used with ":e {filename}", that associated filename will be used.
    A simple ":w" is like MS Word "save" and ":w {new_filename}" is "save a copy as {new_filename} but keep the current buffer".

    :save {filename} - Save as (and change current buffer to {filename})
    :w! - force write (e.g., even if the underlying file has been been changed by another program and this write will overwrite those changes)

  17. @dmsul dmsul revised this gist Dec 29, 2017. 1 changed file with 1 addition and 1 deletion.
    2 changes: 1 addition & 1 deletion vim_crash_course.md
    Original file line number Diff line number Diff line change
    @@ -1,5 +1,5 @@
    # NORMAL MODE
    Vim has 2 main "modes", that chance the behavior of all your keys. The default mode of Vim is Normal Mode and is mostly used for moving the cursor and navigating the current file.
    Vim has 2 main "modes" that are used to change the behavior of all the keys on your keyboard. The default mode of Vim is Normal Mode and is mostly used for moving the cursor and navigating the current file.

    Some important (or longer) commands begin with ":" and you will see the text you enter next at the bottom left of the screen.

  18. @dmsul dmsul revised this gist Dec 29, 2017. 1 changed file with 3 additions and 1 deletion.
    4 changes: 3 additions & 1 deletion vim_crash_course.md
    Original file line number Diff line number Diff line change
    @@ -90,11 +90,13 @@ I - Enter insert mode at the beginning of the current line's text (same as doing
    A - Enter insert mode After the end of th current line (like $ then a)
    o - Add a new line after the current line and enter insert mode (like doing A\<Enter>)
    O - Add a new line before the current line and enter insert mode

    c[m] - Change text from here to [m]. "Change" deletes the text and immediately enters insert mode.
    cc - Change this whole line.
    C - Changes from here to end of line.

    r - replace the current character with the next character typed (only one character allowed)
    R - Replace characters until \<Esc> (like replace/overwrite mode in Word)
    c[m] - Change text from here to [m]. "Change" deletes the text and immediately enters insert mode.


    # Edit commands for Normal Mode
  19. @dmsul dmsul revised this gist Dec 29, 2017. 1 changed file with 155 additions and 155 deletions.
    310 changes: 155 additions & 155 deletions vim_crash_course.md
    Original file line number Diff line number Diff line change
    @@ -3,98 +3,98 @@ Vim has 2 main "modes", that chance the behavior of all your keys. The default m

    Some important (or longer) commands begin with ":" and you will see the text you enter next at the bottom left of the screen.

    :q\[uit] - quit (the current window of) Vim. ("Window" here is internal to Vim, not if you have multiple OS-level windows of Vim open at once.)
    :q! - force quit (if the current buffer has been changed since the last save)
    :e\[dit] {filename} - read file {filename} into a new buffer.
    :q\[uit] - quit (the current window of) Vim. ("Window" here is internal to Vim, not if you have multiple OS-level windows of Vim open at once.)
    :q! - force quit (if the current buffer has been changed since the last save)
    :e\[dit] {filename} - read file {filename} into a new buffer.
    Vim doesn't "open" files like MS Word does. Instead, it reads the contents of a file into RAM and then you edit the "buffer" in RAM. Other programs may access and change the underlying file you originally opened (Vim will notice this and issue a warning).
    :w\[rite] {filename} - write the current buffer to {filename}. If no filename passed (i.e., ":w") and the buffer already has an associated filename (the one used with ":e {filename}", that associated filename will be used.
    A simple ":w" is like MS Word "save" and ":w {new_filename}" is "save a copy as {new_filename} but keep the current buffer".
    :save {filename} - Save as (and change current buffer to {filename})
    :w\[rite] {filename} - write the current buffer to {filename}. If no filename passed (i.e., ":w") and the buffer already has an associated filename (the one used with ":e {filename}", that associated filename will be used.
    A simple ":w" is like MS Word "save" and ":w {new_filename}" is "save a copy as {new_filename} but keep the current buffer".
    :save {filename} - Save as (and change current buffer to {filename})
    :w! - force write (e.g., even if the underlying file has been been changed by another program and this write will overwrite those changes)

    These commands can be combined, e.g.
    :wq - write the buffer and quit
    :wq! - force write and quit
    These commands can be combined, e.g.
    :wq - write the buffer and quit
    :wq! - force write and quit

    ## Basic motion commands move cursor...
    j - down
    k - up
    h - left
    l - right

    0 - Move to beginning of line
    ^ - Move to first character (non-space or tab) in line (same as "0" if the line starts with a non-space character)
    $ - Move to end of line
    0 - Move to beginning of line
    ^ - Move to first character (non-space or tab) in line (same as "0" if the line starts with a non-space character)
    $ - Move to end of line
    \[Note: ^ and $ are Regular Expression shortcuts for beginning and end of a string, respectively]

    % - If cursor inside parens (or similar), move to opening paren. If cursor on paren, move to partner paren. If not between parens, do nothing. [Can do weird stuff with unmatched parens.]
    % - If cursor inside parens (or similar), move to opening paren. If cursor on paren, move to partner paren. If not between parens, do nothing. \[Can do weird stuff with unmatched parens.]

    w - forward one word (alphanumeric or _; or consective chars that are not those)
    e - end of current word (or next word if currently at end of word)
    b - to beginning of word (or previous word if currently at beginning)
    w - forward one word (alphanumeric or \_; or consective chars that are not those)
    e - end of current word (or next word if currently at end of word)
    b - to beginning of word (or previous word if currently at beginning)
    }({) - Move forward (back) a paragraph.

    gg - go to beginning of file
    \[#]gg - go to line [#] (Example 20gg goes to line 20)
    G - go to end of file
    \[#]| - go to column [#] on current line, e.g. 10| goes to col 10.
    gg - go to beginning of file
    \[#]gg - go to line [#] (Example 20gg goes to line 20)
    G - go to end of file
    \[#]| - go to column [#] on current line, e.g. 10| goes to col 10.

    f(F)<char> - "find"/put cursor on next (previous) instance of <char> in line
    t(T) - "to"/ like f, but put cursor right before the character
    ;(,) - move to next(previous) instance of <char> from most recent f,F,t, or T
    f(F)\<char> - "find"/put cursor on next (previous) instance of \<char> in line
    t(T) - "to"/ like f, but put cursor right before the character
    ;(,) - move to next(previous) instance of \<char> from most recent f,F,t, or T

    /(?)<RegEx><Enter> - next (previous) instance of <RegEx> (uses full Regular Expression matching)
    n(N) - next instance of recent search
    \* - Do "/" search for word under cursor
    \[This is basic search functionality. "/gen<Enter>" will go to the next instance of the string "gen", and then hitting "n" will move to the next instance, etc. When you get to the end of the file, it will cycle back to the beginning. Using "?" instead of "/" is just a backwards search.\]
    /(?)\<RegEx>\<Enter> - next (previous) instance of \<RegEx> (uses full Regular Expression matching)
    n(N) - next instance of recent search
    \* - Do "/" search for word under cursor
    \[This is basic search functionality. "/gen\<Enter>" will go to the next instance of the string "gen", and then hitting "n" will move to the next instance, etc. When you get to the end of the file, it will cycle back to the beginning. Using "?" instead of "/" is just a backwards search.\]

    c-u - move cursor Up full page
    c-d - move cursor Down full page
    _Note: "c-u" in Vim mappings means "Ctrl-u"_
    c-u - move cursor Up full page
    c-d - move cursor Down full page
    _Note: "c-u" in Vim mappings means "Ctrl-u"_

    c-e - scroll forward, keeping cursor in place
    e-y - scroll backward, keeping cursor in place
    c-e - scroll forward, keeping cursor in place
    e-y - scroll backward, keeping cursor in place

    c-f - Forward half-page
    c-b - Back half-page
    c-f - Forward half-page
    c-b - Back half-page

    H - highest line on screen (home)
    M - middle line on screen
    L - lowest line on screen
    H - highest line on screen (home)
    M - middle line on screen
    L - lowest line on screen


    **Note:** Most motion commands can take a number before them to execute that number of times.
    4j - move cursor down 4 times
    10w - move forward 10 "words"
    **Note:** Most motion commands can take a number before them to execute that number of times.
    4j - move cursor down 4 times
    10w - move forward 10 "words"

    # VISUAL "MODE"
    v[m] - Go into visual (highlight) mode to select characters. Use usual motion commands to add to selection as cursor moves.
    V[m] - Visual mode, but grab whole lines at a time, not characters.
    c-v[m] - Visual mode, but select vertically (by columns) instead of horizontally
    v[m] - Go into visual (highlight) mode to select characters. Use usual motion commands to add to selection as cursor moves.
    V[m] - Visual mode, but grab whole lines at a time, not characters.
    c-v[m] - Visual mode, but select vertically (by columns) instead of horizontally

    ggvG - Highlight whole file, i.e., go to beginning of file (gg), enter visual mode (v), go to end of file (G).
    ggvG - Highlight whole file, i.e., go to beginning of file (gg), enter visual mode (v), go to end of file (G).

    Once a selection has been made, you can use an edit command (see below) on that selection and it will (usually) behave as you'd expect.
    Once a selection has been made, you can use an edit command (see below) on that selection and it will (usually) behave as you'd expect.


    # INSERT MODE
    Most commands are executed in Normal Mode. If you actually want to add to the text (type a "j" instead of moving down one line) you need to enter Insert Mode. There are several ways to do this.

    i - Enter insert mode before the current character
    a - Enter insert mode After the current character
    \<Esc\> - Exit Insert Mode (go back to Normal Mode).
    [Note: Because <Esc> is a little out of the way, it's common to remap a more convenient keybinding to also exit Insert Mode. For example, "inoremap
    jk <Esc>" in vimrc will allow you to use a quick jk instead of <Esc>]
    i - Enter insert mode before the current character
    a - Enter insert mode After the current character
    \<Esc\> - Exit Insert Mode (go back to Normal Mode).
    [Note: Because \<Esc> is a little out of the way, it's common to remap a more convenient keybinding to also exit Insert Mode. For example, "inoremap
    jk \<Esc>" in vimrc will allow you to use a quick jk instead of \<Esc>]

    I - Enter insert mode at the beginning of the current line's text (same as doing ^ then i)
    A - Enter insert mode After the end of th current line (like $ then a)
    o - Add a new line after the current line and enter insert mode (like doing A<Enter>)
    O - Add a new line before the current line and enter insert mode
    cc - Change this whole line.
    C - Changes from here to end of line.
    r - replace the current character with the next character typed (only one character allowed)
    R - Replace characters until <Esc> (like replace/overwrite mode in Word)
    c[m] - Change text from here to [m]. "Change" deletes the text and immediately enters insert mode.
    I - Enter insert mode at the beginning of the current line's text (same as doing ^ then i)
    A - Enter insert mode After the end of th current line (like $ then a)
    o - Add a new line after the current line and enter insert mode (like doing A\<Enter>)
    O - Add a new line before the current line and enter insert mode
    cc - Change this whole line.
    C - Changes from here to end of line.
    r - replace the current character with the next character typed (only one character allowed)
    R - Replace characters until \<Esc> (like replace/overwrite mode in Word)
    c[m] - Change text from here to [m]. "Change" deletes the text and immediately enters insert mode.


    # Edit commands for Normal Mode
    @@ -104,80 +104,80 @@ shift + command: execute command from cursor to end of current line

    More generally, the composability of editing commands and motion is what makes Vim particularly powerful. If you know 5 editing commands and 5 motion commands, you actually know 25 specific and easy to remember commands.

    [#]d[m] - delete over [m] (do this [#] times)
    dw - delete from here (location of cursor) to beginning of next word (includes character under the cursor)
    d4w - delete from here to beginning of 4th word forward
    dtT - deletes "to" (up to but not including) the next instance of "T" on this line
    df) - deletes to ("finds") the next instance of ")" on this line
    [#]d[m] - delete over [m] (do this [#] times)
    dw - delete from here (location of cursor) to beginning of next word (includes character under the cursor)
    d4w - delete from here to beginning of 4th word forward
    dtT - deletes "to" (up to but not including) the next instance of "T" on this line
    df) - deletes to ("finds") the next instance of ")" on this line

    dd - delete this entire line 4dd - delete this line and next 3 (4 total)
    D - delete from here to end of line
    dd - delete this entire line 4dd - delete this line and next 3 (4 total)
    D - delete from here to end of line

    y[m] - yank (copy). Same behavior as d (delete).
    yw - yank from here to beginning of next word
    y$ - yank from here to end of line
    [Note: To make consistent with D, it's common to add a mapping for Y in your vimrc, like so:
    y[m] - yank (copy). Same behavior as d (delete).
    yw - yank from here to beginning of next word
    y$ - yank from here to end of line
    [Note: To make consistent with D, it's common to add a mapping for Y in your vimrc, like so:
    nnoremap Y y$
    ]

    p - paste after cursor location (like "after" command, a)
    P - paste before cursor location (like i)
    p - paste after cursor location (like "after" command, a)
    P - paste before cursor location (like i)

    ## Registers (for yank and paste).
    "<char>y - yank to register <char>.
    "\<char>y - yank to register \<char>.
    This allows you to have multiple things in your clipboard. Note the Vim clipboard is separate from the OS clipboard. To move between the two (copy/paste between Vim and another program) use the * register, so:

    y$ - yanks to end of line, puts in default register
    "a$ - yank to register "a"
    "*yG - yanks to end of file, puts in OS register
    p - pastes what's in the default register (after the cursor, like "a")
    P - paste before cursor (like command "i")
    y$ - yanks to end of line, puts in default register
    "a$ - yank to register "a"
    "*yG - yanks to end of file, puts in OS register
    p - pastes what's in the default register (after the cursor, like "a")
    P - paste before cursor (like command "i")
    "*p - pastes what's in the OS register (i.e., if you already yanked to * or you did a Ctrl+C copy in another program)

    NOTE: deleting text puts that text into the default register, so if you "yy", move to another line, then "dd", you'll lose whatever whatever you yanked with "yy". There is a plugin to override this behavior (I think by Tim Pope).


    ## Change case
    \[#]~ - toggle case of \[#] character(s)
    g~\[m] - toggle case with motion [m]
    gU\[m] - uppercase
    gu\[m] - lowercase
    \[#]~ - toggle case of \[#] character(s)
    g~\[m] - toggle case with motion [m]
    gU\[m] - uppercase
    gu\[m] - lowercase

    ## Indentation
    \>\[m] - indent current line through motion \[m]
    \>5j - indent this and next 5 lines
    \>G - indent to end of file
    \>\> - indent this line (like dd, yy, etc.)
    \<\[m] - un-indent (same as indent, but in reverse)
    \>\[m] - indent current line through motion \[m]
    \>5j - indent this and next 5 lines
    \>G - indent to end of file
    \>\> - indent this line (like dd, yy, etc.)
    \<\[m] - un-indent (same as indent, but in reverse)


    ## Misc useful commands
    J - Take the next line and move it to the end of this line.

    gq\[m] - Format the text between here and [m] (usually just breaks overly long lines to smaller lines, by default 80 characters).
    gqq - Format the current line
    gq\[m] - Format the text between here and [m] (usually just breaks overly long lines to smaller lines, by default 80 characters).
    gqq - Format the current line

    u - undo
    c-r - redo
    u - undo
    c-r - redo

    . - repeat last edit (including insert, replace, indent, etc.) \[EXTREMELY useful]
    A;;\<Esc>j. - Enter insert mode at end of line (A), type two semi-colons [;;], exit Insert Mode \[\<Esc>], move down one line \[j], and add two semi-colons to the end of this new line \[.]
    . - repeat last edit (including insert, replace, indent, etc.) \[EXTREMELY useful]
    A;;\<Esc>j. - Enter insert mode at end of line (A), type two semi-colons [;;], exit Insert Mode \[\<Esc>], move down one line \[j], and add two semi-colons to the end of this new line \[.]
    \>\>... - Indent this line \[\>\>], then three more times [...]


    # Substitution
    :<range>s/<re>/<str>/<flags> - substitute first instance of <re> in each line in <range> with <str>. <flags> change default behavior.
    <range>
    default range is this line only
    % - global (whole file)
    \<a\>,\<b\> - between lines/markers/etc
    . - current line
    $ - last line in file (so :.,$s is "from here to end of file")
    [There are other <range> things, most common is just %.]
    <flags>
    g - global/all instance of <re> on line (not just first instance on line)
    c - confirm (will highlight next instance of <re> and ask you to press "y" to execute change
    i - case insensitive
    :\<range>s/\<re>/\<str>/\<flags> - substitute first instance of \<re> in each line in \<range> with \<str>. \<flags> change default behavior.
    \<range>
    default range is this line only
    % - global (whole file)
    \<a\>,\<b\> - between lines/markers/etc
    . - current line
    $ - last line in file (so :.,$s is "from here to end of file")
    \[There are other \<range> things, most common is just %.]
    \<flags>
    g - global/all instance of \<re> on line (not just first instance on line)
    c - confirm (will highlight next instance of \<re> and ask you to press "y" to execute change
    i - case insensitive

    Specific sub: Use "\zs" and "\ze" to demark a sub-RegEx within the matched RegEx that should be substituted. Example:

    @@ -191,82 +191,82 @@ There are "motion" commands that can be used with delete, yank, etc., that can b

    A shortcut around this is these motion-like object commands.

    daw - Delete "a" "word". Deletes the current word and space(s) after it.
    diw - Delete "inner" "word". Deletes current word but not trailing space(s).
    dap - Delete a paragraph. A "paragraph" to Vim is a group of consecutive lines of text between an empty line(s).
    yaw - Yanks a word.
    yiw - Yanks inner word.
    ya( - Yank a parenthetical. If cursor between (), yank everything between those parens and the parens themselves. Else do Nothing.
    yi( - Yank inner parenthetical. Like ya(, but excluding the parens.
    ya) - ya(
    ya[ - Same as ya( but for brackets [].
    ya" - Same
    daw - Delete "a" "word". Deletes the current word and space(s) after it.
    diw - Delete "inner" "word". Deletes current word but not trailing space(s).
    dap - Delete a paragraph. A "paragraph" to Vim is a group of consecutive lines of text between an empty line(s).
    yaw - Yanks a word.
    yiw - Yanks inner word.
    ya( - Yank a parenthetical. If cursor between (), yank everything between those parens and the parens themselves. Else do Nothing.
    yi( - Yank inner parenthetical. Like ya(, but excluding the parens.
    ya) - ya(
    ya\[ - Same as ya( but for brackets \[].
    ya" - Same

    da( - Deletes a parenthetical.
    di( - Deletes within parenthetical.
    da( - Deletes a parenthetical.
    di( - Deletes within parenthetical.

    g~i( - Toggles the case of the inner parenthetical.
    g~i( - Toggles the case of the inner parenthetical.

    ciw - Change inner word
    ci[ - Change inner (within) brackets (delete text within brackets and enter Insert Mode).
    ciw - Change inner word
    ci[ - Change inner (within) brackets (delete text within brackets and enter Insert Mode).


    # Other very useful stuff

    ## Predictive completion (while in Insert Mode)
    c-p - predictive completion (word)
    c-x c-l predictive completion (line)
    c-p - predictive completion (word)
    c-x c-l predictive completion (line)

    This takes what you've already typed (either word or line) and uses the text in the rest of any open buffers to predict what will come next. If there's only one possibility, it will be filled in. If there are several possibilities, it will give you the choices.

    Vim autocomplete is pretty nice, but there are better, automated predictive text solutions (specifcally, the package YouCompleteMe). However, I've found they're a bit too demanding for most laptops and only useful on desktop computers.

    ## Global command by line
    :g/<RegEx>/<edit command> - perform the edit command on every line that matches RegEx
    :g!/... or :v/... -- the same but for lines that don't match
    Examples:
    :g/DEL THIS/d deletes every line that contains "DEL THIS"
    :g/ $/d deletes every line that ends with a space.
    :g/\<RegEx>/\<edit command> - perform the edit command on every line that matches RegEx
    :g!/... or :v/... -- the same but for lines that don't match
    Examples:
    :g/DEL THIS/d deletes every line that contains "DEL THIS"
    :g/ $/d deletes every line that ends with a space.

    ## Macros

    Hit 'q' then a letter 'a' to begin recording macro 'a'.
    Do your thing.
    Hit 'q' to stop recording.
    @a to repeat the new macro. [#]@a repeats a # times.
    Hit 'q' then a letter 'a' to begin recording macro 'a'.
    Do your thing.
    Hit 'q' to stop recording.
    @a to repeat the new macro. [#]@a repeats a # times.


    # Other moderately useful stuff

    ## Marks

    Lower case are local, upper case are global (across files). Jumping to a mark is a standard motion command for deleting, yanking, etc.
    ma - sets mark on current cursor location (line and column), WLOG, called "a"
    'a - jump to line of "a" (first non-blank character of line)
    \`a - jump to position of "a" (line and col)
    :marks - lists all current marks
    :delmarks <args>
    a - delete a
    a-d - delete a through d
    abxy - delete this list
    :delmarks! - delete all lowercase in buffer
    ]', [' - jump to next (previous) line with a lowercase mark
    ]\`, [\` - jump to next (previous) lowercase mark

    Special Marks \[_Most useful when beginning_]
    ' - The line you were on before making a "jump". So if you're on line 57 and jump to beginning of file using "gg", hitting '' will take you right back to line 57.
    Special marks
    . - last edit in current buffer
    \`\` - jump back to position (line and col) where just jumped from
    \`\[, \`] - jump to beg/end of last changed or yanked text
    \`<, \`> - jump to beg/end of last visual selection

    ma - sets mark on current cursor location (line and column), WLOG, called "a"
    'a - jump to line of "a" (first non-blank character of line)
    \`a - jump to position of "a" (line and col)
    :marks - lists all current marks
    :delmarks \<args>
    a - delete a
    a-d - delete a through d
    abxy - delete this list
    :delmarks! - delete all lowercase in buffer
    ]', [' - jump to next (previous) line with a lowercase mark
    ]\`, [\` - jump to next (previous) lowercase mark

    ### Special Marks \[Most useful when beginning]
    ' - The line you were on before making a "jump". So if you're on line 57 and jump to beginning of file using "gg", hitting '' will take you right back to line 57.
    . - last edit in current buffer
    \`\` - jump back to position (line and col) where just jumped from
    \`\[, \`] - jump to beg/end of last changed or yanked text
    \`<, \`> - jump to beg/end of last visual selection

    ## Spellcheck

    Turn on with ":set spell", turn off with ":set nospell".

    z= Suggest correctly spelled words
    ]s/\[s Move to next/previous mispelled word (use S for "bad words only")
    zq Add word under cursor as good word to first name in 'spellfile'
    zw Mark as bad word
    zu(q,w) Undo marking
    z= Suggest correctly spelled words
    ]s/\[s Move to next/previous mispelled word (use S for "bad words only")
    zq Add word under cursor as good word to first name in 'spellfile'
    zw Mark as bad word
    zu(q,w) Undo marking
  20. @dmsul dmsul revised this gist Dec 29, 2017. 1 changed file with 4 additions and 4 deletions.
    8 changes: 4 additions & 4 deletions vim_crash_course.md
    Original file line number Diff line number Diff line change
    @@ -17,10 +17,10 @@ These commands can be combined, e.g.
    :wq! - force write and quit

    ## Basic motion commands move cursor...
    j - down
    k - up
    h - left
    l - right
    j - down
    k - up
    h - left
    l - right

    0 - Move to beginning of line
    ^ - Move to first character (non-space or tab) in line (same as "0" if the line starts with a non-space character)
  21. @dmsul dmsul revised this gist Dec 29, 2017. No changes.
  22. @dmsul dmsul revised this gist Dec 29, 2017. No changes.
  23. @dmsul dmsul created this gist Dec 29, 2017.
    272 changes: 272 additions & 0 deletions vim_crash_course.md
    Original file line number Diff line number Diff line change
    @@ -0,0 +1,272 @@
    # NORMAL MODE
    Vim has 2 main "modes", that chance the behavior of all your keys. The default mode of Vim is Normal Mode and is mostly used for moving the cursor and navigating the current file.

    Some important (or longer) commands begin with ":" and you will see the text you enter next at the bottom left of the screen.

    :q\[uit] - quit (the current window of) Vim. ("Window" here is internal to Vim, not if you have multiple OS-level windows of Vim open at once.)
    :q! - force quit (if the current buffer has been changed since the last save)
    :e\[dit] {filename} - read file {filename} into a new buffer.
    Vim doesn't "open" files like MS Word does. Instead, it reads the contents of a file into RAM and then you edit the "buffer" in RAM. Other programs may access and change the underlying file you originally opened (Vim will notice this and issue a warning).
    :w\[rite] {filename} - write the current buffer to {filename}. If no filename passed (i.e., ":w") and the buffer already has an associated filename (the one used with ":e {filename}", that associated filename will be used.
    A simple ":w" is like MS Word "save" and ":w {new_filename}" is "save a copy as {new_filename} but keep the current buffer".
    :save {filename} - Save as (and change current buffer to {filename})
    :w! - force write (e.g., even if the underlying file has been been changed by another program and this write will overwrite those changes)

    These commands can be combined, e.g.
    :wq - write the buffer and quit
    :wq! - force write and quit

    ## Basic motion commands move cursor...
    j - down
    k - up
    h - left
    l - right

    0 - Move to beginning of line
    ^ - Move to first character (non-space or tab) in line (same as "0" if the line starts with a non-space character)
    $ - Move to end of line
    \[Note: ^ and $ are Regular Expression shortcuts for beginning and end of a string, respectively]

    % - If cursor inside parens (or similar), move to opening paren. If cursor on paren, move to partner paren. If not between parens, do nothing. [Can do weird stuff with unmatched parens.]

    w - forward one word (alphanumeric or _; or consective chars that are not those)
    e - end of current word (or next word if currently at end of word)
    b - to beginning of word (or previous word if currently at beginning)
    }({) - Move forward (back) a paragraph.

    gg - go to beginning of file
    \[#]gg - go to line [#] (Example 20gg goes to line 20)
    G - go to end of file
    \[#]| - go to column [#] on current line, e.g. 10| goes to col 10.

    f(F)<char> - "find"/put cursor on next (previous) instance of <char> in line
    t(T) - "to"/ like f, but put cursor right before the character
    ;(,) - move to next(previous) instance of <char> from most recent f,F,t, or T

    /(?)<RegEx><Enter> - next (previous) instance of <RegEx> (uses full Regular Expression matching)
    n(N) - next instance of recent search
    \* - Do "/" search for word under cursor
    \[This is basic search functionality. "/gen<Enter>" will go to the next instance of the string "gen", and then hitting "n" will move to the next instance, etc. When you get to the end of the file, it will cycle back to the beginning. Using "?" instead of "/" is just a backwards search.\]

    c-u - move cursor Up full page
    c-d - move cursor Down full page
    _Note: "c-u" in Vim mappings means "Ctrl-u"_

    c-e - scroll forward, keeping cursor in place
    e-y - scroll backward, keeping cursor in place

    c-f - Forward half-page
    c-b - Back half-page

    H - highest line on screen (home)
    M - middle line on screen
    L - lowest line on screen


    **Note:** Most motion commands can take a number before them to execute that number of times.
    4j - move cursor down 4 times
    10w - move forward 10 "words"

    # VISUAL "MODE"
    v[m] - Go into visual (highlight) mode to select characters. Use usual motion commands to add to selection as cursor moves.
    V[m] - Visual mode, but grab whole lines at a time, not characters.
    c-v[m] - Visual mode, but select vertically (by columns) instead of horizontally

    ggvG - Highlight whole file, i.e., go to beginning of file (gg), enter visual mode (v), go to end of file (G).

    Once a selection has been made, you can use an edit command (see below) on that selection and it will (usually) behave as you'd expect.


    # INSERT MODE
    Most commands are executed in Normal Mode. If you actually want to add to the text (type a "j" instead of moving down one line) you need to enter Insert Mode. There are several ways to do this.

    i - Enter insert mode before the current character
    a - Enter insert mode After the current character
    \<Esc\> - Exit Insert Mode (go back to Normal Mode).
    [Note: Because <Esc> is a little out of the way, it's common to remap a more convenient keybinding to also exit Insert Mode. For example, "inoremap
    jk <Esc>" in vimrc will allow you to use a quick jk instead of <Esc>]

    I - Enter insert mode at the beginning of the current line's text (same as doing ^ then i)
    A - Enter insert mode After the end of th current line (like $ then a)
    o - Add a new line after the current line and enter insert mode (like doing A<Enter>)
    O - Add a new line before the current line and enter insert mode
    cc - Change this whole line.
    C - Changes from here to end of line.
    r - replace the current character with the next character typed (only one character allowed)
    R - Replace characters until <Esc> (like replace/overwrite mode in Word)
    c[m] - Change text from here to [m]. "Change" deletes the text and immediately enters insert mode.


    # Edit commands for Normal Mode
    These commands help change text while still in Normal Mode. Many of these commands require a motion command (signified here as [m]) to follow to specify the extent over which to execute the edit. Several common conventions for many (but not all) commands:
    double-tap: execute command for entire line cursor is currently on
    shift + command: execute command from cursor to end of current line

    More generally, the composability of editing commands and motion is what makes Vim particularly powerful. If you know 5 editing commands and 5 motion commands, you actually know 25 specific and easy to remember commands.

    [#]d[m] - delete over [m] (do this [#] times)
    dw - delete from here (location of cursor) to beginning of next word (includes character under the cursor)
    d4w - delete from here to beginning of 4th word forward
    dtT - deletes "to" (up to but not including) the next instance of "T" on this line
    df) - deletes to ("finds") the next instance of ")" on this line

    dd - delete this entire line 4dd - delete this line and next 3 (4 total)
    D - delete from here to end of line

    y[m] - yank (copy). Same behavior as d (delete).
    yw - yank from here to beginning of next word
    y$ - yank from here to end of line
    [Note: To make consistent with D, it's common to add a mapping for Y in your vimrc, like so:
    nnoremap Y y$
    ]

    p - paste after cursor location (like "after" command, a)
    P - paste before cursor location (like i)

    ## Registers (for yank and paste).
    "<char>y - yank to register <char>.
    This allows you to have multiple things in your clipboard. Note the Vim clipboard is separate from the OS clipboard. To move between the two (copy/paste between Vim and another program) use the * register, so:

    y$ - yanks to end of line, puts in default register
    "a$ - yank to register "a"
    "*yG - yanks to end of file, puts in OS register
    p - pastes what's in the default register (after the cursor, like "a")
    P - paste before cursor (like command "i")
    "*p - pastes what's in the OS register (i.e., if you already yanked to * or you did a Ctrl+C copy in another program)

    NOTE: deleting text puts that text into the default register, so if you "yy", move to another line, then "dd", you'll lose whatever whatever you yanked with "yy". There is a plugin to override this behavior (I think by Tim Pope).


    ## Change case
    \[#]~ - toggle case of \[#] character(s)
    g~\[m] - toggle case with motion [m]
    gU\[m] - uppercase
    gu\[m] - lowercase

    ## Indentation
    \>\[m] - indent current line through motion \[m]
    \>5j - indent this and next 5 lines
    \>G - indent to end of file
    \>\> - indent this line (like dd, yy, etc.)
    \<\[m] - un-indent (same as indent, but in reverse)


    ## Misc useful commands
    J - Take the next line and move it to the end of this line.

    gq\[m] - Format the text between here and [m] (usually just breaks overly long lines to smaller lines, by default 80 characters).
    gqq - Format the current line

    u - undo
    c-r - redo

    . - repeat last edit (including insert, replace, indent, etc.) \[EXTREMELY useful]
    A;;\<Esc>j. - Enter insert mode at end of line (A), type two semi-colons [;;], exit Insert Mode \[\<Esc>], move down one line \[j], and add two semi-colons to the end of this new line \[.]
    \>\>... - Indent this line \[\>\>], then three more times [...]


    # Substitution
    :<range>s/<re>/<str>/<flags> - substitute first instance of <re> in each line in <range> with <str>. <flags> change default behavior.
    <range>
    default range is this line only
    % - global (whole file)
    \<a\>,\<b\> - between lines/markers/etc
    . - current line
    $ - last line in file (so :.,$s is "from here to end of file")
    [There are other <range> things, most common is just %.]
    <flags>
    g - global/all instance of <re> on line (not just first instance on line)
    c - confirm (will highlight next instance of <re> and ask you to press "y" to execute change
    i - case insensitive

    Specific sub: Use "\zs" and "\ze" to demark a sub-RegEx within the matched RegEx that should be substituted. Example:

    :%s/Year \zs2007\ze is over/2008/g

    This changes all instances of "Year 2007 is over" to "Year 2008 is over", but not all "2007" to "2008".


    # Advanced motion(ish) commands
    There are "motion" commands that can be used with delete, yank, etc., that can be used to target specific text objects. "dw" will delete from cursor to beginning of next word, so will not delete the entire current word under the cursor unless the cursor happens to be at the beginning of the wordSo "bdw" will delete the whole word and the space(s) after it (unless the cursor is already at the beginning of the word).

    A shortcut around this is these motion-like object commands.

    daw - Delete "a" "word". Deletes the current word and space(s) after it.
    diw - Delete "inner" "word". Deletes current word but not trailing space(s).
    dap - Delete a paragraph. A "paragraph" to Vim is a group of consecutive lines of text between an empty line(s).
    yaw - Yanks a word.
    yiw - Yanks inner word.
    ya( - Yank a parenthetical. If cursor between (), yank everything between those parens and the parens themselves. Else do Nothing.
    yi( - Yank inner parenthetical. Like ya(, but excluding the parens.
    ya) - ya(
    ya[ - Same as ya( but for brackets [].
    ya" - Same

    da( - Deletes a parenthetical.
    di( - Deletes within parenthetical.

    g~i( - Toggles the case of the inner parenthetical.

    ciw - Change inner word
    ci[ - Change inner (within) brackets (delete text within brackets and enter Insert Mode).


    # Other very useful stuff

    ## Predictive completion (while in Insert Mode)
    c-p - predictive completion (word)
    c-x c-l predictive completion (line)

    This takes what you've already typed (either word or line) and uses the text in the rest of any open buffers to predict what will come next. If there's only one possibility, it will be filled in. If there are several possibilities, it will give you the choices.

    Vim autocomplete is pretty nice, but there are better, automated predictive text solutions (specifcally, the package YouCompleteMe). However, I've found they're a bit too demanding for most laptops and only useful on desktop computers.

    ## Global command by line
    :g/<RegEx>/<edit command> - perform the edit command on every line that matches RegEx
    :g!/... or :v/... -- the same but for lines that don't match
    Examples:
    :g/DEL THIS/d deletes every line that contains "DEL THIS"
    :g/ $/d deletes every line that ends with a space.

    ## Macros

    Hit 'q' then a letter 'a' to begin recording macro 'a'.
    Do your thing.
    Hit 'q' to stop recording.
    @a to repeat the new macro. [#]@a repeats a # times.


    # Other moderately useful stuff

    ## Marks

    Lower case are local, upper case are global (across files). Jumping to a mark is a standard motion command for deleting, yanking, etc.
    ma - sets mark on current cursor location (line and column), WLOG, called "a"
    'a - jump to line of "a" (first non-blank character of line)
    \`a - jump to position of "a" (line and col)
    :marks - lists all current marks
    :delmarks <args>
    a - delete a
    a-d - delete a through d
    abxy - delete this list
    :delmarks! - delete all lowercase in buffer
    ]', [' - jump to next (previous) line with a lowercase mark
    ]\`, [\` - jump to next (previous) lowercase mark

    Special Marks \[_Most useful when beginning_]
    ' - The line you were on before making a "jump". So if you're on line 57 and jump to beginning of file using "gg", hitting '' will take you right back to line 57.
    Special marks
    . - last edit in current buffer
    \`\` - jump back to position (line and col) where just jumped from
    \`\[, \`] - jump to beg/end of last changed or yanked text
    \`<, \`> - jump to beg/end of last visual selection

    ## Spellcheck

    Turn on with ":set spell", turn off with ":set nospell".

    z= Suggest correctly spelled words
    ]s/\[s Move to next/previous mispelled word (use S for "bad words only")
    zq Add word under cursor as good word to first name in 'spellfile'
    zw Mark as bad word
    zu(q,w) Undo marking