Linux Editor VIM configuration

Source: Internet
Author: User
Tags word wrap

Linux programming has been criticized a point is: Not a good IDE, a good IDE is how important ah, estimated that many people are stuck on this threshold, "工欲善其事, its prerequisite" Well, I teach you today to convert vim into a simple IDE, said it "simple" is the interface look "Simple", but the function is absolutely no better than a good IDE, there are features, should not have some features, the following starts to introduce today's work.

This article will teach you:
1. Installation of the Chinese Help manual

2. Syntax highlighting

3. Jump in the program: use of Ctags

4. Teach you to browse the source code efficiently--plugin: TagList

5. File Browser and window Manager-plugin: Winmanager

6. Implement code completion for parentheses

Eg: some of the paths mentioned in the article, such as:
~/.vim/plugin
~/.vim/doc
~/.vim/syntax
If you don't have one, create it yourself (created in your own working directory).
The article says that the. vimrc file refers to ~/.VIMRC (the System Configuration folder for Vim itself is under/usr/share/vim/and/etc/vim/two folders. In general, we do not change the configuration file under the two folders, but rather in the user folder/home/user (where user is the username, my username is Yangle) to create their own profile. Use $CD ~ To switch to a user folder, $touch. vimrc file, where you add your own style of configuration )

I. Installation of the Chinese Help manual

Vim Chinese Help document TAR package:
http://sourceforge.net/projects/vimcdoc/files/vimcdoc/
After decompression, there is a Doc folder, the contents of which are copied to ~/.vim/doc, or the VIM installation directory in the Doc directory, the Help information in Vim is already in Chinese.

Two. Syntax highlighting

~$ gedit. VIMRC
Note: The use of gedit is mainly for the convenience of large sections of the text paste!
Then copy the following text into the file and save it:

"This line should is removed as it ensures that various options is" properly set to work with the vim-related Packag Es available in Debian. Debian.vim "Uncomment the next line to make vim more vi-compatible" NOTE:debian.vim sets ' nocompatible '. Setting ' compatible ' changes numerous "options, so any other options should is set after Setting ' compatible '. Set Nocompat Ible "VIM5 and later versions support syntax highlighting. Uncommenting the "following enables syntax highlighting by Default.if have (" syntax ") syntax on" syntax highlighting Endifcolor Scheme Ron "Elflord Ron peachpuff default set color scheme, VIM comes with a color scheme saved in/usr/share/vim/vim72/colors directory" detect file Typefile  Type Onfiletype plugin on ' If using a dark background within the editing area and syntax highlighting ' turn on this option As Wellset Background=dark "uncomment the following to had Vim jump to the last position when" reopening a fileif had ("a Utocmd ") au bufreadpost * If line (" ' \ "") > 1 && line ("' \" ") <= LINE ("$") | EXE "normal! G ' \ "" | endif "has Vim load indentation rules and plugins according to the detected filetype filetype plugin indent onendif" Th E Following is commented out as they cause vim to behave a lot "differently from regular Vi. They is highly recommended though. " Set ignorecase "Search mode ignores case" set Smartcase "if the search pattern contains uppercase characters, do not use the ' ignorecase ' option. Used only when entering the search mode and opening the ' ignorecase ' option. Set Autowrite "Automatically writes the contents back to the file: If the file has been modified, in each: Next,: Rewind,: Last,: First,:p revious,: Stop,: Suspend,: Tag,:!.: Make, Ctrl] and ctrl-^ when the command is used: buffer, Ctrl-o, Ctrl-i, ' {a-z0-9}, or ' {a-z0-9} ' to go to another file.        Set autoindent "Sets automatic alignment (indentation): That is, the indent value for each line is equal to the previous line, and the set Smartindent smart alignment set tabstop=4 with Noautoindent  The Set tab (tab) Width set softtabstop=4 "Sets the width of the soft tab set shiftwidth=4" (Auto) indents the 4 spaces set cindent use C/w + + The automatic indentation of the language set Cinoptions={0,1s,t0,n-2,p2s, (03s,=.5s,>1s,=1s,:1s "sets the specific indentation of the C + + language" set backspace=2 "set Backspace key available set S Howmatch "Set match mode to display matching parenthesesSet linebreak "integer word wrap set whichwrap=b,s,<,>,[," "The cursor jumps from the beginning and end of the line to another line" set hidden "Hide buffers when they is ABA Ndonedset mouse=a "Enable mouse usage (all modes)" Use mouse set number "Enable Line No." Set Previewwindow "Identity Preview window set history=50" SET command history to 50 "record 50"--Status line set--set laststatus=2 "Total display The status line of the last window, which is set to 1 when more than one window displays the status line of the last window; 0 does not display the last window's status line set ruler "ruler, which displays the line and column numbers of the cursor position, separated by commas. Each window has its own ruler. If the window has a status line, the ruler is displayed there. Otherwise, it appears on the last line of the screen. "--Command line settings--set showcmd" command line display input command set showmode "command line display vim current mode"--find setting--set incsearch "Input word  Match point set Hlsearch is displayed
Note: In a configuration file, text that begins with a single double quotation mark is commented.
After saving the file, start vim. At this point, VIM has shown a syntax highlighting effect.

Three. Jump in the program: use of Ctags

(1) to http://ctags.sourceforge.net/download Ctags source code ctags-5.8.tar.gz
Http://prdownloads.sourceforge.net/ctags/ctags-5.8.tar.gz
(2) Unzip and install
Tar zxvf ctags-5.8.tar.gz
CD ctags-5.8
./configure && make && make install
(3) Use
Create source index, such as need to view library function source code, and the code is placed in the/usr directory
Then after the terminal enters the directory, enter the command ctags-r, you will find a more tags file, this is the index file

