Installation and configuration of VIM for Linux applications (CentOS)

Source: Internet
Author: User
Tags define function eol set background

Installation of 1.vim

#yum Search Vim//view VIM related software information

#yum install-y vim*//Online installation vim

Configuration of 2.vim

(1) ~/.viminfo  

In Vim, Vim is automatically recorded and saved in the ~/.viminfo file. This is to facilitate the next processing, such as: Vim when you open the file, the cursor will automatically appear in the last location. The original searched string, the newly opened file is automatically highlighted. the ~/.viminfo file is automatically generated by the system.

(2)/ETC/VIMRC

The VIMRC file is a VIM environment settings file. The overall vim setting is in the/ETC/VIMRC file. Modifying the/ETC/VIMRC file is not recommended , and each user can set up vim in the user's root directory and create a new ~/.VIMRC. Vim has more configuration options.

The default settings for VIMRC are commented as follows:

If V:lang =~ "utf8$" | | V:lang =~ "utf-8$"
Set Fileencodings=ucs-bom,utf-8,latin1
endif

Set nocompatible "Use Vim defaults (much better!)
Set Bs=indent,eol,start backspacing over everything in insert mode
' Set AI ' always set autoindenting on
"set Backup" Keep a backup file
set viminfo= ' 20,\ "read/write A. viminfo file, don ' t store more
" than Es of registers
set history=50 "Keep lines of command line history
Set ruler" show the cursor position all the Time

