Master vi/vim editor for Creating and editing text files from the command line in deatail

Опубликовано: 22 Октябрь 2024
на канале: techessay
46
0

Objectives
Create and edit text files from the command line with the vim editor. vi and vim / VISUAL EDITOR
Edit Files with Vim
The fundamental design principle of Linux is that it supports storage of the information and configuration settings in text-based files. These files follow various structures such as lists of settings, INI-like formats, structured XML or YAML, and others. The advantage of storing files in a text-based structure is that they are edited with any text editor.
Vim is an improved version of the vi editor, which is distributed with Linux and UNIX systems. Vim is a highly configurable and efficient editor that provides split-screen editing, color formatting, and highlighting for editing text.
Benefits of the Vim Editor
When a system uses a text-only shell prompt, you should know how to use at least one text editor for editing files. You can then edit text-based configuration files from a terminal window or remote logins through the ssh command or the Web Console. You also do not need access to a graphical desktop to edit files on a server, and that server might not need to run a graphical desktop environment.
The key reason to learn Vim is that it is almost always installed by default on a server for editing text-based files. The Portable Operating System Interface or POSIX standard specified the vi editor on Linux, and many other UNIX-like operating systems largely do likewise.
Vim is also used often as the vi implementation on other standard operating systems or distributions. For example, macOS currently includes a lightweight installation of Vim by default. So, Vim skills that are learned for Linux might also prove useful elsewhere.
Get Started with Vim

#vim filename
#vi filename


VIM support three/four operating mode-
1. Normal / Command line mode
2. Extended Command line mode
3. Visual line /Visual Block mode
4. Edit /Insert MOde
Advance mode

/etc/vimrc
~/.vimrc



1. Normal / Command line mode-

Available commands-
press ecs escape key to make sure you are in command MODE
press
i - for going into insert mode
yy- for copy copmlete line
p- paste the copied data
5p - paste copied data 5 times
45-
3p-
dd- delete a line
x- for deleting a charcter of cursor
dw- deleting a word on which cursor is present
u- for undo the last changes
cw- changing the current currsor word
d$- for deleting the line from current cursor postion to end of line
o/O - for opeing a new line and going into the insert mode
A/a= for going inti the append mode
: for going into the Extended command mode
shift+v - for going into the visual mode

2. Extended Command line mode-
ecs /escape to make sure you are in normal mode
: - to go into the extended command mode
:write/w - writing
:w /anylocationofnew file
:wq It will write and quit / save and exit
:q just quit without saving any thing
:q! Quite by discarding all changes
:set nu - for setting number before line

:set all -- explore all supported set command


Edit mode-
ctrl+shift+c for copying selected data
ctrl+shift+v for pasting the copied data