VIM Flashcards

(110 cards)

1
Q

VIM word vs WORD

A
word:
hello
,
.
[

WORD:
hello(){}
hello(2,3)
[1, 2, 3, 4]

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
2
Q

Jump to the end of a word backwards

A

ge - word

gE - WORD

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
3
Q

Move just before the character (until)

A

t/T{char}

! Delete everything before the “(“

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
4
Q

Repeaters

A

;/, - f & t

n/N - / and ?

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
5
Q

Go to the first character of the line

A

0 (zero)

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
6
Q

Go to the first non-blank character of the line

A
How well did you know this?
1
Not at all
2
3
4
5
Perfectly
7
Q

Go to the end of the line

A

$

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
8
Q

Go to the last non-blank character of the line

A

g_

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
9
Q

Jump the entire paragraph downwards

A

}

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
10
Q

Jump the entire paragraph upwards

A

{

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
11
Q

Move down half a page by scrolling page

A

CTRL-D

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
12
Q

Move up half a page by scrolling page

A

CTRL-U

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
13
Q

Search backwards

A

?

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
14
Q

Repeat the last search

A

/[enter] or ?[enter]

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
15
Q

Search the word under your cursor

A
* - forward
# - backwards
How well did you know this?
1
Not at all
2
3
4
5
Perfectly
16
Q

Go to definition of the thing under the cursor

A

gd

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
17
Q

Go to a file in import

A

gf

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
18
Q

Go to the top of a file

A

gg

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
19
Q

Go to the end of a file

A

G

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
20
Q

Jump to maching ({[]})

A

%

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
21
Q

Operator

A

An action to preform (Delete, Put, Change, Yank…)

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
22
Q

Count

A

A multiplier to perform action X times

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
23
Q

Motion

A

The piece of text to which to apply the action defined by the operator (word, WORD, line…)

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
24
Q

Combining operators and motions

A

{operator}{count}{motion}

{motion}{count}{operator}

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
25
delete 2 WORDS
d2W
26
delete 3 lines downwards
d3j
27
delete everything in the current line until the ' character, including the ' character
df'
28
delete everything in the current line until the ( character, excluding the ( character
dt(
29
delete everything until the first occurrence of hello (excluding hello)
d/hello
30
delete the entire contents of a document
ggdG
31
c
Change deletes a piece of text and then sends you into insert mode. Like d and i combined
32
switch case
g~
33
make something lowercase
gu
34
make something uppercase
gU
35
shift right (add indentation)
>
36
shift left (remove indentation)
37
format code
=
38
copy a whole document
ggyG
39
capitalise a world
gUw
40
change whole line
cc
41
delete to the end of the line
D
42
change to the end of the line
C
43
paste before the cursor
P
44
VIM: What is a document composed of?
Of text objects: - words - sentences - quoted text - paragraphs - blocks - (HTML) tags
45
Vim: Text object
Structured piece of text, or entity of a document domain model: - word - sentence - quoted text - paragraph - block - (HTML) tag
46
Vim: How to specify a text object?
{a | i}{text-object-id} a - all of the text object, including whitespace i - inner object, without whitespace text-object-id - a character representing text object.
47
Vim: characters representing text objects
- w - s: sentence - ', ", ` - p: paragraph - b, (, or ): block surrounded by () - B, {, or } - - [, ] - t
48
Delete a word plus trailing whitespace
daw
49
Change inner word
ciw
50
Delete a sentence
das
51
Delete inner sentence
dis
52
Delete all in double quotes, including the quotes
da"
53
Change inside double quotes
ci"
54
Delete a block surrounded by (), including ()
dab da( da)
55
Delete a block surrounded by {}, including {}
daB da{ da}
56
Change the contents of an HTML tag
cit
57
Delete the character before the cursor
X = dh
58
Delete the character under the cursor and enter insert mode
s = ch
59
Switch case of a single character
~
60
Repeat the last change
. Text objects are more reliable than other motions because you don't need to care as much about the position of the cursor. The commands with text objects are far more repeatable and work beautifully in tandem with the "." command. The "." command works great with repeaters: ;,nN
61
Delete all occurrences of "cucamber"
``` /cucamber daw -> delete the first occurrence n -> go to the next occurrence . -> delete it and so on... ```
62
Go back to the insert mode at the last place you left insert mode?
gi
63
Delete the last character you typed
ctrl + h
64
Delete the last word you typed
ctrl + w
65
Delete the last line you typed
ctrl + u
66
Exit insert mode
esc, ctrl + [, ctrl + c
67
Select text using rectangular blocks
C-V visual mode block-wise
68
gn GN
supercharged n N: 1. on top of a search match, it selects the match in visual mode 2. in visual mode, it extends your current selection until the end of the next match 3. in operator-pending mode, it operates on the next match === dgn means apply this change (delete) to the match, so you can use just . instead of n .
69
Paste and put the cursor after the pasted section.
gp | gP
70
Swap lines
ddp
71
Emulate mouse hover
gh
72
Copy within parenthesis
yi(
73
The Unnamed register
" The default register where your copy and cut stuff goes to when you don't explicitly set a register.
74
The Named registers
a-z Can be used to explicitly copy and cut stuff at will. "{name of register}y{motion} "{name of register}d{motion} "{name of register}c{motion}
75
The yank register
0 (zero) The last thing you copied. Deletes and changes don't overwrite this register, like they do the unnamed register.
76
The cut registers
1-9 The last nine things you cut using d or c.
77
Yank a sentence and store it in "a" register
"ayas
78
Paste the contents of "a" register
"ap
79
See what's in your registers
:reg
80
See what's in a specific register
:reg {reqister}
81
Append to name register
"{uppercased register" {y | d | c} {motion} "Ayw - append word to register a "Byy - append line to register b
82
Create a file in Vim
:edit {relative-path-to-file} | :e {relative-path-to-file}
83
Save a file in Vim
:write :w Even if it's been saved already or is read-only :write! :w!
84
Quit a file in Vim
:q :quit Even without saving it :q! :quit!
85
Save and close a file
:wq
86
Save and close all files
:wqa | :wqall
87
Save all files
:wa :wall Even if saved already or read only: :wa! :wall!
88
Quit all files
:qa :qall Even if not saved :qa! :qall!
89
Text-editing EX commands scheme
:[range] command[options] e.g., delete lines 10, 11, 12, and put them in the "a" register :10,12d a
90
EX commands extremes of ranges
Can be expressed using: - offsets :10,+2 - current line :.,+2 - the whole file :% - the beginning of file :0,+2 - the end of file :10,$ - current visual mode text selection :'
91
When to use EX commands
Useful because they allow you to apply a command over a range of lines without needing to move the cursor to that location first. Whenever you need to apply changes over multiple lines, consider using ex commands.
92
Repeating EX commands
Type :@ and you'll repeat the last command. From then on you can repeat it again with @@.
93
Substituting text scheme
:[range]s/{pattern}/{substitute}/{flags}
94
Transmute the first occurrence of lead in the current line with gold
:s/led/gold
95
Transmute all occurrences of lead in the current line with gold
:s/led/gold/g
96
Transmute all occurrences of lead lead with gold in whole file
:%s/led/gold/g
97
Flags for substituting text commands
g - all occurrences i - case-insensitive search c - confirm each and every substitution
98
Open a file in a new horizontal split
:sp {relative-path-to-file} ctrl-w S -> ctrl-p
99
Open a file in a new vertical split
:spv {relative-path-to-file} chtl-w V -> ctrl p
100
Move between splits
ctrl-w + hkjl
101
Open a file in new tab
:tabnew {file}
102
Go to the next tab
:tabn/:tabnext
103
Go to the previous tab
:tabp/:tabprevious
104
Close all other tabs
:tabo/:tabonly
105
Splits vs. Tabs
Vim works with splits of tabs. VSC works with tabs of splits
106
Surround operator
Can be seen as 3 separate operators: ds cs ys - add suroundings ds{count}{motion}
107
Delete the surrounding '
ds'
108
Change the surrounding from ' to "
cs'"
109
Surround a paragraph with a li tag
ysaptli>
110
Surround selected text in visual mode
S{desired character}