Vim getting started
VIM and EMACS have been working for a while. But as a JAVA program, it is not realistic to use VIM to write JAVA code (IDEA is used now. I recently felt that VIM was good when I was writing front-end code and blogs, so I decided to pick up VIM.
The bare VIM is not very easy to use. You need to install the required plug-ins. The previous method was to download the corresponding compressed package and modify the configuration. This process is extremely patient and character-oriented!
Use vundle management plug-in
Vundle removes the need to find plug-ins and configurations. All plug-ins are managed in a similar way, greatly reducing the cost of use!
The path where the plug-in is stored is ~ /. Vim/bundle/. After the directory is created, download vundle:
git clone https://github.com/VundleVim/Vundle.vim.git ~/.vim/bundle/Vundle.vim
Later configurations can be found in ~ /. Completed in vimrc:
Set nocompatible "Disable compatibility mode filetype off" Disable Automatic file type detection set rtp ++ = ~ /. Vim/bundle/Vundle. vim "add to runtime path call vundle # begin ()" initialization "ins list start in 'vundlevim/Vundle. vim '" call vundle # end ()" complete filetype plugin indent on "open file type detection
Common plug-in source configurations include:
| Source |
Description |
| Github.com |
Plug-ins hosted on github (Plugin 'tpope/vim-fugitive ') |
| Vim-scripts.org/vim/scripts.html |
Plug-ins maintained on the site (Plugin 'd9 ') |
After the configuration is complete, open VIM and use the following command:
- : PluginList: Open the plug-in list
- : PluginInstall: Install the plug-in
- : PluginSearch foo: Search for plug-ins. You can choose to install the plug-ins after finding them.
- : PluginClean: Clear unused plug-ins (this is not very understandable)
Finally, when you want to install the winmanager plug-in:
- Add in. vimrc
Plugin 'winmanager'
- Open vim
- Run
:PluginListYou can see the winmanager plug-in.
- Run
:PluginInstallInstall
Is it much simpler than before? There is no complicated plug-in management. Now we will go to VIM!
Basic usage
I was very uncomfortable switching from EditPlus to VIM. I just wanted to edit the file, but I still had to consider switching to different modes:
- Command mode
- Edit mode
- Visual Mode
After a long time, it seems reasonable to separate the text. In the command mode, you can use some simple commands to quickly view and modify the text, it is more efficient than using the mouse in EditPlus. This mode uses a lot of commands, which are classified below!
I. move the cursor
You can jump to any dimension at will:
| Command |
Function |
| H/j/k/l |
Move up/down/up/right |
| Ctrl + f/B |
Flip up/down |
| Ctrl + d/u |
Flip up/down half page |
| $/0/^ |
End of line/beginning of Line |
| (/) |
Previous sentence/next sentence |
| W/B |
Next word/previous word |
| Gg/G |
Document start/end |
| % |
Matching of parentheses |
| Ngg/nG/: n |
To row n |
| H/M/L |
Screen top/middle/Bottom |
| */# |
Position of the next or last occurrence of the Current Character |
2. search and replace
| Command |
Function |
| : S/s1/s2 |
Replace the next s1 WITH s2 |
| : % S/s1/s2 |
Replace all s1 WITH s2 |
| : S/s1/s2/g |
Replace s1 of the current row with s2. |
| : N1, n2 s/s1/s2/g |
Replace s1 from line n1 to line n2 with S2. |
| /Xxxx |
Search for xxxx, find and continue searching by n, and then continue searching by N |
| Mx |
Insert a bookmark (x is a lowercase letter). You can use 'x' to jump to this bookmark later. |
| '. |
Last edited location |
Iii. Copy, cut, paste, and delete
Some registers exist in VIM to store the copied and deleted content:
": Recently deleted or copied content
0: Recently copied content
1、2、、9: Add the last deleted content to 1, the original content to 2, and so on.
%: File Name
:: Command
/: String to be searched
You can use reg to view the content in each register during editing! To facilitate the selection of the visual mode introduced in text VIM, first move the cursor to the start position, and then run the following command to enter the visual mode:
ctrl+v: Block
v: Normal
V: Line
Move the cursor to select and operate the text! Frequently Used commands for editing include:
| Command |
Function |
| Y |
Copy the selected text and use"nyTo copy to register n |
| X |
Cut selected text or delete current character |
| D |
Delete selected text |
| P |
Paste"npTo paste the content in register n. |
| Dd |
Delete current row |
| Dw |
Delete a word after the cursor |
| Dl |
Delete a character |
| D/C |
Delete to end of line |
| Yy/Y |
Copy a row |
You can useuAndctrl+rTo perform undo and redo operations.
Iv. macros
Some simple and mechanical operations are often encountered during data creation, which can be done with macros:
px: Starts macro recording. x is a lowercase letter.
- Operation
q: Record operations to registers
@x: Execute operations in register x
@@: Execute the last recording.
You can also use: reg to view the register status.
5. Edit
Run the following command to enter the insert mode:
| Command |
Description |
| I/ |
Insert before/after the cursor |
| I/ |
Insert at the beginning/end of a row |
| O/O |
Insert a row before/after to edit |
| S/S |
Delete one character/line for editing |
| R |
Replacement mode, which is very useful for drawing |
Multi-screen operations
When writing code, it is common to write several files. It is very comfortable to split several screens. The following methods can be used to enable split screens:
vim -On file1 file2 ...: Open multiple files on the Vertical Split screen
vim -on file1 file2 ...: Open multiple files on the horizontal split screen
ctrl+w s: Splits the current file up and down
ctrl+w v: Split the current file horizontally
:sp filename: Split up and down to open a new file
:vsp filename: Open a new file horizontally
To switch the working screen, run ctrl + w h/j/k/l/w. h/j/k/l moves in the direction and w moves to the next screen! You can use ctrl + w H/J/K/L to move the split screen when you think the screen sequence is a little uncomfortable. You can also adjust the screen size:
ctrl+w =: The height of all screens is the same
ctrl+w -: Height reduction
ctrl+w +: Increase the height
During editing, you can browse the directory on the split screen:
:He: Split up and down the screen, in the following (:He!On the top) browse the Directory
:Ve: Left/right split screen, on the left side (:Ve!View the directory on the right.
You can also use: E to open the directory on the current screen for browsing. You can use some commands to perform operations:
-: Go to the parent directory
s: Sort files
x: Execution File
R: Modify file name
D: Delete an object
Enter: Go to the subdirectory
While reading and writing, You Need To synchronously scroll on multiple screens.:set scbAnd:set scbTo bind and unbind (this function is still very useful )! Finally, you can usectrl+w cOrctrl+w q(If it is the last screen, exit VIM) to close the split screen!
Summary
Having mastered this, it should be difficult to edit simple text. Later, we will write more details separately.
For more Vim tutorials, see the following:
Build VIM into a simple and practical IDE
Vim Learning Guide
Quick learn Vi Editor
Powerful Vim Editor
Build a Vim Development Environment on CentOS 6.2
Install the highlighted Vim editing tool in CentOS 5.4
Vim tips: C language settings
Set the Vim row number in Ubuntu
Vim editor basic tutorial
This article permanently updates the link address: