m-chrzan.xyz
aboutsummaryrefslogtreecommitdiff
path: root/vim.md
blob: 2497e768d93220b1eb3b1158151dff1861dec60a (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
# Vim tricks

## vimgrep

Search through all files in a directory

    :vimgrep /pattern/ **/*

Open window with all instances:

    :copen

## Search

    \c - ignore case

## Settings

    ic - ignore case in searches

## readline

vi keybindings in various `readline` and similar CLIs:

    # ~/.inputrc
    set editing-mode vi

    # ~/.editrc
    bind -v

    # ~/.haskeline
    editMode: Vi

    # ~/.guile
    (use-modules (ice-9 readline))
    (activate-readline)

## Navigating help

| prefix | example       | context                                          |
| ------ | ------------- | ------------------------------------------------ |
| `:`    | `:h :r`       | ex command (command starting with a colon)       |
| `none` | `:h r`        | normal mode                                      |
| `v_`   | `:h v_r`      | visual mode                                      |
| `i_`   | `:h i_CTRL-W` | insert mode                                      |
| `c_`   | `:h c_CTRL-R` | ex command line                                  |
| `/`    | `:h /\r`      | search pattern (in this case, `:h \r` also works |
| `'`    | `:h 'ro'`     | option                                           |
| `-`    | `:h -r`       | Vim argument (starting Vim)                      |

## Registers

: is the "last command" register. @: reruns the last command.

## Marks

mA - capital letters are global, will jump to file
`a - jumps to line and column of mark, not just line

## v/V/<c-v> as operators

Most commands act line-wise (d2j deletes two lines). v makes things
character-wise, <c-v> makes them block-wise.

## Ranges

    g/regex/command # executes command on each line matching regex
    v/regex/command # executes command on each line not matching regex

## Ex commands

    :norm abc # runs the keys abc on each line in range
    :g/abc/norm dt; # deletes until semicolon on each line with "abc"

    :co <location> # copies range to location (can be ., +n, 'a)
    :mv <location> # same but moves

    :s/pattern/thing/c # replace, prompting at each replacement

## Visual mode

gv - selects the previous visual
g<c-a/x> - increment/decrement by 1 more on each selected line

    0          1            1
    0 <c-a> -> 1  g<c-a> -> 2
    0          1            3

## Using vim as a hex editor?

    :%!xxd
    :%!xxd -r

## Spellcheck

    :setlocal spell spelllang=en_us
    [/]s - previous/next marked word
    [/]S - previous/next bad word
    z=   - replacement suggestions

## Formatting

    gq

## Splits

* number before split shortcut - height of old window

Set window height/width (defaults to max):

    [n]^W _
    [n]^W |

Equalize window heights/widths:

    ^W =

Close window:

    ^W c

## Movements

    % - goes to matching bracket

## Time travel

    :earlier 5m
    :later 10m