10-17-2020

https://youtu.be/QP7LE9LPMeM

 

 

VI Editor

 

Vi is a text editor originally created with UNIX, widely used for editing configuration files

 

 

[root@localhost ~]# vi file1

-          It opens the editor with specified file name

-          If the file does not exits it will create one

-          You will vi eidtor in command mode

-          Push ‘i’ to enter the insert mode

-          Push ‘esc’ to get out of the edit mode

-          Once you have edited or put some text in the file

-          Shift + :x will save and exit

-           

[root@localhost ~]# cat file1

 

 

 

 vi commands

 

 

:

This is ready for commands

:x

Save and exit

:q

Quit – if you have not made changes

:q!

Quit – without saving even if you made changes

i

Insert mode

l

Moves cursor one character to left

h

Moves cursor one character to right

K

Moves cursor one line up

J

Moves cursor one line down

o

Opens the new line in insert mode below the cursor

yy

Copies the line

-          3yy or 2yy copies that many lines

-          You got the idea

‘u’

Undo

‘dd’

This works as cut – you can paste else where

:/RHEL

Searches the pattern – cursor will jump to first instance

 

‘n’ to jump between results

:%s/linux/LINUX

Replaces the patter

:wq

Save and quit – official way

 

 

 

 

 

 

 

‘:e file1’

Loads the specified file for editing

-          You can also specifi absolute and relative path

 

‘:r’

Load the file content of the file again

:!

 

Allows you to run shell commands from within vi example: !ls /etc

i

insert text and not replace it

R

over write existing text when new text added

cw

remove current word cursor is on and insert into insert mode to add text

cc

replace the entire of line of text

l

moves cursor one character to the right

h

moves cursor one character to the left

j

moves cursor down one line

k

moves cursor up one line Yank – Term used to copy text. Use YY to “yank” a line of text.

yy

will yank/copy entire line the cursor is currently on

2yy

will copy the current line of text as well as the line underneath it (2lines)

3yy

will copy three lines, 4yy 4 lines of text 5yy…

p

will paste the contents from yanked yy text, starting on the line after your cursor

P

uppercase P will paste the yanked line(s) starting on the line before the cursor

5G

moves your cursor to line 5

5gg

moves your cursor to line 5 (note case sensitive)

G

Moves the cursor to the beginning of the last line in the file

1G

Moves the cursor to the first line of the file

L

Also moves the cursor to the beginning of the last line on the terminal screen

H

Moves the cursor to the first line on the terminal screen

o

opens insert mode to insert text, creates a new line below your current cursor position

u

undo

cc

Removes the entire line and places you into insert mode

/ - search, /root

will search the file for root you can navigate to the next occurrence using the n key

?

is the same as / as it relates to searching