How to obtain the powerful functions of VIM

Source: Internet
Author: User
Tags imap xsl

I am not a fan of Linux/Unix, although I advocate the spirit of GNU.
I used to write C/C ++ programs on the Windows platform using VC,
It also uses editplus to write ASP/HTML, and occasionally uses sourceinsight to browse some
Large Project source code.
The debate on the editor is often seen on the Internet, so we often hear this:
"VI and Emacs are the two most powerful editors in the world ".
I have installed RedHat on my PC.
They are deleted. I am not very interested in Linux,
Soon I felt that Linux was not easy to use, and VI could not see any useful information.
I often hear people talk about how powerful VI is and what can be done.
Some examples are often provided, such as regular expression search.
However, in my daily work, it is really rare to see who needs such professional editing when programming and writing code.
Tips. Sometimes, when installing Linux, I just want VI to be the same as editplus.
I don't want to expect it to be as convenient as VC.
However, in common Linux/Unix entry books, you can use VI without exception,
The distinction between insert mode and command mode is usually introduced.
Move, talk about: Q,: WQ,: Q! Exit, talk about I, O, a insertion, talk about <escape>,
Copy & paste, such as DD, YY, and P. (Of course, these are the most basic ones, and you have :-))
However, I think most people will find it hard to find the most powerful editor.
I feel inferior to notepad. I really don't understand it :-(.
I am a beginner in Linux and often see VI skills on the Internet or BBS.
Always these impractical commands, like replacing % S/Foo/BAR/GC will become
The article about tips is really confusing, because these are very basic for the Windows Editor.
Why do so many people say VI/Vim is the best editor? I think there is always a reason.
Although the speaker often refers to one sentence, VI is the best. Use VIM + GCC + GDB,
What do you want to do. I am not a fan of VIM,
I just hope that I can have a good tool when programming in Linux/Unix.
When I accidentally accessed vim.sourceforge.net, I downloaded several top rated
Vim script and read the top rated tips. My views have changed a lot.
After spending a whole day studying and mastering these tips and scripts, I feel that Vim is indeed
A good tool.
Let me first talk about some of the features that I want most when I turn to VI for programming,
These functions may be small, but if they are equivalent to editplus or Vc, I feel very uncomfortable.
Of course it may have been too long since Windows was poisoned.
1. How to easily edit multiple files at the same time, such as switching between multiple files,
Copy paste content.
2. I want to find a word in the editing text. Almost all I teach in books is to use "/word ",
However, if the word is under the cursor, I need a character to enter the word,
Isn't it depressing? For example:/I _want_to_search_this_long_word.
3. My main job is C/C ++ programming. I really hope I can see it on the left.
Project file list, and class, function, struct list, and select
You can jump to the corresponding location.
4. It is also related to programming. In VC, after browse info is built, F12 will
You can easily define ition in class, variable, constant, etc,
Implementation or reference redirection, which is very convenient and useful.
5. In VC, in A. C/. cpp file, for include files, such
# Include "foo. H", where you are at Foo, you can jump
This header file is really convenient. Isn't Vim provided?
6. If you can view the file list like explorer in VI, you can select.
There are more problems, so I don't have to list them one by one, because this article is not intended
Baike gave up (:-) for those who used VI, but certainly not transferred to Emacs ),
And beginners of Linux/VI, but read books but think VI is not easy to use.
OK, the solution to the above six problems.
1. vim.sourceforge.net download the bufexplorer. Vim ranking No. 3
2. In vim.sf.net, tips's no. 1 "Super Star ".
You can press * on the word, just as convenient as pressing CTRL + F3 on editplus.
Another trick is to write the/to start searching, and then <Ctrl + r> <Ctrl + W> can put
It is a useful tip for copying words to the command buffer.
3. A) to view the list of class and struct, you need taglist. Vim of No. 1,
With it, VIM looks much better now. B) You want to have a project file list: you need
Project. Vim of No. 7, with both of them, the left-side windows of VC are basically simulated. :-)
4. With the help of taglist. Vim, you will feel much more convenient. The taglist requires ctags.
In order to achieve this, the function of ctags is to create tags for symbol in C code. What is tags?
You can see through Vim's help (: help), which is like a hyperlink. However, the ctags Function
It is not strong enough, because csflood is indeed better and stronger than it. If you are interested
When using cssag, you should check cscope.sf.net, and many Vim versions are
No support for Embedded csflood. You can use version in VIM to view details. If no,
Congratulations! You have the opportunity to compile Vim yourself. Haha, note./configure
-Enable-cscope. With csflood, it is really amazing to use Vim to view the project code!
5. GF -- that's simple. What if you still cannot find the header file?
Please: Help path. It is important to correctly set the path of the header file.
6. Try: Ex and: Sex: E. And: E/usr/src.
Other
7. You must go to vim.sf.net and put the top 10 scripts in your vim,
You must save the tip of No. 2 and check it at any time.
8. I use Vim in xterm, but it is also good to use gvim for long time programming. You can
Download desert. Vim in a good color and protect your eyesight. Gvim = vim-G
P.s.
Here, I wrote this article because it took me a whole day to learn vim,
And install and test the use of these scripts, finally feel that the use of VIM is getting started and easy.
In fact, I have been using VI for a long time, but I have never been to vim.sf.net, so
I have always thought that VI is not easy to use. Now my views have changed. I hope this article will help those
Hope to learn about vim. :-)
If you are learning Emacs, you must go to www.emacswiki.org to check the tip,
Download the script. But I already think Vim is good enough. Because I like the VI Method
Use J to move the cursor, instead of pressing CTRL + n like Emacs. You need two hands.

