Editor-God Vim communication learning

Source: Internet
Author: User
Tags home screen

In the past few days, I will talk to my colleagues about the basic use of vim and record relevant information here.

This communication should be divided into several parts

1. What is Vim?

2. vim and Emacs

3. Why Learning Vim?

4. Comparison between common GUI editors and VIM reflects the advantages of VIM

5. Introduction to common Vim commands

6. Develop related commands

7. How to Learn Vim

8. Vim value-added learning Linux and Efficiency

9. Suggestions for improving work efficiency

1. What is Vim?
Vim is a text editor similar to VI, but many new features are added based on VI.
VI and Vim are the most commonly used editors in Linux. Most Linux-like systems are installed by default. Although Vim is not as simple as the GUI Editor, it is never comparable to the GUI editor in the system management and Server Management character interfaces.

Ii. vim and Emacs
It is said that Emacs is the god Editor, while Vim is the god of the editor. The so-Called god editor Emacs is certainly not as simple as editing files. It is said that Emacs can manage file systems, run terminals, receive emails, access the Internet, listen to music, and even some people use Emacs to control coffee making. The so-called editor God should be literally the most powerful and strongest in the editor. Vim has always been famous for its FAST text editing. Its buttons are more concise and quick to implement operations.

3. Why Learning Vim?
1. EditProgramSpeed is fast. This is the most important vim and is also famous in the world.

2. It is easier to learn and use Linux systems
Each system administrator must at least learn to use a command line interface's text processor to manage the system. There are a lot of word processing software in Linux, such as Emacs xedit kedit, but VI is installed by default in almost any UNIX-like system. It is much easier to learn from and use Linux.

Iv. Comparison between vim and common GUI editors
1. Eclipse and other GUI tools can achieve Vim faster

Enable and switch the new tags of multiple files

View File Directories

Text Search

Text replacement

Use Regular Expressions

Save and restore

Save and restore the Work Environment

2. What eclipse can do is

Move the cursor position, for example, move a word in a row, move a nested statement in a row

Scrolling display

Multiple files in the split window are displayed on the screen at the same time.

Function preview and file editing

CodeMovement under the nested Structure

No plug-ins required for Automatic completion

All of this can be achieved on Linux without installing any tool.

Introduction to common Vim commands

Introduction to VIM Basic Mode
The Vim editor is a mode editor. This means that the editor has different behavior modes in different States. Vim has three modes: general mode editing mode command line mode in general mode and command line mode, each character you type is considered a command. In insert mode, all the characters entered are used as the actual text content.

Normal Mode
Common commands in Normal Mode

move the cursor
scroll screen: CTRL + F move one page down CTRL + B reverse Ctrl + D move down half page Ctrl + u reverse Ctrl + e move one row up Ctrl + y move one row down
Move the current row position: ZZ moves the row where the cursor is located to the center ZT screen above the ZB screen
move the cursor on the current screen: h home screen top line m middle line l last bottom line
file moving: Gg first line G last line ng n line
single line moving: shift + ^ shift at the beginning of the row + $ at the end of the row
move to the position where f'm' m is located on the specified character. F: move the cursor to the left and place it on the search character. N: Execute several times t. move the cursor before the searched character
by word: w: move one word backward NW move n words backward B move one word forward Nb move n words forward cursor place on the first letter of the word
E move one word backward cursor place on the last word letter Ge and vice versa
% nested China Mobile includes () [] {}< br> move to the specified line N {hjkl} and perform corresponding redirects respectively, for example, move 3j down 3 rows
move the file location percentage to 10% of the file content
view the current location: CTRL + G
jump: ''Ctrl + O Ctrl + I forward

Delete copy and paste
X returns a character to the backend x reverse NX deletes n characters to the backend NX reverse
dd deletes a row of NDD and deletes n rows down
DW deletes a word
d1g deletes all data from the cursor location to the first row. DG deletes all data from the cursor location to the last row.
d $ deletes the cursor location d0 or d ^ at the end of the row to delete the cursor position to the beginning of the row
YY copy the line where the cursor is located Ayy copy the next n rows where the cursor is located
y1g copy the row where the cursor is located to the first row all data in the row YG copy all data from the row where the cursor is located to the last row
y0 copy all characters from the cursor position to the first row y $ copy all characters from the cursor position to the end of the row
P: paste the copied content to the next line of the cursor P: paste it to the top line of the cursor
J: Merge the row where the cursor is located with the next line into a row
U undo
Ctrl + R Reply
. repeat the previous action
X indicates DL (delete the character under the current cursor)
X indicates DH (delete the character on the left of the current cursor)
d Indicates d $ (content deleted to the end of the row)
C indicates C $ (content modified to the end of the row)
S stands for Cl (change one character)
S stands for CC (change one line)
Y stands for YY

How to enter the editing mode
I start to insert at the place where the current cursor is located I insert at the beginning of the current row
A. Insert a from the next character at the cursor position. Insert a from the last character in the row where the cursor is located.
O Insert a new row into the next row of the current Row O Insert a new row into the previous row of the current row
R replaces a character R always replaces the text where the cursor is located
Exit edit mode
The edit mode command rarely searches for Embedded characters as input content.