"Only does this" when the compiled with the support for Autocommands
if have ("Autocmd")
Augroup redhat
AUTOCMD!
"in text files, all limit the width of text to characters
" Autocmd bufread *.txt set tw=78
"when Editin G A file, the last cursor position
autocmd bufreadpost *
\ If line ("' \" ") > 0 && Line (" "\" ") <= Line (" $ ") |
\ EXE "normal! G ' \ "" |
\ endif
"Don ' t write swapfile on most commonly used directories for NFS mounts or USB sticks
Autocmd BUFNEWF ile,bufreadpre/media/*,/run/media/*,/mnt/* set Directory=~/tmp,/var/tmp,/tmp
"Start with spec file template
Autocmd bufnewfile *.spec 0r/usr/share/vim/vimfiles/template.spec
augroup END
endif

If has ("Cscope") && filereadable ("/usr/bin/cscope")
Set Csprg=/usr/bin/cscope
Set csto=0
Set CST
Set Nocsverb
"Add any database in current directory
If Filereadable ("Cscope.out")
CS Add $PWD/cscope.out
"Else add database pointed to by environment
ElseIf $CSCOPE _db! = ""
CS Add $CSCOPE _db
endif
Set Csverb
endif

"Switch syntax highlighting on while the terminal has colors
"Also switch on highlighting, the last used search pattern.
If &t_co > 2 | | Has ("gui_running")
Syntax on
Set Hlsearch
endif

FileType plugin on

If &term== "Xterm"
Set T_co=8
Set T_SB=DM
Set T_SF=DM
endif

"Don T wake up system with blinking cursor:
"Http://www.linuxpowertop.org/known.php
Let &guicursor = &guicursor. ", A:blinkon0"

(3) ~/.VIMRC

"""""""""""""""""""
The show related
"""""""""""""""""""
"Set Shortmess=ati" does not display the reminder to help Ugandan children when it starts
"Winpos 5 5" Setting window position
"Set lines=40 columns=155" setting window size
"Set Nu" displays line numbers
Set go= "Do not graph button
"Color asmanian2" setting background theme
Set Guifont=courier_new:h10:cansi "Setting font
"Syntax on" syntax highlighting
Autocmd insertleave * se nocul "highlight when moving forward with light
Autocmd insertenter * se cul "highlight when moving forward with light
"Set ruler" display ruler
Set showcmd "Input command displayed, see clearly
The height of the "set cmdheight=1" command line (under the status line), set to 1
"Set Whichwrap+=<,>,h,l" allows backspace and cursor keys to span line boundaries (not recommended)
The "set scrolloff=3" cursor moves to the top and bottom of buffer to maintain 3 lines of distance
Set Novisualbell "Do not blink (do not understand)
Set statusline=%f%m%r%h%w\ [format=%{&ff}]\ [type=%y]\ [pos=%l,%v][%p%%]\%{strftime (\ "%d/%m/%y\-\%H:%M\")} " What the status line displays
Set Laststatus=1 "Start Display status line (1), always show status line (2)
Set foldenable "Allow folding
Set foldmethod=manual "Manual folding
"Set Background=dark" background using black
Set nocompatible "Remove nasty about VI consistency mode, avoid some bugs and limitations of previous versions
The show Chinese help
If version >= 603
Set HELPLANG=CN
Set Encoding=utf-8
endif
The Set color scheme
"ColorScheme Murphy
The font
"If (Has (" gui_running "))
"Set guifont=bitstream\ vera\ sans\ mono\ 10
"EndIf
Set fencs=utf-8,ucs-bom,shift-jis,gb18030,gbk,gb2312,cp936
Set Termencoding=utf-8
Set Encoding=utf-8
Set fileencodings=ucs-bom,utf-8,cp936
Set Fileencoding=utf-8
"""""""""""""""""""""""""
"" "" "New File title" "" "" "" ""
"Create a new. c,.h,.sh,.java file, insert the file header automatically
Autocmd bufnewfile *.cpp,*. [Ch],*.sh,*.java exec]: Call Settitle () "
"" Define function Settitle, insert file header automatically
Func Settitle ()
"If the file type is. sh file
if &filetype = = ' sh '
Call Setline (1, "\#########################################################################")
Call Append ("."), "\# File Name:". Expand ("%"))
Call Append (".") +1, "\# author:test")
Call Append (".") +2, "\# Mail: <a href=" Mailto:[email protected] ">[email protected]</a>")
Call Append (".") +3, "\# Created Time:". Strftime ("%c"))
Call Append (".") +4, "\#########################################################################")
Call Append (".") +5, "\#!/bin/bash")
Call Append (".") +6, "")
Else
Call Setline (1, "/*************************************************************************")
Call Append ("."), "> File Name:" Expand ("%"))
Call Append (".") +1, "> author:test")
Call Append (".") +2, "> Mail: <a href=" Mailto:[email protected] ">[email protected]</a>")
Call Append (".") +3, "> Created time:". Strftime ("%c"))
Call Append (".") +4, "************************************************************************/")
Call Append (".") +5, "")
endif
if &filetype = = ' cpp '
Call Append (".") +6, "#include <iostream>")
Call Append (".") +7, "using namespace std;")
Call Append (".") +8, "")
endif
if &filetype = = ' C '
Call Append (".") +6, "#include <stdio.h>")
Call Append (".") +7, "")
endif
"Automatically navigates to the end of a file after you create a new file
Autocmd Bufnewfile * Normal G
Endfunc
"""""""""""""""""""""""""""""""
The keyboard command
"""""""""""""""""""""""""""""""
Nmap <leader>w:w!<cr>
Nmap <leader>f:find<cr>
"Map Select all + Copy Ctrl + A
Map <C-A> Ggvgy
map! <C-A> <esc>ggvgy
Map <F12> gg=g
"CTRL + C copy in selected state
Vmap <C-c> "+y
"Go empty line
Nnoremap <F2>:g/^\s*$/d<cr>
The Compare files
Nnoremap <C-F2>: Vert diffsplit
The new label
Map <M-F2>:tabnew<cr>
"Lists the current directory files
Map <F3>: Tabnew .<cr>
"Open the tree-like file directory
Map <C-F3> \be
"C,c++ Press F5 to compile and run
Map <F5>: Call COMPILERUNGCC () <CR>
func! COMPILERUNGCC ()
Exec "W"
if &filetype = = ' C '
Exec "!g++%-O%<"
EXEC "! ./%<"
ElseIf &filetype = = ' cpp '
Exec "!g++%-O%<"
EXEC "! ./%<"
ElseIf &filetype = = ' java '
Exec "!javac%"
Exec "!java%<"
ElseIf &filetype = = ' sh '
:!. /%
endif
Endfunc
"Commissioning of the C,c++
Map <F8>: Call Rungdb () <CR>
func! Rungdb ()
Exec "W"
Exec "!g++%-g-o%<"
Exec "!gdb ./%<"
Endfunc
""""""""""""""""""""""""
"" Utility settings
""""""""""""""""""""""""
"Set to automatically load when files are changed
Set Autoread
"Quickfix mode
Autocmd FileType c,cpp map <buffer> <leader><space>:w<cr>:make<cr>
The Code completion
Set Completeopt=preview,menu
The Allow plugins
FileType plugin on
The Share clipboard
Set clipboard+=unnamed
"Never Back Up
Set Nobackup
The Make Run
: Set makeprg=g++\-wall\ \%
The Auto Save
Set Autowrite
Set ruler "Open the status bar ruler
Set Cursorline "highlight when moving forward
Set Magic
Set Guioptions-=t "Hide the toolbar
Set guioptions-=m "Hide Menu bar
"Set statusline=\%<%f[%1*%m%*%n%r%h]%=\%y\%0 (%{&fileformat}\%{&encoding}\%c:%l/%L%) \
"Sets the information displayed in the status line
Set foldcolumn=0
Set Foldmethod=indent
Set foldlevel=3
Set foldenable "Start folding
"Don't use VI's keyboard mode, but Vim's own
Set nocompatible
The syntax highlighting
Set Syntax=on
"Remove the sound of input errors
Set Noeb
"When working with unsaved or read-only files, pop-up confirmation
Set confirm
The Auto Indent
Set Autoindent
Set Cindent
The width of the TAB key
Set tabstop=4
"Unified Indentation is 4
Set softtabstop=4
Set shiftwidth=4
"Do not use spaces instead of tabs
Set Noexpandtab
Use tabs at the beginning of rows and segments
Set Smarttab
The Display line number
Set number
"Number of historical records
Set history=1000
"Prohibit generation of temporary files
Set Nobackup
Set Noswapfile
"Search ignores case
Set ignorecase
"Search for verbatim Fugauliang
Set Hlsearch
Set Incsearch
"In-line substitution
Set Gdefault
The Encoding settings
Set Enc=utf-8
Set fencs=utf-8,ucs-bom,shift-jis,gb18030,gbk,gb2312,cp936
The Language settings
Set LANGMENU=ZH_CN. UTF-8
Set HELPLANG=CN
"My status line displays the contents (including file type and decoding)
"Set statusline=%f%m%r%h%w\ [format=%{&ff}]\ [type=%y]\ [pos=%l,%v][%p%%]\%{strftime (\"%d/%m/%y\-\%H:%M\ ")}
"Set statusline=[%f]%y%r%m%*%=[line:%l/%l,column:%c][%p%%]
"Always Show status lines
Set laststatus=2
The height of the command line (under the status line), which defaults to 1, here is 2
Set cmdheight=2
"Detect file Types
FileType on
"Load file type plug-in
FileType plugin on
"Loading related indentation files for a specific file type
FileType indent on
"Save Global variables
Set viminfo+=!
"Words with the following symbols are not separated by line breaks
Set iskeyword+=_,$,@,%,#,-
The number of pixel lines inserted by the word putting
Set linespace=0
"Command-line auto-complete operation in enhanced mode
Set Wildmenu
"Make the Back bar (BACKSPACE) normal handling indent, EOL, start, etc.
Set backspace=2
"Allow backspace and cursor keys to span line boundaries
Set Whichwrap+=<,>,h,l
"You can use the mouse anywhere in the buffer (similar to the workspace in office, double-click the mouse to navigate)
Set Mouse=a
Set selection=exclusive
Set Selectmode=mouse,key
"By using: Commands command, tell us which line of the file has been changed
Set report=0
"Display whitespace between split windows for easy reading
Set Fillchars=vert:\, Stl:\, Stlnc:\
"Highlight matching parentheses
Set Showmatch
"Matches the time of the parentheses highlighting (in a very second)
Set matchtime=1
"Keep 3 lines away when the cursor moves to the top and bottom of the buffer
Set scrolloff=3
"Provides automatic indentation for C programs
Set Smartindent
"Highlight normal TXT file (requires Txt.vim script)
Au bufread,bufnewfile * Setfiletype txt
"Auto-complete
: Inoremap (() <esc>i
: Inoremap) <c-r>=closepair (') ') <CR>
: inoremap {{<cr>}<esc>o
: Inoremap} <c-r>=closepair ('} ') <CR>
: Inoremap [[]<esc>i
: Inoremap] <c-r>=closepair ('] ') <CR>
: Inoremap "" "<esc>i
: Inoremap ' <esc>i
function! Closepair (char)
If Getline ('. ') [Col ('. ')-1] = = A:char
Return "\<right>"
Else
Return A:char
endif
Endfunction
FileType plugin indent on
"Open File type detection, add this sentence can be used to complete the smart
Set Completeopt=longest,menu
""""""""""""""""""""""""""""""""
"The setting of the Ctags
""""""""""""""""""""""""""""""""
Let Tlist_sort_type = "name" "Sort by name"
Let Tlist_use_right_window = 1 "Display window on the right
Let Tlist_compart_format = 1 "compression mode
Let Tlist_exist_onlywindow = 1 "Kill buffer if only one buffer,kill window is killed
Let Tlist_file_fold_auto_close = 0 "Do not close other files of tags
Let Tlist_enable_fold_column = 0 "Do not show collapsed tree
Autocmd FileType Java Set tags+=d:\tools\java\tags
"Autocmd FileType h,cpp,cc,c set Tags+=d:\tools\cpp\tags
"Let tlist_show_one_file=1" does not display the tag of multiple files at the same time, only displays the current file's
The Set tags
Set Tags=tags
The Set Autochdir
"""""""""""""""""""""""""
"Other Stuff
"""""""""""""""""""""""""
The default open TagList
Let Tlist_auto_open=1
""""""""""""""""""""""""""""""
"Tag list (ctags)
""""""""""""""""""""""""""""""""
Let Tlist_ctags_cmd = '/usr/bin/ctags '
Let Tlist_show_one_file = 1 "does not display the tag of multiple files at the same time, only displays the current file's
Let Tlist_exit_onlywindow = 1 "If the TagList window is the last window, exit vim
Let Tlist_use_right_window = 1 "Displays the TagList window in the right window
"General settings for the MINIBUFEXPL plugin
Let G:minibufexplmapwindownavvim = 1
Let G:minibufexplmapwindownavarrows = 1
Let G:minibufexplmapctabswitchbufs = 1
Let G:minibufexplmodseltarget = 1

Installation and configuration of VIM for Linux applications (CentOS)

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.