Reference from http://www.smth.edu.cn/bbsgcon.php? Board = linuxapp & file = N/g.20.1286675.00 & num = 1280

Vim configuration instance

Code
Set nocompatible
Source $ vimruntime/vimrc_example.vim
Source $ vimruntime/mswin. Vim
Behave mswin

Set guifont = fixed0000tf: H14 "if this font is not available, do not add
Set tabstop = 8
Set softtabstop = 4
Set shiftwidth = 4
Colorscheme blue "in gvim, you can see the number of coloscheme

Set Sw = 4 "shiftwidth
Set et "expandtab
Set WM = 8 "wrapmargin
Set BS = 2 "backspace
Set Ru "Ruler
Set ic "ignorecase" is case-insensitive, but is not case-insensitive if the input is case-insensitive.
Set is "incsearch
Set SCS "smartcase: override the 'ic 'when searching
"If search pattern contains uppercase char
Set VB t_vb = "Set visual Bell and disable screen flash
Set backup "enable backup and define the backup file
Set backupext =. Bak
Set hlsearch "hlsearch
"Allow backspacing over everything in
"The insert mode
Set backspace = indent, EOL, start
Set dir = E:/tmp/vimswap/vim1, E:/tmp/vimswap/vim2, E:/tmp/vimswap/vim3, E:/tmp/vimswap/vim4
"Set the directory above the swap file
Set backupdir = E:/tmp/vimswap/vim1, E:/tmp/vimswap/vim2, E:/tmp/vimswap/vim3, E:/tmp/vimswap/vim4
"Setting the directory of the backup file I do not like to see that there is a backup under each directory because the backup is generally not used

Set diffexpr = mydiff ()
Function mydiff ()
Let opt =''
If & diffopt = ~ 'Icase' | let opt = opt. '-I' | endif
If & diffopt = ~ 'Iwhite' | let opt = opt. '-B' | endif
Silent execute '! D:/tools/Vim/vim62/diff-'. OPT. '"'. v: fname_in. '""'. v: fname_new. '"> "'. v: fname_out. '"'
Endfunction

"The following is the setting of automatic folder Based on the write C code. If you do not like folder, you can omit it.
AU bufreadpost *. C, *. cpp SYN region myfold start = "{" End = "}" transparent fold
AU bufreadpost *. C, *. cpp SYN sync fromstart
AU bufreadpost *. C, *. cpp set foldmethod = syntax
Set foldlevel = 0

