Update vim cheatsheet

This commit is contained in:
Rico Sta. Cruz 2017-08-24 15:51:01 +08:00
parent d4b9c9977c
commit 0c8749580d
No known key found for this signature in database
GPG Key ID: CAAD38AE2962619A
2 changed files with 237 additions and 126 deletions

View File

@ -26,6 +26,10 @@
text-align: right;
}
& td:first-child {
white-space: nowrap;
}
& td:first-child > code {
font-size: 0.86em;
color: #35a;

359
vim.md
View File

@ -1,8 +1,240 @@
---
title: vim
title: Vim
category: Vim
layout: 2017/sheet
---
Getting started
---------------
{: .-three-column}
### Navigating
| Shortcut | Description |
| --- | --- |
| `h` `j` `k` `l` | Arrow keys |
| `^u` _/_ `^d` | Page up/page down |
| --- | --- |
| `b` _/_ `w` | Previous/next word |
| `e` _/_ `ge` | Previous/next end of word |
| --- | --- |
| `0` _(zero)_ | Start of line |
| `^` | Start of line _(after whitespace)_ |
| --- | --- |
| `$` | End of line |
| `gg` | First line |
| `G` | Last line |
{: .-shortcuts}
### Entering insert mode
| Shortcut | Description |
| --- | --- |
| `a` | Append |
| `i` | Insert |
| `o` | Next line |
| `O` | Previous line |
| --- | --- |
| `s` | Delete char and insert |
| `S` | Delete line and insert |
| `C` | Delete until end of line and insert |
| --- | --- |
| `R` | Replace |
{: .-shortcuts}
### Exiting insert mode
| Shortcut | Description |
| --- | --- |
| `Esc` _/_ `^[` | Exit insert mode |
| `^c` | Exit insert mode, and abort current command |
{: .-shortcuts}
### Clipboard
| Shortcut | Description |
| --- | --- |
| `x` | Delete character |
| --- | --- |
| `dd` | Delete line _(Cut)_ |
| `yy` | Yank line _(Copy)_ |
| --- | --- |
| `p` | Paste |
| `P` | Paste before |
{: .-shortcuts}
### Visual mode
| Shortcut | Description |
| --- | --- |
| `v` | Enter visual mode |
| `V` | Enter visual line mode |
| `^v` | Enter visual block mode |
| --- | --- |
| `d` _/_ `x` | Delete selection |
| `s` | Replace selection |
| `y` | Yank selection _(Copy)_ |
{: .-shortcuts}
Text objects
------------
### Usage
| Shortcut | Description |
| --- | --- |
| `vip` | Select paragraph |
| `vipipipip` | Select more |
| --- | --- |
| `yip` | Yank inner paragraph |
| `yap` | Yank paragraph (including newline) |
| --- | --- |
| `dip` | Delete inner paragraph |
{: .-shortcuts}
### Text objects
| Shortcut | Description |
| --- | --- |
| `ap` | a paragraph |
| `ip` | inner paragraph |
| --- | --- |
| `ap` `ip` | Paragraph |
| `aw` `iw` | Word |
| `as` `is` | Sentence |
| --- | --- |
| `a[` `a(` `a{` `a<` | A [], (), or {} block |
| `a'` `a"` <code>a`</code> | A quoted string |
| --- | --- |
| `ab` | A block [( |
| `aB` | A block in [{ |
| `at` | A XML tag block |
{: .-shortcuts}
### Navigation
| Shortcut | Description |
| --- | --- |
| `[(` `[{` `[<` | previous `(` or `{` or `<` |
| `])` | next |
| --- | --- |
| `[m` | previous method start |
| `[M` | previous method end |
{: .-shortcuts}
Misc
----
### Folds
| Shortcut | Description |
| --- | --- |
| `zo` _/_ `zO` | Open |
| `zc` _/_ `zC` | Close |
| `za` _/_ `zA` | Toggle |
| --- | --- |
| `zv` | Open folds for this line |
| --- | --- |
| `zM` | Close all |
| `zR` | Open all |
| --- | --- |
| `zm` | Fold more _(foldlevel += 1)_ |
| `zr` | Fold less _(foldlevel -= 1)_ |
| --- | --- |
| `zx` | Update folds |
{: .-shortcuts}
Uppercase ones are recursive (eg, `zO` is open recursively).
### Jumping
| Shortcut | Description |
| --- | --- |
| `^O` | Go back to previous location |
| `^I` | Go forward |
| --- | --- |
| `gf` | go to file in cursor |
{: .-shortcuts}
### Counters
| `^A` | increment number |
| `^X` | decrement |
### Windows
| `z{height}<Cr>` | Resize pane to `{height}` lines tall |
### Tags
| Shortcut | Description |
| --- | --- |
| `:tag Classname` | Jump to first definition of Classname |
| --- | --- |
| `^]` | Jump to definition |
| `g]` | See all definitions |
| `^t` | Go back to last tag |
| `^o ^i` | Back/forward |
| --- | --- |
| `:tselect Classname` | Find definitions of Classname |
| `:tjump Classname` | Find definitions of Classname (auto-select 1st) |
{: .-shortcuts}
### Case
| Shortcut | Description |
| --- | --- |
| `~` | toggle case (Case => cASE) |
| `gU` | uppercase |
| `gu` | lowercase |
| --- | --- |
| `gUU` | uppercase current line (also `gUgU`) |
| `guu` | lowercase current line (also `gugu`) |
{: .-shortcuts}
Do these in visual mode.
### Marks
| <code>`^</code> | Last position of cursor in insert mode |
| <code>`.</code> | Last change |
| <code>``</code> | Last jump |
### Misc
| Shortcut | Description |
| --- | --- |
| `.` | repeat last command |
| `]p` | paste under the current indentation level |
| --- | --- |
| `zz` | Center this line |
### Command line
| Shortcut | Description |
| --- | --- |
| `<C-r><C-w>` | insert current word into the command line |
| `<C-r>"` | paste from " register |
### Text alignment
:center [width]
:right [width]
:left
See `:help formatting`
### Calculator
<C-r>=128/2
Do this in insert mode.
Also see
--------
{: .-one-column}
* [Digraphs](vim-digraphs.html)
* [Help text](vim-help.html)
* [Vimscript](vimscript.html)
@ -10,128 +242,3 @@ category: Vim
* [Vim-easyalign](vim-easyalign.html)
* [Vim-rails](vim-rails.html)
Command line
------------
<C-r><C-w> # insert current word into the command line
<C-r>" # paste from " register
Text objects
------------
vip # Select paragraph
vipipipip # Select more
ap # a paragraph
ip # inner paragraph
ap, ip # Paragraph
aw, iw # Word
as, is # Sentence
ab # A block [(
aB # A block in [{
at # A XML tag block
a[ ( { < # A [], (), or {} block
a' " ` # A quoted string
[( [{ [< # previous ( or { or <
]) # next
[m # previous method start
[M # previous method end
Example:
yip # Yank inner paragraph
yap # Yank paragraph (including newline)
Folds
-----
zo # Open
zO # Open, recursive
zc # Close
zC # Close, recursive
za # Toggle
zA # Toggle, recursive
zv # Open folds for this line
zM # Close all
zR # Open all
zm # Fold more (foldlevel += 1)
zr # Fold less (foldlevel -= 1)
zx # Update
Jumping
-------
^O # Go back to previous location
^I # Go forward
gf # go to file in cursor
Misc
----
. # repeat last command
]p # paste under the current indentation level
zz # Center this line
Counters
--------
^A # increment number
^X # decrement
Windows
-------
z{height}<Cr> # Resize pane to {height} lines tall
Tags
----
:tag Classname # Jump to first definition of Classname
^] # Jump to definition
g] # See all definitions
C-t # Go back to last tag
^O ^I # Back/forward
:tselect Classname # Find definitions of Classname
:tjump Classname # Find definitions of Classname (auto-select 1st)
Case
----
~ # toggle case (Case => cASE)
gU # uppercase
gu # lowercase
gUU # uppercase current line (also gUgU)
guu # lowercase current line (also gugu)
Marks
-----
`^ # Last position of cursor in insert mode
`. # Last change
`` # Last jump
Text alignment
--------------
See `:help formatting`
:center [width]
:right [width]
:left
### Calculator
(Insert mode) <C-r>=128/2