Skip to main content

Chapter 1 : Basics of Vi editor

 Notes by vishalk17 ( t.me/vishalk17 ) Devops 

=====================================================================

 

1.   Starting vi

Open a file with vi. Type: vi myfile.txt

2.   vi Modes

Command Mode

o   Command mode is the mode you are in when you start (default mode)

o   Command mode is the mode in which commands are given to move around in the file, to make changes, and to leave the file

o   Commands are case sensitive: j not the same as J

Insert (or Text) Mode

o   The mode in which text is created.

o   There is more than one way to get into insert mode but only one way to leave: return to command mode by pressing <Esc>

3.   Setting Basic Options in vi

Displaying Line Numbers

    From Command Mode
  
    :set nu    Display line numbers
  
    :set nonu  Hide line numbers
 
 
 

4.   Basic commands

To repeat and undo:

Commands

Action

u

Undo the last command

.

Repeat the last command

Command to cut, copy and paste:

Commands

Action

dd

Delete a line

yy

(yank yank) copy a line

p

Paste after the current line

P

Paste before the current line

Command to cut, copy and paste in blocks:

Commands

Action

<n>dd

Delete the specified n number of lines

<n>yy

Copy the specified n number of lines

Search a string:

Commands

Action

/string

Forward search for given string

?string

Backward search for given string

 

To move to the start or end of the file:

  • :1 - Moves the cursor to the start of the page.
  • :$ - Moves the cursor to the end of the page.

5.   Exiting vi

o   To exit you must be in command mode-press <Esc> if you are not in command mode

o   exit vi by typing: :x

From Command Mode

 

    ZZ     Write/save then quit

 

    :wq    Write/save then quit

 

    :x   Write/save then quit

 

    :q!    Quit without saving changes to file

 

6.   Basics Summary 

  A Basic vi Session

o   To enter vi, type: vi filename <Return>

o   To enter insert mode, type: i

o   Type in the text: This is easy.

o   To leave insert mode and return to command mode, press: <Esc>

o   In command mode, save changes and exit vi by typing: :x

You are back at the Unix prompt.

 

Comments

Popular posts from this blog

 Notes by vishalk17 ( t.me/vishalk17 ) Devops    Chapter 3 : Linking/archieve/add-remove-users/disk space/size of file ===================================================================== groupadd command in Linux with examples           Groups  in Linux refer to the user groups. In Linux, there can be many users of a single system. In a scenario where there are many users, there might be some privileges that some users have and some don’t, and it becomes difficult to manage all the permissions at the individual user level. So using groups, we can group together a number of users, and set privileges and permissions for the entire group. groupadd command is used to create a new user group.      We can use either usermod or gpasswd command to add user to group in Linux operating system. And both commands are very easy to use.   Syntax groupadd [option] group_name            Every new group created is registered in the file “/etc/group“. To verify that the group has b

Chapter 2 : Linking/archieve/add-remove-users/disk space/size of file

Notes by vishalk17 ( t.me/vishalk17 ) Devops    Chapter 2 : Linking/archieve/add-remove-users/disk space/size of file ===================================================================== Linking:   Soft Links vs Hard Links The  ln  command can be used to create two different kinds of links: Soft links (for files / directories) Hard links (only for files) Soft (Symbolic) Links (for files /directories) A soft link, sometimes called a symbolic link or  symlink , points to the location or  path  of the original file. It works like a hyperlink on the internet. Here are a few important aspects of a soft link: If the original file is moved or deleted, the symbolic link won’t work. A soft link can refer to a file on a different file system. Soft links are often used to quickly access a frequently-used file without typing the whole location. A soft link is something like a shortcut in Windows. How to Use the ln Command  By default, the ln command cre