Register the path to vim for index file tags,
$ VI ~/.VIMRC
At the end of the open file, add the following (of course, the exact path is based on your own situation)
"--ctags setting--
"Press F5 to regenerate the tag file and update the TagList
Map <F5>:!ctags-r--c++-kinds=+p--fields=+ias--extra=+q .<cr><cr>:tlistupdate<cr>
IMAP <F5> <esc>:!ctags-r--c++-kinds=+p--fields=+ias--extra=+q .<cr><cr>: TlistUpdate<CR >
Set Tags=tags
Set Tags+=./tags "Add current directory ' s generated tags file
Set Tags+=/usr/tags "Add new tags file (just build the path of tags, after ctags-r generated tags files, do not move tags to another directory, or CTRL +], you will be prompted to find the source file)
Set Tags+=./tags to search for tags files under the current working directory
Set Tags+=/usr/tagsWhen searching for tags files, you also need to search for tags files under the ~/usr/folder.
Then save and Exit VI. In this way, you can use VIM to view the prototype of the library function anywhere.

View the printf function hover the cursor over printf and press Ctrl+w +],VI to automatically jump to the Linux system function printf (), where we can see the prototype of printf ()
When you're done, press Ctrl+o (go back to the previous tab) and return to the original place.
Four. teach you to browse the source code efficiently--plugin: TagList
Download Taglist_xx.zip, unzip the completion, will extract the contents of the doc to ~/.vim/doc, will extract the contents of plugin under the copy to ~/.vim/plugin. Generally at the beginning of the working directory there is no. vim folder, so create one yourself. Vim is the same way you would create a folder under Windows.
Click this link to download: http://www.vim.org/scripts/script.php?script_id=273
After completion, add the following three instructions in the. VIMRC:
Let tlist_show_one_file=1
Let Tlist_exit_onlywindow=1
Let Tlist_use_right_window=1
After entering vim, use the command ": Tlist" to open/close the TagList window
Effect
Five. File browser and window Manager-plugin: Winmanager decompression Winmanager.zip, will extract the contents of the doc to ~/.vim/doc, the extracted plugin content copied to ~/.vim/plugin
Click this link to download: http://www.vim.org/scripts/script.php?script_id=95
Add the following two lines of instructions in. VIMRC When you are done:
Let g:winmanagerwindowlayout= ' fileexplorer| TagList '
Nmap wm:wmtoggle<cr>

Common commands
: Wmtoggle on/off Winmanage, but we did a shortcut key mapping in the configuration file. VIMRC, so press WM to open/close winmanage
File browser commands (used in the File browser window)
or double-click if the cursor is under the directory, then enter the directory; If the file is under the cursor, open the file
If the cursor is a directory, enter the directory; If the file is under the cursor, open the file in a new window
Refresh List
-Return to previous level directory
C Make browsing directory a vim current working directory
D Create a directory
D Delete the directory or file under the current cursor
I toggle display mode
R file or directory rename
S Select Sort method
R Reverse Sort List
X Custom Browsing mode, open the file using the program you specified
Winmanager Help Documentation
: Help Winmanager
NETRW Help Documentation
: Help NETRW
Six. Implement code completion for parentheses~$ gedit. VIMRC
Add the following command directly to the. VIMRC and Save: Inoremap <S-ENTER> <c-r>=skippair () <CR>
: Inoremap <S-SPACE> <esc>la
: Inoremap <C-ENTER> <ESC>A;<CR>
: Inoremap (() <esc>i
: Inoremap) <c-r>=closepair (') ') <CR>
: inoremap {<c-r>=clsoebrace () <CR>
: Inoremap} <c-r>=closepair ('} ') <CR>
: Inoremap [[]<esc>i
: Inoremap] <c-r>=closepair ('] ') <CR>
: Inoremap;; <ESC>A;<CR>

function Closepair (char)
If Getline ('. ') [Col ('. ')-1] = = A:char
Return "\<right>"
Else
Return A:char
endif
Endf
function semicolon ()
"Echo getline ('. ') [Col ('. ')]
If Getline ('. ') [Col ('. ')] = = ') '
Return "<ESC>A;"
ElseIf getline ('. ') [Col ('. ')] = = '} '
Return "\<esc>a;"
ElseIf getline ('. ') [Col ('. ')] = = '] '
Return "\<esc>a;"
Else
Return ";"
endif
Endf
function Skippair ()
If Getline ('. ') [Col ('. ')-1] = = ') '
Return "\<esc>o"
Else
Normal J
Let CurLine = line ('. ')
Let Nxtline = CurLine
While curline = = Nxtline
If Getline ('. ') [Col ('. ')-1] = = '} '
Normal J
Let Nxtline = Nxtline + 1
Let CurLine = line ('. ')
Continue
Else
Return "\<esc>i"
endif

Endwhile
Return "\<esc>o"
endif
Endf
function Clsoebrace ()
If Getline ('. ') [Col ('. ')-2] = = '
Return "{}\<esc>i"
ElseIf getline ('. ') [Col ('. ')-3] = = '
Return "{}\<esc>i"
ElseIf getline ('. ') [Col ('. ')-1] = = ' {'
Return "{}\<esc>i"
ElseIf getline ('. ') [Col ('. ')-2] = = ' {'
Return "{}\<esc>i"
ElseIf getline ('. ') [Col ('. ')-2] = = ', '
Return "{}\<esc>i"
ElseIf getline ('. ') [Col ('. ')-3] = = ', '
Return "{}\<esc>i"
Else
Return "{\<enter>}\<esc>o"
endif
Endf


Linux Editor vim configuration

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.