Network Security Internet Technology Development Database Servers Mobile Phone Android Software Apple Software Computer Software News IT Information

In addition to Weibo, there is also WeChat

Please pay attention

WeChat public account

Shulou

Example Analysis of practical basic Operation skills of VIM in CentOS

2025-02-24 Update From: SLTechnology News&Howtos shulou NAV: SLTechnology News&Howtos > Servers >

Share

Shulou(Shulou.com)06/01 Report--

This article mainly introduces the example analysis of practical basic operation skills of VIM in CentOS, which is very detailed and has certain reference value. Friends who are interested must finish it!

There are many text editors, such as gedit and kwrite in graphic mode, and vi, vim (an enhanced version of vi) and nano in text mode. Vi and vim are the most commonly used editors in Linux systems. Someone once said that there are three kinds of people in the world: one is using Vi, the other is using Emacs, and the rest are the third kind of people.

(1) Primary personalized configuration of your vim

1. What is vim?

Vim is Vi IMproved, an enhanced version of the editor Vi, an extremely powerful editor that conforms to the habits of IT engineers (programmers, operations and maintenance). If you are a professional SE, you must be looking for an excellent editor that can be freely customized and can be edited flexibly. So the answer is vim or Emacs.

2. Where is the configuration file?

The configuration file for the Windows system is the vimrc file in the vim installation directory.

For Linux systems, the configuration files for RHEL and CentOS are / etc/vimrc,Debian and the configuration files for Ubuntu are / usr/share/vim/vimrc.

The configuration file for Mac OS X is / usr/share/vim/vimrc.

3. What is the meaning of RC in vimRC?

Why list such a meaningless question? The reason is simple: at the beginning of my contact with vim, the second question I wanted to ask was this (the first is the "1" above). Generally speaking, at the beginning of running a software, environment, or tool, some commands to be executed initially are called Run Commands, or RC. According to Wikipedia.org, the use of RC abbreviations is derived from MIT's compatible time-sharing operating system (Compatible Time-Sharing System,CTSS) [Ref. 1]. So if you see SystemRC or ScreenRC in the future, you'll know why.

4. Three basic models

In "Let's learn vim", it is mentioned that there are six or five modes of vim, but apart from the different degrees of subdivision, there are actually only three commonly used modes: Normal Mode, Insert Mode and Command-line Mode.

To enter Insert Mode from Normal Mode, you can press I, I, a, A, o, O, r, R. Where I and I denote Insert and r and R denote replace.

To enter Normal Mode from Insert Mode, just press the ESC key.

To enter Command-line Mode from Normal Mode, press ":", "/", "?". Where ":" means to enter the vim command, "/" means to enter the string to search down later, "?" Indicates that the string to be searched up is entered later.

To enter Normal Mode from Command-line Mode, just press the ESC key.

You can think of Normal Mode as normal, you need some special way to enter any other mode, and to return to Normal Mode from another special mode, just press the ESC key.

5. The most commonly used configurations in vim

When you try to google some other people's vimrc configuration, you will certainly find an article called "The ultimate vim configuration", but its author, Amix, later mentioned on his blog [reference 2], this vim profile, which will be in the top 10 in google search vimrc, is now out of date, so he provided some updates.

(1) Color setting

Syntax on "turn on code highlight

Syntax off "turn off code highlight

Syntax enable "turn on code highlight

(2) search settings

Set hlsearch "turn on search highlight

Set nohlsearch "turn off search highlight

Set incsearch "search while entering a search string

Ignore case when searching for set ignorecase

(3) user interface

Set showmode "on mode display

Set ruler "turns on the cursor position prompt

Set number "displays the line number

Set nonu "does not display line number

"set cursorline" emphasizes the line of the cursor

The height of the "set cmdheight=1" command section is 1

(4) Editing the auxiliary configuration

Set autoindent "auto indent

Set noautoindent "does not indent automatically

Set smartindent "Smart indent

Set autoread "vim automatically updates and loads when the file is changed externally."

Set showmatch "displays matching parentheses

Reference:

[1] Run Commands, http://en.wikipedia.org/wiki/Run_commands

[2] The Ultimate vim Configuration (vimRC), http://amix.dk/blog/post/19486

(2) commonly used state switch buttons

1. Normal Mode-> Insert Mode

I lowercase I, insert at cursor position

A lowercase letter a, insert at the next position of the cursor

I uppercase I, insert at the first non-space on the line where the cursor is located

A uppercase letter A, insert at the last character of the line where the cursor is located

O lowercase o, insert a new line at the next line where the cursor is located

