This article is based on the Vi Editor, prepared by Lamb & Robbins. For PDF download, see
Summary:
Set settings
. Vimrc Configuration
Run linux commands in vim
Use linux commands to edit the current file
Abbreviation
This article stipulates:
$ + Command indicates that the command line in normal bash is
: + Command indicates that in vim's ex (command) mode, press "Ctrl" + ":" to enter
Set command
There are two types of options you can use: set command to modify: trigger options that are not on or off, and options with numbers or string values (such as the margin position and file name)
The command for triggering the option is set cmd.
The command to disable the option is: set nocmd
The above cmd indicates a Command Option
For example,
: Case Insensitive for set ic search (ic = ignore case)
: Set noic is case-insensitive during search
You can run the: set all command to view all the options. You can see the value you set or the default value.
: Set option? View the current setting value of option
: Set displays the options modified or set during the. vimrc file or the current session.
. Vimrc File
In Linux,. vimrc is in the home directory of the user (you do not need to create one at first). You can modify this file.
You can write the set, AB, and map commands to this file. Then, if you enable vim editing, the configuration in this file will be used.
Replace Environment
In addition to reading the. vimrc configuration file in the home directory, vim can also read the. vimrc file in the current directory, so that you can set the options for special projects.
Note: You can set some options in. vimrc in the home directory, and then cancel these settings in the local directory.
Run linux commands
When editing in vim, you can display or read the execution results of any Linux Command.
Use an exclamation point (!) You can create a shell in vim and regard the content following it as a Linux Command:
:! Command
For example,
:! Date display current time
The preceding command can only be executed once, and then return to the vim editing environment. If you want to execute multiple commands without returning to the vim editing environment, you can use the command,
: Sh
This command is actually a new shell that can be operated like a normal command line.
If you want to exit shell and return to vim for editing, press Ctrl + D
The read (r) command can be used to read the result of Linux Command Execution into the current edited file:
: R! Date
The current time will be read into the editing file.
Filter text using commands
Using the exclamation point to execute linux commands, vim can use the functions provided by linux commands to edit them.
For example, the file content:
4
5
2
3
To sort these rows from small to large, you can use the system's sort command:
: 1, 4! Sort
These four rows will be sorted
Abbreviation
Abbreviations are very useful. We often repeatedly enter phrases of the same length in files, whether in insert mode or command mode, vim and ex have many different methods for saving long command sequences.
: AB hw hello world!
This command indicates that hw is hello world! In insert or command mode, if you enter hw as a complete word (not part of other words), it will be automatically expanded to hello world!
To cancel this abbreviation, enter
: Unab hw
List all abbreviations currently
: AB
Recommended reading:
Vim Learning Guide
Quick learn Vi Editor
Powerful Vim Editor
Build a Vim Development Environment on CentOS 6.2
Vim 7.4a released, a new and faster Regular Expression Engine
Install the highlighted Vim editing tool in CentOS 5.4
Vim tips: C language settings
Set the Vim row number in Ubuntu