Basically, you should stay in the insert mode as little as possible, because in the insert mode, VIM is like a "dumb" editor. Many new users will stay in the insert mode because it is easy to use. But Vim is powerful in its command mode!
You will find that after you get to know Vim more and more, you will spend less and less time using the insert mode.

Common commands in command mode

Search error and replacement
Search:/down? Ignore case sensitivity in n-direction to n-direction \ c
You can also place the cursor on the word to be searched * search down # search up
Search for the entire word plus <>
replace: n1, replace all word1 in the N2s/word1/word2/GC n1-n2 line with word2 and confirm with the user
% all rows G indicates to replace all matching items in one row C requires user confirmation
set ignorecase case-insensitive
\ c Regular Expression case-insensitive \ c case-sensitive
set nowrapscan disable loop search
/search/2 target offset of two rows-2 up
/search/e + 1 next character-1 Previous character
/search/B + 1 next character-1 Previous character

file operation
W save WQ save exit Q exit before adding! Is force e! Restore the file to the initial state
W filename: Save the edited data to another file. N1, n2 saves data from line N1 to line N2 to the new file
r filename reads a new file
! Run the shell command to start a new shell
Ctrl + line B
Ctrl + line E
S + {left, right} Use words as the moving range
Ctrl + W Delete the entire word
Ctrl + u Delete the entire line
Ctrl + C delete all data in the command line and exit the command line mode
the tab arrow is automatically completed, as is not supported by B edit VI.
Ctrl + D: display all data that meet the conditions.
Ctrl + L maximum completion. common parts of each conformity
History display all historical commands
Ctrl + P the previous Ctrl + n the next different and up arrow search based on the entered
q: open the command line window to view and edit the old command
! All shell commands must be prefixed! For example! SVN up ~
shell opens a new shell.

In visual mode, press V to enter visual mode (visual selection mode)
V select characters
V select row
CTRL + V Block Selection
O reset the cursor to the other end of the selected area
O move the left and right corners of the same row

Replacement Mode
R replaces a single character
R always replaces the character of the cursor

Several common Vim Methods

1. edit multiple files (important)
Edit filename open a new file. Edit! Filename force not save open new file
Hide edit filename does not save the changes to the current file to open the new file so that the modified file becomes a hidden buffer.
Next next file wnext save current file and next nnext n times
Previous previous file wprevious save current file and previous nprevio n times'
Last last
First
ARGs: view the file currently added
CTRL + ^ fast switch between two files
Ls displays the list of opened files
Switch B n to the nth
Write> filelog Append content to the file
Save saveas as a new file
Tabedit new tab to open a new file

2. split the window (convenient)
horizontal split of split filename
Vertical Split of vsplit filename
close split window Q can be closed but close can keep the last window
only one window is retained. close all
Ctrl + WW switch different windows
new open a new window and edit a new buffer
vnew open a recharge split window and start edit a new buffer
nsplit opens a window with N rows in height
Ctrl + W + {hjkl} switch between different windows
Ctrl + W + {hjkl} Move the positions of different windows
qall exit all windows exit Vim
wall save all windows
wqall save exit all windows
vim-o open a window for each file

3. Edit the program (important)
The author of VIM is a programmer. Therefore, VIM has many functions to help write programs.
The definition of an identifier is unknown.
Ctags generate the tags file to record the location where all identifiers appear, Linux usually install http://ctags.sf.net
Tag M jump to the place defined by M Ctrl +] Jump to the location defined by the identifier where the cursor is located 3 tag jump to the place where the third appearance
Stag split window Ctrl + W +] Likewise
Tags list used tags
CTRL + t jump to the tag used last time
Set tags = tags to set the tags file. If you want to use multiple tags files
Tnext, the next tag with the same name tprevious, the last one of tfirst's first tlast
Tselect to view tags with the same name
The tab key can be used to complete the tag
Ptag preview tag definition Ctrl + W +}
Pcloase close preview window