O uppercase O, insert Singapore Airlines on the previous line of the cursor

R lowercase letter r, replace the character where the cursor is located once

R capital letter R, continue to replace the character where the cursor is located until ESC is pressed

2. Normal Mode-> Command-line Mode

W save the file

: w! Force the file to be saved (provided the user has permission to modify file access)

Q exit buffer

: q! Force to exit the buffer without saving

Wq saves the file and exits the buffer

ZZ saves the file and exits

: wq! Force to save the file and exit the buffer (provided the user has permission to modify file access)

: W save as a file named filename

The data from line N1 to line N2 is saved as a file named filename

: X if there are any changes to the file, save and exit. Or just quit.

3. Insert Mode-> Normal Mode

Press the ESC key

4. Command-line-> Normal Mode

Press the ESC key

(3) commonly used cursor movement keys

1. Cursor character operation

J Down

K up

H to the left

L to the right

Move the cursor to the end of the line (End) and press the shift key

0 move the cursor to the beginning of the line (Home)

Move the ^ cursor to the first non-white space character (Home) at the beginning of the line, and press shift

2. Operation of beacons

W cursor moves to the beginning of the latter word

The W cursor moves to the beginning of the latter word and ignores punctuation.

E the cursor moves to the end of the latter word

The E cursor moves to the end of the latter word and ignores punctuation.

B move the cursor to the beginning of the previous word

B the cursor moves to the beginning of the previous word and ignores punctuation

3. Cursor sentence operation

) move the cursor to the beginning of the latter sentence

(the cursor moves to the beginning of the previous sentence

Use with "(" and ")" to find a matching partner.

4. Cursor line operation

The G cursor moves to the first non-white space character on the last line of the document

The nG cursor moves to the nth line of the document, which is equivalent to ": n"

The gg cursor moves to the first non-blank character on line 1 of the document, which is equivalent to "1G" and also equivalent to ": 1"

Move the cursor down N lines

5. Cursor segment operation

} move the cursor to the beginning of the next paragraph

{the cursor moves to the beginning of the previous paragraph

Use with "(" and ")" to find a matching partner.

6. Cursor page operation

Ctrl+f page down (Pagedown)

Ctrl+b page up (Pageup)

Ctrl+d turns down half a page

Ctrl+u turns up half a page

The H cursor moves to the first line of the currently displayed page

The M cursor moves to the middle line of the currently displayed page

The L cursor moves to the last line of the currently displayed page

7. Operate the cursor freely

Ctrl+o returns to the previous position of the cursor

(4) commonly used editing operation keys

1. Delete operation (delete)

Dd deletes the line of the cursor

Ndd delete the downward n-line starting from the line where the cursor is located

D1G deletes all lines from the line where the cursor is located to the first line

DG deletes all lines from the line where the cursor is located to the last line

D $removes all characters from the cursor position to the end of the line

D0 removes all characters from the cursor position to the beginning of the line

2. Copy operation (yank)

Yy copy the line of the cursor

Nyy copy starts at the line of the cursor and goes down on the n line

Y1G copies all lines from the line where the cursor is located to the first line

YG copies all lines from the line of the cursor to the last line

Y$ copies all the characters from the cursor position to the end of the line

Y0 copies all characters from the position of the cursor to the beginning of the line

3. Paste operation (paste)

P lowercase p, paste the data from the clipboard, starting on the next line of the cursor

P uppercase P, paste the data from the clipboard, starting with the previous line of the cursor

4. Undo and redo operations (undo,redo)

U (Undo) undoes the previous action

Ctrl+r (Redo) redoes the previous operation

5. Repeat operation

. Repeat the previous operation

6. Replace operation (replace)

R replace the character at the cursor

R enters replacement mode until you press ESC to exit

Cc replaces the line of the cursor

Cw replaces the English word where the cursor is located

~ convert case

7. Typesetting operation

Left alignment of the line where the le cursor is located

Align the line where the ri cursor is located to the right

The line of the ce cursor is centered

The above is all the contents of the article "sample Analysis of practical basic operating skills of VIM in CentOS". Thank you for reading! Hope to share the content to help you, more related knowledge, welcome to follow the industry information channel!

Welcome to subscribe "Shulou Technology Information " to get latest news, interesting things and hot topics in the IT industry, and controls the hottest and latest Internet news, technology news and IT industry trends.

Views: 0

*The comments in the above article only represent the author's personal views and do not represent the views and positions of this website. If you have more insights, please feel free to contribute and share.

Share To

Servers

Wechat

© 2024 shulou.com SLNews company. All rights reserved.

12
Report