Vi is a screen-oriented text editor originally created for the Unix operating system. It remains one of the most widely used text editors on Unix-like systems, including Linux. Vi is known for its efficiency and powerful command set, making it a favorite among system administrators and developers.
To start Vi, simply type vi
followed by the name of the file you want to edit:
vi filename
Vi operates in several modes, the most important being:
i
: Switch to insert mode.Esc
: Return to normal mode.:w
: Save the file.:q
: Quit Vi.:wq
: Save and quit.:q!
: Quit without saving.dd
: Delete a line.yy
: Yank (copy) a line.p
: Paste the yanked or deleted text./pattern
: Search for a pattern.n
: Repeat the last search in the same direction.N
: Repeat the last search in the opposite direction.u
: Undo the last change.Ctrl-r
: Redo the undone change.Vi can be customized through the .vimrc
file (for Vim, a more advanced version of Vi). Here are some common customizations:
set number
syntax on
set tabstop=4
set shiftwidth=4
set expandtab
Vi provides powerful search and replace functionality:
/pattern
:%s/old/new/g
You can record and play back macros to automate repetitive tasks:
q<register>
q
@<register>
vimtutor
in the terminal..vimrc
file to set preferences and shortcuts.Vi is an essential tool for any Linux server administrator, offering powerful features and efficiency for text editing tasks.