4. Movement in code blocks (important)
Move in a code block
% Shuttle at the beginning and end () [] {}
[[Previous code block] Next code block
[{Beginning of code block]} End of code block
[/Comment start]/comment end

Common skills

Suspension and recovery
Same as Linux job control
Jobs view jobs
CTRL + z pending
FG recovery
BG transferred to the background for execution
& Background running
Kill: You can also delete a job by using FG + Ctrl + C.

File browsing
Edit.
Enter to open a file or directory
CTRL + O return or Q
O open a horizontally separated window to display files
V open a vertically separated window to display files
T open the file in a new tab

I control the display style of the List (only the file name is displayed, or the detailed information is displayed in a row,
List projects by line or tree display). The detailed information style includes file size and date information.
Repeat by S will change the way files are sorted cyclically: By file name, by the last modification time, or by file size.
R switch positive/reverse sorting

Indent
> Right indent the row where the cursor is located
<Right indent the row where the cursor is located
Set shiftwidth = 8 default indentation 8
Set softtabstop = 8 set the tab key indent

Save session
Create a mksession
Source resume session
Resume session when vim-S is started

Quick typing
CTRL + P automatically complete Ctrl + N reverse search complete
Search file sequence 1. Current file 2. files opened in other Windows 3. Tag files
CTRL + y copy the same content as the previous line
CTRL + e copy the same content as the next line
Abbreviation (not important, easy to develop dependency)
Iabbrev func Function
Abbreviate Teh The Automatic Error Correction
Abbreviations list all abbreviations
Unabbreviate

Line breaks
ZF create a line
Zo opens the line
ZC close the line

Format Text
= Combined with vitrual Mode
Right 40 rows
1, 20, center, 40 rows
1 left 5 5 left white space count

Switch working directory
Other windows of the CD directory will also change.
CD-switches between two working Directories
Local LCD window working directory Switch
PWD: Check that the current working directory is the same as the command line in shell.

Common settings
Set nu display row number
Set Nonu does not display row numbers
Set hlsearch to set whether to highlight the search string
Whether set autoindent is automatically indented
Whether set backup automatically stores the backup file filename ~
Set backupext backup file suffix
Shows the status line description in the lower right corner of set ruler.
Whether set backup automatically stores the backup file filename ~
Whether the insert replace mode and other modes are displayed in the lower left corner of set showmode
Set ignorecase ignore size is generally used for search
Set wrap display line feed nowrap do not line feed
Set textwidth = 90 each line has 90 characters, exceeding the automatic line feed
Set linebreak
Options display all set values

DOS and Linux line breaks are different
Set fileformat? View the current file format
Set fileformats = UNIX, DOS, and Mac: Set the file formats recognized by VIM
Set fileformat = UNIX write to set the format of the saved file
The last modification time of the dos2unix-K file to be retained-n the old file is retained and output to the new file
Unix2dos

Change text case
Gu and Virtual Mode Combination

Vimdiff comparison file
Vimdiff file1 file2
Diffsplit file compares a new file
Vertical Split of windows opened
Set scrollbind synchronous scrolling
] C jump back to different places
[C jump forward to different places
Comparison of diffupdate updates
DP eliminates the difference of the current row
Vim encrypted file
Vim-x encrypted file

Restore Files
Vim-r wapfilename restore File

Replace multiple files
: Argdo % S/\ <word1 \>/\ <word2 \>/Ge | update % all rows <> the matching item cannot be found for all e of the entire word G Single Row. No error is reported, update is performed after replacement. save | split command

Personal habits
~ /. Vimrc/etc/vimrc
Alias

Vimtutor simple learning manual if Vim has been installed in your system, go to vimtutor and learn the simple command, in the shell command line, type vimtutor to start your vim learning journey.

6. Basic Introduction to commonly used commands for development
Grep is used to find the file content grep-IWR./'serch' -- include = *. php
SVN version control command SVN up SVN st SVN log SVN diff SVN merge SVN Ci
History commands! N: Execute the N command !! Previous command! Commands starting with XX in XX history
Jobs job suspension Resume viewing
Head less Cat Tail View File Content

7. How to Learn Vim

There are three phases

1. Vim is particularly difficult to use strange editors

In the beginning, it was notepad, word, and edit that monopolized your brain. These things are deep-rooted and the use of VIM is a nightmare for you. It reduces your productivity rather than improving your productivity. the three working modes make you think that they are full of bugs or at least an odd user interface that is friendly to today.Software with severe disconnections. in fact, these initially seem odd features are Vim (or VI) the author and its users summed up the fastest and most practical operations in their long career of text editing and programming. In the long term that is almost equal to the history of the computer itself, through criticism and testing by countless demanding computer users, there is no room for survival in the face of VIM user groups for useless features or poor design. the careful and careful authors of VIM do not allow such a thing in the software they have designed.

2. Skilled in using Vim to replace the guid editing tool

You are now familiar with some basic operations that are sufficient for your daily work. however, you rarely touch Vim's obscure online help documentation at these stages. it is just notepad in your mind. Edit is a barely qualified alternative.

3. If the command used in the second stage is not met, the system always tries to find the command with the minimum number of inputs.

Keep improving you are not satisfied with simple operations without a rest, lengthy and boring. Is there a better way to pull your teeth. as a result, from the Unix reference manual, from the mouth of colleagues, through various channels, you are always trying

Find the simplest and fastest operation.This is the last phase in which you use Vim. It is also the longest, most challenging, and interesting stage. your mind is highly nervous because it uses Vim for efficient editing. It also begins to find that you have done almost everything in the shell in Vim. in fact, you have become a hopeless Vim hardcore player.

8. Vim value-added learning Linux and Efficiency

1. To use vim, you must enter the command line mode of the command line Linux, so that you can avoid some windows interference, such as pop-up windows QQ, so that you can focus on one thing.

2. To use vim, you must have other UNIX-like systems such as Linux systems. This also increases your access to Linux and attempts to solve some problems such as grep using tools in Linux.

9. Suggestions for improving work efficiency

1. Learn to use Google Calendar to plan your work and life

2. One thing to do is to do only one thing. Don't do it here. You have to write other code. It's not too late to read it after Weibo is finished.

3. Think about the requirements and try again.

Related Article

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.