Configuration File

Code
"----------------------------------------------------------------
"$ ID: .vimrc.html, V 1.3 2003/06/16 23:29:15 thouveni exp $
"
"
"Download <URL: http://touv.ouvaton.org/documents/MyDotFiles/.vimrc>
"
"----------------------------------------------------------------

"-----------------------------------------------------------
"{1. General setup
"-----------------------------------------------------------

"Enable backspace to delete anyting (DES/n) in insert mode
Set backspace = 2

"Il parait que C' est mieux de ne pas restart re compatible
Set nocompatible

"??? Fait un bip lors D 'une erreur
Set errorbells

"Active les plugins et les indeantaions par type de fichier
Filetype plugin indent on

"Quand on tape UN), VIM montre furtivement le (correspondant.
Set showmatch

"On ne coupe pas Les lignes Si elles sont grandes
Set nowrap

"??? Now real wrap during insert (enable/override this when using as mail-editor)
"Set Tw = 0

"??? Use full featured format-Options. See "Help fo-table for help
If V: version> = 600
Set formatoptions = tcrqn2
Else
"Vim 5 doesn't know R/n
Set formatoptions = tcq2
Endif

"Define what are comments
Set com & "reset to default
Set com ^ = sr: */-, MB: * //, El: */COM ^ = sr: //-, MB: ///, El: ///

"Ajoute une marge? Gauche pour afficher les +/-des replis
Set foldcolumn = 2

"}}}

"-----------------------------------------------------------
"{2 indentation
"-----------------------------------------------------------

"On garde d'une ligne? L 'autre l' indentation d' un paragraphe
Set autoindent

"???
Set expandtab

"Nombre d' Espace pour une tabulation
Set shiftwidth = 4

"If non-zero, number of spaces to insert for a <tab>
Set softtabstop = 4

"Number of spaces the tab stands
Set tabstop = 4

