Linux commands + shell scripts: vim basics

Recommended free tutorials: Python, C++, Java, JS, Rust, Go Language Introduction Complete Manual (6 in 1).zip-Python Documentation Resources-CSDN Download

The vim editor processes data in memory buffers. Just type the vim command (or vi, if the alias or link file
exists) and the name of the file to edit to start the vim editor:
$ vim myprog.c
If no file name was specified when starting vim, or the file is not exists, vim will open up a new buffer area for editing.
If you specify the name of an existing file on the command line, vim will read the entire content of the file into a buffer area for editing
, as shown in Figure 10-1.

The vim editor will detect the type of session terminal (see Chapter 2), and use the full-screen mode to use the entire console window as the editor
area.
The initial vim editing window shows the contents of the file (if any) and a message
line at the bottom of the window. If the file content does not occupy the entire screen, vim will place a wavy line on the non-file content line (as shown in Figure 10-1).
The message line at the bottom shows information about the edited file according to the state of the file and the default settings when vim was installed. If the
file is newly created, the message [New File] appears.
The vim editor has two modes of operation:
 Normal mode
 Insert mode
When you just open the file to be edited (or create a new file), the vim editor will enter the normal mode. In normal mode
, the vim editor interprets keystrokes as commands (more on this later in this chapter).
In insert mode, vim will insert every key you type at the current cursor position into the buffer. Press the i key to enter
insert mode. To exit insert mode and return to normal mode, press the escape key (ESC key, also known as Escape key) on the keyboard
.
In normal mode, you can use the arrow keys to move the cursor in the text area (as long as vim can correctly identify your terminal type). If
you happen to be on a wacky terminal connection with no arrow keys defined, it's not all hopeless.
There are commands for moving the cursor in vim .
 h : Move one character to the left.
 j : Move down one line (next line in text).
 k : Move up one line (previous line in text).
 l : Move one character to the right.
Moving back and forth line by line in a large text file can be particularly cumbersome. Fortunately, vim provides some
commands that can speed up the movement.
 PageDown (or Ctrl+F): Scroll down one screen.
 PageUp (or Ctrl+B): Turn up one screen.
 G ​​: Move to the last line of the buffer.
 num G : Move to line num in the buffer.
 gg : Move to the first line of the buffer.
The vim editor has a special function in normal mode called command line mode. The command line mode provides an interactive command
line where additional commands can be entered to control vim's behavior. To enter command line mode, press the colon key in normal mode. The cursor
will move to the message line, and then a colon will appear, waiting for a command to be entered.
There are several commands in command line mode to save the buffer's data to a file and exit vim.
 q : Exit if the buffer data has not been modified.
 q! : Cancel all modifications to buffer data and exit.
 w filename : Save the file to another file.
 wq : Save the buffer data to a file and exit.
After understanding these basic vim commands, you may understand why some people hate the vim editor. To unleash
the full power of vim, you must know a lot of obscure commands. But as long as you understand some basic vim commands,
you can quickly modify files directly on the command line no matter what the environment is. Once you get used to typing commands, entering data along with editing commands at the command line is
as natural as second nature, and going back to using the mouse feels weird. 

Recommended free tutorials: Python, C++, Java, JS, Rust, Go Language Introduction Complete Manual (6 in 1).zip-Python Documentation Resources-CSDN Download

Guess you like

Origin blog.csdn.net/tysonchiu/article/details/125963285