Vim configuration in linux

Source: Internet
Author: User

On suse enterprise 10 recently installed, vim is still the default setting. It is not easy to use. It took a night to configure it. I have sent a lot of information from the Internet and sorted it out, make a backup later ~~

 

Vim version: 7.3. The default version of suse10 is 6.4, which is not supported by nerdtree. download the latest version from the vim official website and install it as a root user;


1. Basic configuration of vimrc:

Set nocp

Syntax on "syntax highlighting"

Set nocompatible "using vim keyboard mode"

Set nu "set row number"

Set nobackup "no backup required"

Set confirm "Confirmation is displayed when it is not saved or read-only"

Set mouse = a "mouse available"

Set selection = exclusive

Set selectmode = mouse, key

Set showcmd "show unfinished commands"

Set tabstop = 4 "tab is 4 spaces"

Set shiftwidth = 4 "line interleaved"

Set cindent "c file type automatic indent"

Set autoindent "automatic alignment"

Set smartindent "smart indent"

Set hlsearch "highlight search matching"

Set background = Dark "background color"

Set showmatch "show match"

Set ruler "show cursor position in the lower right corner"

Set fillchars = vert:/, STL:/, stlnc:/"blank between Split windows"

Set noerrorbells "no warning"


Set foldenable

Set foldmethod = syntax

Nnoremap <space >@= (foldclosed (line ('.') <0 )? 'Zc': 'Z') <CR> "Space Control folding"


Filetype plugin indent on

Set fileencodings = GBK, UTF-8, gb2312, gb18030, cp936

Set termencoding = GBK, UTF-8, gb2312, gb18030, cp936


2. Tree Structure

The nerdtree plug-in is required. Here we download version 5.8. After the download, decompress it in the. Vim folder;

Add a shortcut in vimrc:

Nnoremap <F1>: nerdtree <CR>

F1 can display the directory tree structure. (It can also be replaced with other keys. I prefer F1)


3. Automatic completion and ctags settings

Vim is mainly used to write C and C ++ code, and some sh scripts occasionally exist. Therefore, it is much easier to automatically complete C and C ++ types.

Here two plug-ins are required. One is ctags, which is used to generate the tags file; the other is omnicppcomplete, which is automatically supplemented. Just like nerdtree, decompress it to The. Vim folder.

Set the shortcut key for generating tags:

Nnoremap <F2>: sil! Find-maxdepth 1-name '*. [CH]'-print0-o

/-Name '*. cpp'-print0/| xargs-0 ctags -- C ++-kinds = + p -- fields = + IAS -- extra = + q <CR>

Nnoremap <F3>: sil! Find-maxdepth 1-name '*. [CH]'-print0-o

/-Name '*. H'-print0/| xargs-0 ctags -- C ++-kinds = + p -- fields = + IAS -- extra = + q <CR>


Set F2 and F3 respectively as the shortcut keys for generating C ++ tags. With the tag file, when editing the file, press ctrl + n and press ctrl + p to automatically complete the file.

How can I Enable Automatic completion of multiple files (in one project)? I have not studied it yet. Can someone know it?


4. automatically generate a File Header

It mainly refers to the description information such as date and author. Write a template and put it in the. vim folder. Assume It is called skeleton. Edit the following command in vimrc:


"Pre-generated File Header"

Fun! LoadSkeleton ()

Let file = $ HOME. "/. vim/skeleton"

If filereadable (file)

Exe "0 read". file

Exe "normal! G"

Endif

Exe "call CreateTime ()"

Exe "normal! G"

Endfun


"Generation time"

Fun! CreateTime ()

If line ("$")> 20

Let l = 20

Else

Let l = line ("$ ")

Endif

Exe "1,". l. "s/date:. */date:". strftime ("% Y % B % d % X"). "/e"

Endfun


"Set the file type of the preload File Header"

Au BufNewFile *. c call LoadSkeleton ()

Au BufNewFile *. h call LoadSkeleton ()

Au BufNewFile *. cpp call LoadSkeleton ()

Au BufNewFile *. sh call LoadSkeleton ()


The format of my skeleton is as follows:

/*************************************** *********

*

* Author :####

* Date: 2011 Mar 19 00:57:10 AM

* Mail :####

* Version: 1.0.0.0

* Function:

*

**************************************** *******/

A very simple header. vimrc replaces the time and automatically loads the header for files ending with. c,. cpp,. h,. sh;

5. Fold

You can use the space key to directly control the folding as follows:

Set foldenable

Set foldmethod = syntax

Nnoremap <space >@= (foldclosed (line ('.') <0 )? 'Zc': 'Z') <CR>

Basically, vim is configured with "OK", which is easy to use. It looks very comfortable to use the wide screen vsp and tree, hiahia.

My vim configuration file is uploaded to the resource. nerdtree, ctags, and omnicppcomplete are all in it (vim Version 7.3 ). Address is http://download.csdn.net/source/3107162

 

 

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.