Vi

Vi is a text editor that is available on most Linux systems. It is a powerful tool that can be used for editing various types of files, such as configuration files, scripts, and programming code. Vi is designed to be used in the command line interface and can be used to edit files quickly and efficiently.

One of the most important features of Vi is its ability to navigate quickly within a file. Here are some basic commands to get started:

  • To open a file in Vi, type “vi filename” in the command line.
  • Once the file is open, you can use the arrow keys to move the cursor around the file.
  • To enter insert mode, press “i”. This will allow you to start typing in the file.
  • To exit insert mode and return to command mode, press the “Esc” key.
  • To save the changes made to the file, type “:w” in command mode.
  • To exit Vi, type “:q” in command mode. If you have unsaved changes, Vi will prompt you to save the changes before exiting. To force quit without saving changes, type “:q!”.

Here are some more advanced commands that can be used in Vi:

  • To delete a character, move the cursor to the character and press the “x” key.
  • To delete a line, move the cursor to the line and type “dd”.
  • To copy a line, move the cursor to the line and type “yy”.
  • To paste a line, move the cursor to the line where you want to paste and type “p”.
  • To search for a word in the file, type “/word” in command mode. Vi will highlight the first instance of the word and you can navigate to the next instance by typing “n”.
  • To replace a word with another word, type “:s/oldword/newword/g” in command mode. This will replace all instances of “oldword” with “newword” in the file.
  • To move to the beginning of a line, type “0” in command mode.
  • To move to the end of a line, type “$” in command mode.
  • To move to the beginning of a word, type “b” in command mode.
  • To move to the end of a word, type “e” in command mode.
  • To move to the next occurrence of a character, type “f” followed by the character in command mode. For example, to move to the next occurrence of the letter “a”, type “fa”.
  • To move to the previous occurrence of a character, type “F” followed by the character in command mode. For example, to move to the previous occurrence of the letter “a”, type “Fa”.
  • To move to a specific line in the file, type the line number followed by “G” in command mode. For example, to move to line 10, type “10G”.
  • To move to the beginning of the file, type “gg” in command mode.
  • To move to the end of the file, type “G” in command mode.
  • To undo your last action, type “u” in command mode.
  • To redo your last action, type “Ctrl + r” in command mode.
  • To select text, move the cursor to the beginning of the text you want to select and type “v”. Move the cursor to the end of the text you want to select and type “y” to copy the selected text or “d” to delete the selected text.
  • To indent text, select the text you want to indent and type “>>” in command mode. To unindent text, select the text you want to unindent and type “<<” in command mode.
  • To replace a single character at the cursor position, type “r” followed by the replacement character in command mode. For example, to replace the current character with the letter “x”, type “rx”.
  • To replace a block of text with new text, select the block of text and type “c” followed by the new text in command mode. For example, to replace a word, select the word and type “cw” followed by the new word.
  • To search and replace text globally in the file, type “:s/search/replace/g” in command mode. This will replace all instances of “search” with “replace” in the file. To replace only the first instance of “search”, type “:s/search/replace/” instead.
  • To insert text before the cursor, type “i” in command mode. To insert text at the beginning of the line, type “I”.
  • To insert text after the cursor, type “a” in command mode. To insert text at the end of the line, type “A”.
  • To open a new line below the current line and enter insert mode, type “o” in command mode. To open a new line above the current line, type “O”.
  • To repeat the last command, type “.” in command mode.
  • To join two lines together, move the cursor to the end of the first line and type “J” in command mode.
  • To change the case of text, select the text and type “U” to make the text uppercase or “u” to make the text lowercase.
  • To repeat a command a specified number of times, type the number followed by the command. For example, to delete 3 lines, type “3dd” in command mode.

These are just a few examples of the many advanced Vi commands that you can use to edit files. With practice, you’ll become an “arctic master”

Leave a Comment

Your email address will not be published. Required fields are marked *

Scroll to Top