Vi Editor Commands Flashcards

1
Q

What are various types of modes in vi editor?

A
  1. Command 2. Insert 3. Ex
How well did you know this?
1
Not at all
2
3
4
5
Perfectly
2
Q

What is the default vi editor mode on startup?

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

How to open a new file or open and existing file in vi editor?

A

vi <filename></filename>

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

How to quit from vi editor?

A

Enter command mode by pressing “Esc” and then type
q! - quit without saving
wq - quit after saving
w <filename> - save as functionality</filename>

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

How to denote a word in vi editor in command line?

A

‘c’ denotes- change textg
cw - change word
cc - change entire line
c$ - change from cursor positioin to end of line
c0 - change from cursor position to beginning of line
c3w -change the next 3 consecutive words

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

what does the command :%s/UNIX/Linux/gci do?

A

Command Breakdown
:: Enters command-line mode in vi.
%: Specifies the entire file as the range for the substitution.
s/UNIX/Linux/g: This is the substitution command.
s: Indicates substitution.
/UNIX/Linux/: Specifies the search pattern (UNIX) and the replacement string (Linux).
g: Global flag; replaces all occurrences on each line. Without g, only the first occurrence per line is replaced.
c: Confirm each substitution.
i: Ignore case while searching.

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

How to copy in vi editor?

A

The y command is used to yank (copy) text into the buffer.
yw - yanks a word
y$ - yanks till end of line
y0 - yanks from current position to beginning of line
yy - yanks entire line (alias Y)
3yy- yanks 3 consecutive lines

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

how to paste copied / deleted words/lines?

A

‘p’ command is used to paste text that has been deleted or yanked (copied) from the buffer

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

how to delete a line in vi editor?

A

‘dd’ deletes a line
8dd deletes 8 consecutive lines

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

How to see the difference between two files (usually one is updated version of other)?

A

diff <filename1> <filename2></filename2></filename1>

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

how to search in vi editor?

A

Enter command mode by pressing “Esc” then type
/<search> - searches in forward direction - press 'n' to continue search in forward direction , N to continue searching in backward direction
?<search> - searches in backward direction - press 'n' to continue search in backward direction, N to continue searching in forward direction.</search></search>

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

How to set / undo line numbers in the text file?

A

Enter command mode by pressing “Esc” then type
:se nu - displays line numbers
:se nonu - hides liine numbers

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

How to set word wrap

A

set wm=2 will set the wrap margin to 2

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