"Some nice options for cindenting by Folke
Set cinoptions = {. 5 S, +. 5 S, T0, N-2, P2s, (03 S, =. 5 S,> 1 s, = 1 s,: 1 s

"A <tab> in an indent insets 'shiftwidth' spaces (not tabstop)
"Set smarttab

"Smartindenting (clever autoindenting)
"Set Si

"}}}

"-----------------------------------------------------------
"{3. Searching, substituting
"-----------------------------------------------------------

"On ignore la Casse des caract replica es dans les recherches de Cha replica es.
Set ignorecase

"No ignorecase if uppercase chars in search
Set SCS

"Change the way backslashes are used in search patterns
Set magic

"Begin search at top when EOF reached
Set wrapscan

"Jump to matches during entering the pattern
Set Sm

"Highlight all matches...
Set HLS

"... And also during entering the pattern
Set incsearch

"!!! Use 'G'-flag when substituting (SUBST. All matches in that line, not only first)
"To turn off, use g (why is there no-G ?)
"Set gdefault

"!!! Turn off the fucking: S // GC toggling
"Set noedcompatible

"}}}

"-----------------------------------------------------------
"{4. Highlighting, colors, fonts
"-----------------------------------------------------------

"Active la coloration syntaxique Quand C' est possible
If & t_co> 2 | has ("gui_running ")
Syntax on
Endif

"Fond Noir
Set BG = dark

If has ("gui_running ")

"Nombre de colonnes? Afficher
Set co = 98

"Nombre de Lignes? Afficher
Set lines = 41

"Choix D 'une police
If has ("Win32 ")
Set guifont = fixedsys: H9: cansi
"Set guifont = courier: H10: cansi
Else
Set GFN =-Adobe-courier-Medium-r-normal-*-140-*-m-*-iso8859-15
Endif

"Choix d 'un theme de coloration
"Colorscheme Pablo
Colorscheme darkblue
Endif

"??? How many lines to sync backwards
SYN sync minlines = 10000 maxlines = 10000

"??? How many lines to search backward after a jump to check syntax
Let c_minlines = 200

"??? Aldo highlight some things in comments
Let c_comment_strings = 1

"??? SQL-highlighting in PHP-strings (1 = YES 0 = No)
"Let php_ SQL _query = 1
"Let php_minlines = 300
"Let php_htmlinstrings = 1

"}}}

"-----------------------------------------------------------
"{4. statusline, menu
"-----------------------------------------------------------

"Use tab for auto-expansion in menus
Set WC = <tab>

"Show a list Of all matches when tabbing a command
Set wmnu

"How command line Completion Works
Set wildmode = List: longest, list: full

"Ignore some files for filename completion
Set wildignore = *. O, *. R, *. So, *. SL, *. Tar, *. tgz

"Some filetypes got lower priority
Set su =. H,. Bak ,~,. O,. info,. SWP,. OBJ

"Rememberlast 2000 typed commands
Set HI = 2000

"Show cursor position below each window
Set ruler

"Shows the current status (insert, visual,...) in statusline
Set showmode

"Use shortest messages
Set SHM =

"Show always statusline of last window
Set laststatus = 2

"}}}

"-----------------------------------------------------------
"{5. Window handling
"-----------------------------------------------------------

"Focus follows mouse
Set mousef

"Minimal number of lines used for the current window
Set wh = 1

"Minimal number of lines used for any window
Set WMH = 0

"Make all windows the same size when adding/removing windows
Set now.always

"A new window is put below the current one
Set splitbelow

"}}}

"-----------------------------------------------------------
"{6. File, backup, path
"-----------------------------------------------------------

"Le swap est mis? Jour APR limit 50 caract bought es saisies
Set UC = 50

"R assumertoire de sauvegarde automaitique
Set backupdir = ~ /. Backup

"On Active la sauvagarde
Set backup

If has ("Unix ")
If V: version> = 600
Set Path =.,/usr/include,/usr/x11r6/include,/usr/local/include
Else
Set Path =.,/usr/include,/usr/x11r6/include/,/usr/local/include
Endif
Endif

"Change to directory of current file automatically
Autocmd bufenter * LCD %: P: H

"}}}

"-----------------------------------------------------------
"{7. UNIX specials
"-----------------------------------------------------------

If has ("Unix ")
Set clipboard = Autoselect
Set shell =/bin/bash
Endif

"}}}

"-----------------------------------------------------------
"{8. Mapping
"-----------------------------------------------------------

"Supprime tout les balancs en debut de ligne
NMAP _ s: % S/^/S/+ // <CR>

"Converts file format to/from UNIX
Command unixformat: Set FF = Unix
Command dosformat: Set FF = DoS

"On fait Tourner les tampons...
Nnoremap <C-N>: BN! <CR>
Nnoremap <C-P>: BP! <CR>

"Annuler aka undo (window $'s style)
Noremap <C-Z> U
Inoremap <C-Z> <C-O> U

"Refaire aka Redo (window $'s style)
Noremap <C-Y> <C-R>
Inoremap <C-Y> <C-O> <C-R>

"Tout s partition predictionner (window $'s style)
Noremap <C-A> gggh< C-O> G
Inoremap <C-A> <C-O> GG <C-O> GH <C-O> G
Cnoremap <C-A> <C-C> gggh <C-O> G

"Indentation Automatique (Emacs's style)
Vnoremap <C-F >=$
Vnoremap <tab> =
Nnoremap <tab >=$
Nnoremap <c-tab> mzvip = 'z

"Fermer fichier (tampon) (window $'s style)
Maps <C-F4>: BD <CR>
Imap <C-F4> <C-O>: BD <CR>
Cmap <c-F4> <c-c>: BD <CR>

"Sauvegarder fichier (touv's style)
Noremap <c-x> <c-S> W <CR>
Inoremap <c-x> <c-S> <C-O>: W <CR>

"Ouvrir UN fichier (Emacs's style)
"Noremap <c-x> <c-F>: E!
"Inoremap <c-x> <c-F> <c-o>: E!

"Have <F1> prompt for a help topic, rather than displaying the introduction
"Page, and have it do this from any Mode:
Nnoremap <F1>: Help <space>
Vmap <F1> <C-C> <F1>
OMAP <F1> <C-C> <F1>
Map! <F1> <C-C> <F1>

"Force la fermeture d' un tampon
Map <F4>: BD! <CR>
Imap <F4> <C-O>: BD! <CR>
Cmap <F4> <c-c>: BD! <CR>

"Fermer UN tag (Cf. closetag. Vim)
Inoremap <F5> <C-R> = getclosetag () <CR>
Map <F5> A <c-_> <ESC>

"Supprime tout les Blancs en fin de ligne
Map <F6>: % S/+ $ // <CR>

"Mets en Commentaire
Map <F7> <leader> C
Imap <F7> <ESC> <F7>

"Active/d standby active la navigation par tags
Nnoremap <silent> <F8>: tlist <CR>

If has ("gui_running ")
"Alt jumps to menu
Set winaltkeys = menu

"Clipboard to Autoselect
Set guioptions + =

"Shift-fleche pour selectionner un bloc
Map <s-up> VK
Vmap <s-up> K
Map <s-down> VJ
Vmap <s-down> J
Map <s-Right> V
Vmap <s-Right> L
Map <s-left> V
Vmap <s-left> H

If has ("Win32") | has ("Win16 ")
"...
Else
"Couper aka cut (generic's style)
Vmap <s-del> "* x

"Copier aka copy (generic's style)
Vmap <c-Insert> "* y
"Vmap <return>" * Y "" Return realize la copie du bloc selectionner
"Vmap <s-return>" * Y "" shift return aussi

"Coller aka insert (generic's style)
Function! Normalpaste ()
If @*! = ""
Normal "* GP
Endif
Endfunction
Function! Selectpaste ()
If @*! = ""
If COL (".") <COL ("'<")
Normal "* GP
Else
Normal "* GP
Endif
Endif
Endfunction

"Map <s-Insert>: Call normalpaste () <CR>
"Imap <s-Insert> x <ESC>: Call normalpaste () <CR> S
"Cmap <s-inserted> <C-R> *
"Vmap <s-Insert>"-X: Call selectpaste () <CR>
Endif
Endif

"}}}

"-----------------------------------------------------------
"{9. Divers
"-----------------------------------------------------------

"Use CSS when converting syntax to HTML (2html. Vim)
Let html_use_css = 1

"And a nice command for makeing HTML-code
Command code2html: Source $ vimruntime/syntax/2html. Vim |

"}}}

"-----------------------------------------------------------
"{11. templates
"-----------------------------------------------------------
If has ("autocmd ")
AU bufnewfile *. XSL 0R ~ /. Vim/templates/XSL. XSL
AU bufnewfile *. xml 0R ~ /. Vim/templates/XML. xml
AU bufnewfile *. html 0R ~ /. Vim/templates/html.html
AU bufnewfile *. c 0R ~ /. Vim/templates/C. C
AU bufnewfile *. php 0R ~ /. Vim/templates/PHP. php
Endif

"}}}

"-----------------------------------------------------------
"{12. SP verify ificit? Pour chaque type de fichier
"-----------------------------------------------------------
Autocmd filetype text setlocal textwidth = 78
Autocmd filetype text set nocindent
Autocmd filetype HTML set formatoptions + = tl
Autocmd filetype CSS set smartindent
Autocmd filetype HTML, CSS set noexpandtab tabstop = 2
Autocmd filetype C, CPP, slang set cindent
Autocmd filetype HTML, XML, XSL source ~ /. Vim/scripts/closetag. Vim

"}}}

"VIM: OFDM = marker

Apply from http://bbs.loveunix.net/viewthread.php? Tid = 3155

Http://larc.ee.nthu.edu.tw /~ Cthuang/Vim/Co., vim-living.html # vertical_splitting

 

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.