vim commands Flashcards

1
Q

How do you open another file while you are in vim

A

Enter command mode and type:e filenameYou can also use :e to reload the file that you have currently opened. Typically this is used to discard the edits and start over from the previous saved file

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

How do you save a file?

A

Enter command mode and pressing :w If you like to save and quit press :wq

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

How do you exit vim

A

Enter command mode and press :q if you edited the file and you like to dicard the edits and exit vim without saving press :q!

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

Save the contents in vim as a different file

A

Enter command mode and :w newfilename

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

Repeats the last change made in normal mode

A

Enter comamnd mode and type .

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

Repeat 5 times the last change made in normal mode

A

Enter command mode and type 5.

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

move the cursor to the end of the word or beginning of word

A

e - endb - beginning

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

move the cursor to the beginning/end of the line

A

0 beginning of line$ end of line

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

move the cursor to the end/start of the file

A

In command modeG - endgg - first line

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

move the cursor to the bottom of the screen

A

L

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

move cursor to line 59. Replace 59 by the desired line number.

A

:59 to go to line 59

to configure vim to
show line numbers
:set nu

to not show line numbers
:set nonu

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

Copy commands

A

Enter escape modePress
y to copy the selected text to clipboard
press yy to copy the current line press
5yy to copy 5 lines
press y$ to copy from cursor to end of line
press y^ to copy from start of line to cursor

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

Paste clipboard contents

A

Enter command mode and press p

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

Delete or cut

A

Enter escape mode and press dd to Cut current lineD cut from cursor to end of line

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

Search fred or joe

A

/fred|joe

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

Replace all occurrences of old by new in file

A

enter escape mode and :%s/old/new/g
:%s/onward/forward/gi for case insensitive
:%s/old/new/gc replace all occurrances with confirmation

17
Q

Replace the beginning of each line by hello

Replace the end of each line by Harry

A

:%s/^/hello/g

:%s/$/Harry/g

18
Q

Delete all lines containing string

Delete all lines containing which didn’t contain string

A

:g/string/d

:v/string/d Delete all lines containing which didn’t contain string

19
Q

Replace Bill by Steve in current line

Replace Bill by Steve in all the file

A

:s/Bill/Steve/g

:%s/Bill/Steve/g

20
Q

:%s/^M//g

A

Delete DOS carriage returns (^M)

21
Q

Vu

A

Lowercase line

22
Q

VU

A

Uppercase line

23
Q

ggguG

A

Set all text to lowercase

24
Q

gggUG

A

Set all text to uppercase

25
:!pwd
Execute the pwd unix command then returns to Vi
26
Temporary returns to Unix and return back to vi
:sh return to shellexit to return back to vi
27
:5,$s/old/new/g
Replace all occurrences from line 5 to EOF
28
search commands
/word Search word from top to bottom /\cword top to bottom case insensitive ?word Search word from bottom to top ?\cword bottom to top case in sensitive
29
How to configure vim to show line numbers each time it starts
Edit the file ~/.vimrc and add a line set -o vi save the file. After that each time you run vim it will show line numbers