-
Notifications
You must be signed in to change notification settings - Fork 0
/
vim-tips
97 lines (65 loc) · 2.93 KB
/
vim-tips
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
----- EDITING A FILE -----
gg=G : holy shit this properly indents the whole freaking file!! gg indeed
=i{ : smaller holy shit but this means 'fix indent' 'inside' '{'
q[any key] : start macro recording into a register (press q at the end again to end the recording)
@[that key]: replay the macro
. : replay last command like 'yit' or even something with insert
:%s/findThisWord/replaceWithThis/g : Find a word and replace all instances with 2nd word.
:%s/foo/bar/gc : Find and replace but ask for confirmation for each word.
gg dG : Delete all lines of a file
J : Move row below cursor to cursor's current row
Comment out lines:
- block lines with ctrl+v
- press I and insert comment signs (//)
- escape
Uncomment out lines:
- select commented lines with ctrl+v
- press d to delete
Format, in tag (think html tag)
= i t
Format in { }
= i {
Format in ( )
= i (
Delete 'around' { } so it takes the stuff inside and the curly braces
d a {
Delete 'around' tags (think <div></div>) so it deletes the whole element
d a t
Delete 'around' ( )
d a (
Can replace the d with y as well to yank
select a bunch of lines you want to sort alphabetically then type :sort
run normal mode on multiple lines: select a bunch of lines then type :normal A; (for example to append ; to the end of each line)
[CUSTOM vim-surround]
: Capital V (select some lines) then type S<div className="container"> TO SURROUND THAT WHOLE CHUNK WITH A TAG WOAH
: yss' - to wrap line with '
: dst - delete surrounding tag
: cst<div className="whatever"> - change surrounding tag to div with class "whatever"
----- NAVIGATING A PROJECT -----
ctrl-w gf : Open file under cursor in new tab
:qa : close all vim windows
:vimgrep /the-string-you're-looking-for/ **/*.js : search for the string in all files that match the regex
:cw : show the list of results from the search
gv : selects the last selected thing
[CUSTOM] move cursor anywhere on css class or ID and type :CSS to jump to css definition
----- NAVIGATING A FILE -----
zz : center the file on cursor
ctrl-d : move down half a screen
ctrl-u : move up half a screen
ctrl-e : move screen down by 1
ctrl-y : move screen up by 1
^ : move to the first none whitespace character of the line
]s : move to the next misspelled word
A : Move to the end of the line and into insert mode
I : Move to the start of a line and into insert mode
----- COPY AND PASTING -----
"0p : paste from yank register
Copy to system clipboard: "*y
Paste from system clipboard: "*p
Copy a line (or multiple lines) from anywhere in buffer to current cursor position - :142,145t.
Copy the whole file - :%w !pbcopy
Paste from clipboard - :r !pbpaste
----- OTHER -----
q<letter or number> : starts recording a macro at the given register
<how many times>@<letter or number> : exexcutes the recorded macro at the given register
@: (then afterwards you can use @@) : repeats the last ':' command