VIM Flashcards

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
Q

delete 2 WORDS

A

d2W

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

delete 3 lines downwards

A

d3j

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

delete everything in the current line until the ‘ character, including the ‘ character

A

df’

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

delete everything in the current line until the ( character, excluding the ( character

A

dt(

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

delete everything until the first occurrence of hello (excluding hello)

A

d/hello

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

delete the entire contents of a document

A

ggdG

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

c

A

Change

deletes a piece of text and then sends you into insert mode. Like d and i combined

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

switch case

A

g~

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

make something lowercase

A

gu

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

make something uppercase

A

gU

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

shift right (add indentation)

A

>

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

shift left (remove indentation)

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

format code

A

=

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

copy a whole document

A

ggyG

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

capitalise a world

A

gUw

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

change whole line

A

cc

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

delete to the end of the line

A

D

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

change to the end of the line

A

C

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

paste before the cursor

A

P

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

VIM: What is a document composed of?

A

Of text objects:

  • words
  • sentences
  • quoted text
  • paragraphs
  • blocks
  • (HTML) tags
How well did you know this?
1
Not at all
2
3
4
5
Perfectly
45
Q

Vim: Text object

A

Structured piece of text, or entity of a document domain model:

  • word
  • sentence
  • quoted text
  • paragraph
  • block
  • (HTML) tag
46
Q

Vim: How to specify a text object?

A

{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
Q

Vim: characters representing text objects

A
  • w
  • s: sentence
  • ’, “, `
  • p: paragraph
  • b, (, or ): block surrounded by ()
  • B, {, or }
  • [, ]
  • t
48
Q

Delete a word plus trailing whitespace

A

daw

49
Q

Change inner word

A

ciw

50
Q

Delete a sentence

A

das

51
Q

Delete inner sentence

A

dis

52
Q

Delete all in double quotes, including the quotes

A

da”

53
Q

Change inside double quotes

A

ci”

54
Q

Delete a block surrounded by (), including ()

A

dab
da(
da)

55
Q

Delete a block surrounded by {}, including {}

A

daB
da{
da}

56
Q

Change the contents of an HTML tag

A

cit

57
Q

Delete the character before the cursor

A

X = dh

58
Q

Delete the character under the cursor and enter insert mode

A

s = ch

59
Q

Switch case of a single character

A

~

60
Q

Repeat the last change

A

.

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
Q

Delete all occurrences of “cucamber”

A
/cucamber
daw -> delete the first occurrence
n -> go to the next occurrence
. -> delete it
and so on...
62
Q

Go back to the insert mode at the last place you left insert mode?

A

gi

63
Q

Delete the last character you typed

A

ctrl + h

64
Q

Delete the last word you typed

A

ctrl + w

65
Q

Delete the last line you typed

A

ctrl + u

66
Q

Exit insert mode

A

esc, ctrl + [, ctrl + c

67
Q

Select text using rectangular blocks

A

C-V

visual mode block-wise

68
Q

gn GN

A

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
Q

Paste and put the cursor after the pasted section.

A

gp

gP

70
Q

Swap lines

A

ddp

71
Q

Emulate mouse hover

A

gh

72
Q

Copy within parenthesis

A

yi(

73
Q

The Unnamed register

A

The default register where your copy and cut stuff goes to when you don’t explicitly set a register.

74
Q

The Named registers

A

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
Q

The yank register

A

0 (zero)

The last thing you copied. Deletes and changes don’t overwrite this register, like they do the unnamed register.

76
Q

The cut registers

A

1-9

The last nine things you cut using d or c.

77
Q

Yank a sentence and store it in “a” register

A

“ayas

78
Q

Paste the contents of “a” register

A

“ap

79
Q

See what’s in your registers

A

:reg

80
Q

See what’s in a specific register

A

:reg {reqister}

81
Q

Append to name register

A

“{uppercased register” {y | d | c} {motion}

“Ayw - append word to register a
“Byy - append line to register b

82
Q

Create a file in Vim

A

:edit {relative-path-to-file}

:e {relative-path-to-file}

83
Q

Save a file in Vim

A

:write
:w

Even if it’s been saved already or is read-only
:write!
:w!

84
Q

Quit a file in Vim

A

:q
:quit

Even without saving it
:q!
:quit!

85
Q

Save and close a file

A

:wq

86
Q

Save and close all files

A

:wqa

:wqall

87
Q

Save all files

A

:wa
:wall

Even if saved already or read only:
:wa!
:wall!

88
Q

Quit all files

A

:qa
:qall

Even if not saved
:qa!
:qall!

89
Q

Text-editing EX commands scheme

A

:[range] command[options]

e.g., delete lines 10, 11, 12, and put them in the “a” register
:10,12d a

90
Q

EX commands extremes of ranges

A

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
Q

When to use EX commands

A

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
Q

Repeating EX commands

A

Type :@ and you’ll repeat the last command.

From then on you can repeat it again with @@.

93
Q

Substituting text scheme

A

:[range]s/{pattern}/{substitute}/{flags}

94
Q

Transmute the first occurrence of lead in the current line with gold

A

:s/led/gold

95
Q

Transmute all occurrences of lead in the current line with gold

A

:s/led/gold/g

96
Q

Transmute all occurrences of lead lead with gold in whole file

A

:%s/led/gold/g

97
Q

Flags for substituting text commands

A

g - all occurrences
i - case-insensitive search
c - confirm each and every substitution

98
Q

Open a file in a new horizontal split

A

:sp {relative-path-to-file}

ctrl-w S -> ctrl-p

99
Q

Open a file in a new vertical split

A

:spv {relative-path-to-file}

chtl-w V -> ctrl p

100
Q

Move between splits

A

ctrl-w + hkjl

101
Q

Open a file in new tab

A

:tabnew {file}

102
Q

Go to the next tab

A

:tabn/:tabnext

103
Q

Go to the previous tab

A

:tabp/:tabprevious

104
Q

Close all other tabs

A

:tabo/:tabonly

105
Q

Splits vs. Tabs

A

Vim works with splits of tabs.

VSC works with tabs of splits

106
Q

Surround operator

A

Can be seen as 3 separate operators:

ds
cs
ys - add suroundings

ds{count}{motion}

107
Q

Delete the surrounding ‘

A

ds’

108
Q

Change the surrounding from ‘ to “

A

cs’”

109
Q

Surround a paragraph with a li tag

A

ysaptli>

110
Q

Surround selected text in visual mode

A

S{desired character}