Learn about Vim

Source: Internet
Author: User

The current job is on the UNIX platform. It is usually written using the FTP function of UE.CodeSometimes the file size is too large, the transmission is very slow, and it is often not very stable.
I made up my mind to learn Vim (no one should use the original VI now). After two weeks of use, I found Vim is a very good editor, now I have installed Vim on windows, which is quite easy to use and has replaced ue.

The following describes some of my experiences in using VIM:
1. Make some settings before using Vim. Otherwise, you will be uncomfortable using it. The following is my configuration.

1 " ========================================================== ======
2 " General settings
3 " ========================================================== ======
4
5 Set nocp
6 Set Ru
7 " Use cindent
8 Set CIN
9 Set cino = : 010000t0 (Sus
10
11 Set Sm
12 Set AI
13 " Scale down
14 Set Sw = 4
15 Set Ts = 4
16 " If the tab is not expanded, it is a space. If the tab is not displayed, Set et
17 Set NOET
18
19 Set LBR
20 Set HLS
21 Set backspace = Indent , EOL , Start
22 Set whichwrap = B , S , < , > , [ , ]
23 Set fo + = MB
24 Set selectmode =
25 Set mousemodel = Popup
26 Set keymodel =
27 Set Selection = Comprehensive
28 Set matchpairs + = <:>
29
30 " ========================================================== ======
31 " Cursor Movement
32 " ========================================================== ======
33 Nnoremap <down> GJ
34 Nnoremap <up> GK
35 Vnoremap <down> GJ
36 Vnoremap <up> GK
37 Inoremap <down> <c-o> GJ
38 Inoremap <up> <c-o> GK
39
40 Nnoremap <End> G $
41 Nnoremap <Home> G0
42 Vnoremap <End> G $
43 Vnoremap <Home> G0
44 Inoremap <End> <c-o> G $
45 Inoremap <Home> <c-o> G0
46
47 Nmaps <C-F4>: Confirm BD <CR>
48 Vmap <C-F4> <ESC>: Confirm BD <enter>
49 OMAP <C-F4> <ESC>: Confirm BD <enter>
50 Map! <C-F4> <ESC>: Confirm BD <enter>
51
52 " Enable syntax highlighting
53 Syntax on
54 " Collapse with syntax
55 Set foldmethod = syntax
56
57 If (has ( " Gui_running " ))
58 Set nowrap
59 Set guioptions + = B
60 Colo inkpot
61 Else
62 Set wrap
63 Colo Ron
64 Endif
65
66 " Set the directory of the swap file
67 Set dir = D: "Vim" tmp
68 " Set the directory of the backup file
69 Set backupdir = D: "Vim" Bak
70
71 " Set the leader shortcut key. The original "" is too far away and the location is not fixed.
72 Let mapleader = " , "

Here are some basic settings
If you have any questions, you can use the normal mode in vim.
: H keyword
View help

2. Vim tutorial
We recommend that you first check the built-in tutor of VIM (this is a good teacher)
Start Vim with vimtutor
Or use H tutor in VIM to start
For Chinese tutorials, I recommend Li guozheng "everyone learns Vim".
Here is the vim key position. You can click it to view it at any time.

 
3. Vim plug-in
Several plug-ins are strongly recommended.
(1) A: switching between CPP and H files with the same name? Script_id = 31
(2) nerd_comments: Super annotation plug-in, supports many languages of the annotation style, according to the above settings, only need ", cc" can add a comment http://www.vim.org/scripts/script.php? Script_id = 1, 1218
(3) csupport: Write C/C ++ code essential http://www.vim.org/scripts/script.php? Script_id = 1, 213
(4) largefile: no longer have to worry about opening large files will slow the http://www.vim.org/scripts/script.php? Script_id = 1, 1506
(5) tipoftheday: Read more vim tips will have a lot of GAINS, remember to often update tips files ah http://www.vim.org/scripts/script.php? Script_id = 88
(6) cppomnicomplete: Provide the completion of class/object members in C ++ (vim7 is required) http://www.vim.org/scripts/script.php? Script_id = 1, 1520
(7) colorsamplerpack: provides hundreds of color themes, there will be a suitable for you, but most of them are in the GUI to have the corresponding effect of http://www.vim.org/scripts/script.php? Script_id = 1, 625
(8) vimcdoc: Hand Vim Help http://vimcdoc.sourceforge.net/

3. Use the vim color in Telnet.
If telnet is used in Linux, securecrt will automatically use the appropriate color to display vim different colors, but if it is in other UNIX, it will not be able to display the correct color, everything is in the same color.

Add in. vimrc (^ [the input method is Ctrl-V and then input ESC ):
If! Has ("gui_running ")
Set t_co = 8
Set t_sf = ^ [3% P1 % DM
Set t_sb = ^ [4% P1 % DM
Endif
Select ANSI for the simulated terminal type of securecrt and hook ANSI color to display different colors.

4. Vim's auto-completion Function
Generally, CTRL + N can be used to automatically complete. After vim7, C/C ++ functions, variables, or class members use Ctrl + X, CTRL + O can also be automatically completed. After cppomnicomplete is installed, you can use Ctrl + X, CTRL + O to complete the object.

5. Code folding
Many editors support code folding, and VIM is no exception.
Common shortcut keys
ZC folding code
Zo code for opening and folding
There are other shortcut keys to view help
: H fold

6. automatically format the code
In visual mode, press = to select the code.
In normal mode, press = to format the row where the cursor is located.

7. Script support
Vim not only has built-in script functions, but also supports extensions of VIM written in popular scripting languages such as Perl, Python, TCL, Ruby, and mzscheme.

Is Vim powerful?
After more than one year of testing, VIM 7.0 has also been release, so it is not easy to download and try again.
Http://www.vim.org

Happy vimming!

Users who are used to VIM but want to program in Windows
I also recommend
Viemu. You can simulate the VI editing operation in Visual Studio.
However, there is only a 30-day trial.

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.