1. 程式人生 > >vim配置入門,到豪華版vim配置

vim配置入門,到豪華版vim配置

eve ltib using xpl 決定 sil etc function single

這幾天一直研究vim的配置,許多版本總是不盡如人意,網上確實有許多優秀的文章值得參考,我的博客後面會貼上具有參考價值的博客鏈接,本文的將手把手教你配置一個功能詳盡的vim.

首先你要明白的是linux下一切皆文件的思想,因此vim的配置文件.vimrc中的內容就決定了你的vim的功能。對於新手來說首先你要做的是保證你的linux(或者是centOs)能夠連上網。我當時是這樣解決的。

流程如下

1)點擊 VM->Settings Hardware選項卡下面

2)點擊Network Adapter 設置如下圖所示,首先我們在虛擬機中將網絡配置設置成NAT,

3、進入Windows操作系統,然後右鍵點擊我們的電腦,進入到管理界面 計算機-> 管理->服務和應用程序->服務,找到如下服務進程 VMware DHCP Service, VMware NAT Service。 分別點擊右鍵->啟動

技術分享圖片

技術分享圖片

二、下載並安裝vim。

從官方網站ftp://ftp.vim.org/pub/vim/unix/中選擇一個版本下載,我這裏使用的是vim-7.4.tar.bz2centos安裝vim7.4

系統版本centos6.4;
root權限
su - root

卸載(當然你也可以不用卸載)
$ rpm -qa | grep vim
$ yum remove vim vim-enhanced vim-common vim-minimal

下載、解壓
$ wget ftp://ftp.vim.org/pub/vim/unix/vim-7.4.tar.bz2
$ wget ftp://ftp.vim.org/pub/vim/extra/vim-7.2-extra.tar.gz
$ wget ftp://ftp.vim.org/pub/vim/extra/vim-7.2-lang.tar.gz
$
$ tar jxvf vim-7.4.tar.bz2
$ tar zxvf vim-7.2-extra.tar.gz
$ tar zxvf vim-7.2-lang.tar.gz
$
$ mv vim72 vim74


安裝編譯環境
$ yum install ncurses-devel
$ yum install gcc

編譯安裝
$ cd vim74/src
$ ./configure --enable-multibyte \--with-features=huge \--disable-selinux
$ make
$ make install

測試

$ vim --version
VIM - Vi IMproved 7.4

三、接下來我們開始配置vim

1.下查看~/目錄下有沒有一個.vimrc的文件,如果沒有自己在當前目錄創建一個。

技術分享圖片

2.需要說明的是在root目錄下的.vimrc對所有用戶生效。你也可以在每個用戶下單獨配置個性化.vimrc.

3.以下是我配置的vim截圖

技術分享圖片

4.vim的功能實際上是由配置文件和插件共同決定的,這裏我提供一份配置文件源碼。大家復制到自己的.vimrc文件中即可。方法是先復制到剪貼板然後打開cd ~/.vimrc,拷貝進去就好了。保存按:

sheft+: w

退出輸入:q

5.源碼如下:

[cpp] view plain copy
  1. set helplang=cn
  2. set encoding=utf-8
  3. set cscopequickfix=s-,c-,d-,i-,t-,e-
  4. nmap <C-_>s :cs find s <C-R>=expand("<cword>")<CR><CR>
  5. nmap <C-_>g :cs find g <C-R>=expand("<cword>")<CR><CR>
  6. nmap <C-_>c :cs find c <C-R>=expand("<cword>")<CR><CR>
  7. nmap <C-_>t :cs find t <C-R>=expand("<cword>")<CR><CR>
  8. nmap <C-_>e :cs find e <C-R>=expand("<cword>")<CR><CR>
  9. nmap <C-_>f :cs find f <C-R>=expand("<cfile>")<CR><CR>
  10. nmap <C-_>i :cs find i ^<C-R>=expand("<cfile>")<CR>$<CR>
  11. nmap <C-_>d :cs find d <C-R>=expand("<cword>")<CR><CR>
  12. let g:miniBufExplMapCTabSwitchBufs = 1
  13. let g:miniBufExplMapWindowNavVim = 1
  14. let g:miniBufExplMapWindowNavArrows = 1
  15. nnoremap <silent> <F12> :A<CR>
  16. nnoremap <silent> <F3> :Grep<CR>
  17. let g:SuperTabRetainCompletionType=2
  18. let g:SuperTabDefaultCompletionType="<C-X><C-O>"
  19. " 自動語法高亮
  20. syntax on
  21. " 檢測文件類型
  22. filetype on
  23. " 檢測文件類型插件
  24. filetype plugin on
  25. " 不設定在插入狀態無法用退格鍵和 Delete 鍵刪除回車符
  26. set backspace=indent,eol,start
  27. set whichwrap+=<,>,h,l
  28. " 顯示行號
  29. set number
  30. " 上下可視行數
  31. set scrolloff=6
  32. " replace tab with space
  33. set expandtab
  34. " 設定 tab 長度為 4
  35. set tabstop=4
  36. " 設置按BackSpace的時候可以一次刪除掉4個空格
  37. set softtabstop=4
  38. " 設定 << 和 >> 命令移動時的寬度為 4
  39. set shiftwidth=4
  40. set smarttab
  41. set history=1024
  42. " 不突出顯示當前行
  43. set nocursorline
  44. " 覆蓋文件時不備份
  45. set nobackup
  46. " 自動切換當前目錄為當前文件所在的目錄
  47. set autochdir
  48. " 搜索時忽略大小寫,但在有一個或以上大寫字母時仍大小寫敏感
  49. set ignorecase
  50. set smartcase
  51. " 搜索到文件兩端時不重新搜索
  52. set nowrapscan
  53. " 實時搜索
  54. set incsearch
  55. " 搜索時高亮顯示被找到的文本
  56. set hlsearch
  57. " 關閉錯誤聲音
  58. set noerrorbells
  59. set novisualbell
  60. "set t_vb=
  61. " 不自動換行
  62. "set nowrap
  63. "How many tenths of a second to blink
  64. set mat=2
  65. " 允許在有未保存的修改時切換緩沖區,此時的修改由 vim 負責保存
  66. set hidden
  67. " 智能自動縮進
  68. set smartindent
  69. " 設定命令行的行數為 1
  70. set cmdheight=1
  71. " 顯示狀態欄 (默認值為 1, 無法顯示狀態欄)
  72. set laststatus=2
  73. "顯示括號配對情況
  74. set showmatch
  75. " 解決自動換行格式下, 如高度在折行之後超過窗口高度結果這一行看不到的問題
  76. set display=lastline
  77. " 設定配色方案
  78. colorscheme evening
  79. " 設置在狀態行顯示的信息
  80. set statusline=\ %<%F[%1*%M%*%n%R%H]%=\ %y\ %0(%{&fileformat}\ [%{(&fenc==\"\"?&enc:&fenc).(&bomb?\",BOM\":\"\")}]\ %c:%l/%L%)
  81. " 顯示Tab符
  82. set list
  83. set listchars=tab:\|\ ,trail:.,extends:>,precedes:<
  84. "啟動時不顯示 捐贈提示
  85. set shortmess=atl
  86. "blank 空白
  87. "buffers 緩沖區
  88. "curdir 當前目錄
  89. "folds 折疊
  90. "help 幫助
  91. "options 選項
  92. "tabpages 選項卡
  93. "winsize 窗口大小
  94. "slash 轉換文件路徑中的\為/以使session文件兼容unix
  95. "unix 設置session文件中的換行模式為unix
  96. set sessionoptions=blank,buffers,curdir,folds,help,options,tabpages,winsize,slash,unix,resize
  97. " 允許backspace和光標鍵跨越行邊界
  98. set whichwrap+=<,>,h,l
  99. " backspace
  100. set backspace=eol,start,indent
  101. " 可以在buffer的任何地方使用鼠標(類似office中在工作區雙擊鼠標定位)
  102. set mouse=a
  103. set selection=exclusive
  104. set selectmode=mouse,key
  105. " 在被分割的窗口間顯示空白,便於閱讀
  106. set fillchars=vert:\ ,stl:\ ,stlnc:\
  107. " 高亮顯示匹配的括號
  108. set showmatch
  109. " 匹配括號高亮的時間(單位是十分之一秒)
  110. set matchtime=5
  111. "編碼設置
  112. set enc=utf-8
  113. set fencs=utf-8,ucs-bom,shift-jis,gb18030,gbk,gb2312,cp936
  114. " set mapleader
  115. let mapleader=","
  116. nmap J 5j
  117. nmap K 5k
  118. " Ctrl+a
  119. nmap <silent> <C-a> ggvG$
  120. " 選中狀態下 Ctrl+c 復制
  121. vnoremap <c-c> "+y
  122. " Ctrl+v
  123. nmap <silent> <C-v> "+p
  124. " 窗口切換
  125. nnoremap <c-h> <c-w>h
  126. nnoremap <c-l> <c-w>l
  127. nnoremap <c-j> <c-w>j
  128. nnoremap <c-k> <c-w>k
  129. " 插入模式下上下左右移動光標
  130. inoremap <c-h> <left>
  131. inoremap <c-l> <right>
  132. inoremap <c-j> <c-o>gj
  133. inoremap <c-k> <c-o>gk
  134. " Ctrl+s
  135. " If the current buffer has never been saved, it will have no name,
  136. " call the file browser to save it, otherwise just save it.
  137. "nnoremap <silent> <C-S> :if expand("%") == ""<CR>browse confirm w<CR>else<CR>confirm w<CR>endif<CR>
  138. "imap <c-s> <c-o><c-s><CR>
  139. " Use CTRL-S for saving, also in Insert mode
  140. nmap <C-S> :update<CR>
  141. vmap <C-S> <C-C>:update<CR>
  142. imap <C-S> <C-O>:update<CR>
  143. " C++的編譯和運行
  144. "map <F6> :call CompileRunGpp()<CR>
  145. "func! CompileRunGpp()
  146. "exec "w"
  147. "exec "!g++ % -o %<"
  148. "exec "! ./%<"
  149. "endfunc
  150. map <F10> :call RunGpp()<cr>
  151. func! RunGpp()
  152. exec "w"
  153. exec "! ./%<"
  154. endfunc
  155. "vim plugin setting
  156. "======================"
  157. set tags=tags
  158. set tags+=~/.vim/my-tags/tags
  159. set tags+=~/.vim/my-tags/stl-tags
  160. set tags+=~/.vim/my-tags/sys-tags
  161. set autochdir
  162. "Update ctags
  163. map <silent> <F8> :!ctags -R --c++-kinds=+p --fields=+iaS --extra=+q<cr>
  164. """"""""""""""""""""""""""""""
  165. " Tag list (ctags)
  166. """"""""""""""""""""""""""""""
  167. "if MySys() == "windows" "設定windows系統中ctags程序的位置
  168. " let Tlist_Ctags_Cmd = ‘ctags‘
  169. "elseif MySys() == "linux" "設定Linux系統中ctags程序的位置
  170. let Tlist_Ctags_Cmd = ‘/home/sphinx/.vim/ctags-5.8/ctags‘
  171. "endif
  172. let Tlist_Show_One_File = 1 "不同時顯示多個文件的tag,只顯示當前文件的
  173. let Tlist_Exit_OnlyWindow = 1 "如果taglist窗口是最後一個窗口,則退出vim
  174. let Tlist_Use_Right_Window = 0 "在右側窗口中顯示taglist窗口
  175. let Tlist_OnlyWindow=1
  176. "let Tlist_Use_Right_Window=0
  177. "let Tlist_Sort_Type=‘name‘
  178. "let Tlist_Show_Menu=1
  179. "let Tlist_Max_Submenu_Items=10
  180. "let Tlist_Max_Tag_length=16 "20
  181. "let Tlist_Use_SingleClick=0
  182. "let Tlist_Auto_Open=0
  183. "let Tlist_Close_On_Select=0
  184. "let Tlist_File_Fold_Auto_Close=1
  185. "let Tlist_GainFocus_On_ToggleOpen=0
  186. "let Tlist_Process_File_Always=1
  187. "let Tlist_WinHeight=10
  188. "let Tlist_WinWidth=18
  189. "let Tlist_Use_Horiz_Window=0
  190. let Tlist_Auto_Highlight_Tag = 1
  191. "let Tlist_Auto_Open = 1
  192. let Tlist_Auto_Update = 1
  193. let Tlist_Close_On_Select = 0
  194. let Tlist_Compact_Format = 0
  195. let Tlist_Display_Prototype = 0
  196. let Tlist_Display_Tag_Scope = 1
  197. let Tlist_Enable_Fold_Column = 0
  198. let Tlist_File_Fold_Auto_Close = 0
  199. let Tlist_GainFocus_On_ToggleOpen = 1
  200. let Tlist_Hightlight_Tag_On_BufEnter = 1
  201. let Tlist_Inc_Winwidth = 0
  202. let Tlist_Max_Submenu_Items = 1
  203. let Tlist_Max_Tag_Length = 30
  204. let Tlist_Process_File_Always = 0
  205. let Tlist_Show_Menu = 0
  206. let Tlist_Sort_Type = "order"
  207. let Tlist_Use_Horiz_Window = 0
  208. let Tlist_WinWidth = 31
  209. map <F12> :TlistOpen<CR>
  210. "OMNI
  211. "omnicppcoplete
  212. "-- omnicppcomplete setting --
  213. set completeopt=menu,menuone
  214. let OmniCpp_MayCompleteDot = 1
  215. " autocomplete with .
  216. let OmniCpp_MayCompleteArrow = 1
  217. " autocomplete with ->
  218. let OmniCpp_MayCompleteScope = 1
  219. " autocomplete with ::
  220. let OmniCpp_SelectFirstItem = 2
  221. " select first item (but don‘t insert)
  222. let OmniCpp_NamespaceSearch = 2
  223. " search namespaces in this and included files
  224. let OmniCpp_ShowPrototypeInAbbr = 1
  225. " show function prototype in popup window
  226. let OmniCpp_GlobalScopeSearch=1
  227. let OmniCpp_DisplayMode=1
  228. let OmniCpp_DefaultNamespaces=["std"]
  229. set nocp
  230. filetype plugin on
  231. "WinManager
  232. let g:winManagerWindowLayout=‘FileExplorer|TagList‘
  233. "let g:winManagerWindowLayout=‘FileExplorer|BufExplorer|TagList‘
  234. let g:persistentBehaviour=0
  235. let g:winManagerWidth=20
  236. let g:defaultExplorer=1
  237. nmap wm :WMToggle<cr>
  238. "QuickFix
  239. nmap <F6> :cn<cr>
  240. nmap <F7> :cp<cr>
  241. "MiniBufExplorer
  242. "let g:miniBufExplMapWindowNavVim = 1
  243. "let g:miniBufExplMapWindowNavArrows = 1
  244. let g:miniBufExplModSelTarget = 1
  245. let g:miniBufExplorerMoreThanOne = 2
  246. let g:miniBufExplModSelTarget = 0
  247. let g:miniBufExplUseSingleClick = 1
  248. let g:miniBufExplMapWindowNavVim = 1
  249. let g:miniBufExplVSplit = 15 "25
  250. let g:miniBufExplSplitBelow=1
  251. let g:bufExplorerSortBy = "name"
  252. autocmd BufRead,BufNew :call UMiniBufExplorer
  253. map <leader>u :TMiniBufExplorer<cr>
  254. "AutoClose
  255. "let g:AutoClosePairs = {‘(‘: ‘)‘, ‘{‘: ‘}‘, ‘[‘: ‘]‘, ‘"‘: ‘"‘, "‘": "‘"}
  256. let g:AutoClosePairs = {‘(‘: ‘)‘, ‘{‘: ‘}‘, ‘[‘: ‘]‘, ‘"‘: ‘"‘, "‘": "‘"}
  257. """""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""
  258. " Maintainer:
  259. " " Geek SphinX
  260. " " [email protected]
  261. " "
  262. " " Version:
  263. " " 1.0 - Thu Nov 1 17:21:44 CST 2012
  264. " "
  265. " """"""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""
  266. " Sets how many lines of history VIM has to remember
  267. " set history=1024
  268. "
  269. " " Auto syntax highlight
  270. " set syntax=on
  271. "
  272. " " Check file format
  273. " filetype on
  274. "
  275. " " Enable filetype plugins
  276. " filetype plugin on
  277. " filetype indent on
  278. "
  279. " " Sets non VI compatible mode
  280. " set nocompatible
  281. "
  282. " " Set to auto read when a file is changed from the outside
  283. " set autoread
  284. "
  285. " " With a map leader it‘s possible to do extra key combinations
  286. " " like <leader>w saves the current file
  287. " let mapleader = ","
  288. " let g:mapleader = ","
  289. "
  290. " " Fast saving
  291. " nmap <leader>w :w<cr>
  292. " nmap <leader>q :q<cr>
  293. "
  294. " """""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""
  295. " " => VIM user interface
  296. " """""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""
  297. " " Replace J, K
  298. " nmap J 5j
  299. " nmap K 5k
  300. "
  301. " " Ctrl+A to select all content in visual mode
  302. " nmap <silent> <C-a> ggvG$
  303. "
  304. " " Ctrl+C to copy
  305. " vnoremap <C-c> "+y
  306. "
  307. " " Ctrl+V to paste
  308. " nmap <silent> <C-v> "+p
  309. "
  310. " " Set 7 lines to the cursor - when moving vertically using j/k
  311. " set so=7
  312. "
  313. " " Turn on the Wild menu
  314. " set wildmenu
  315. "
  316. " " Ignore compiled files
  317. " set wildignore=*.o,*~,*.pyc
  318. "
  319. " "Always show current position
  320. " set ruler
  321. "
  322. " " Height of the command bar
  323. " set cmdheight=2
  324. "
  325. " " A buffer becomes hidden when it is abandoned
  326. " set hid
  327. "
  328. " " Configure backspace so it acts as it should act
  329. " set whichwrap+=<,>
  330. " set backspace=indent,eol,start
  331. "
  332. " " Ignore case when searching
  333. " set ignorecase
  334. "
  335. " " When searching try to be smart about cases
  336. " set smartcase
  337. "
  338. " " Highlight search results
  339. " set hlsearch
  340. "
  341. " " Makes search act like search in modern browsers
  342. " set incsearch
  343. "
  344. " " Don‘t redraw while executing macros (good performance config)
  345. " set lazyredraw
  346. "
  347. " " For regular expressions turn magic on
  348. " set magic
  349. "
  350. " " Show matching brackets when text indicator is over them
  351. " set showmatch
  352. "
  353. " " How many tenths of a second to blink when matching brackets
  354. " set mat=2
  355. "
  356. " " No annoying sound on errors set noerrorbells
  357. " set novisualbell
  358. " set t_vb=
  359. " set tm=500
  360. "
  361. " " Show line number
  362. " set number
  363. "
  364. " " Highlight over 80 columns
  365. " highlight OverLength ctermbg=red ctermfg=white guibg=#592929
  366. " match OverLength /\%81v.\+/
  367. "
  368. " " Show Tab symbol
  369. " set list
  370. " set listchars=tab:\|\ ,trail:.,extends:>,precedes:<
  371. "
  372. " " Switch windows
  373. " nnoremap <C-h> <C-w>h
  374. " nnoremap <C-l> <C-w>l
  375. " nnoremap <C-j> <C-w>j
  376. " nnoremap <C-k> <C-w>k
  377. "
  378. " " Move cursor in insert mode
  379. " inoremap <C-h> <C-o>h
  380. " inoremap <C-l> <C-o>l
  381. " inoremap <C-j> <C-o>j
  382. " inoremap <C-k> <C-o>k
  383. "
  384. "
  385. " """""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""
  386. " " => Colors and Fonts
  387. " """""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""
  388. " " Enable syntax highlighting
  389. " syntax enable
  390. "
  391. " "colorscheme desert
  392. " colorscheme molokai
  393. " set background=dark
  394. "
  395. " " Set extra options when running in GUI mode
  396. " if has("gui_running"www.wanmeiyuele.cn )
  397. " set guioptions-=T
  398. " set guioptions+=e
  399. " set t_Co=256
  400. " set guitablabel=%M\ %t
  401. " endif
  402. "
  403. " " Set utf8 as standard encoding and en_US as the standard
  404. " language
  405. " set encoding=utf8
  406. "
  407. " " Use www.senta77.com/ Unix as the standard file type
  408. " set ffs=unix,dos,mac
  409. "
  410. " " Use Inconsolata as the gui font
  411. " set guifont=Inconsolata\ 15
  412. "
  413. " """""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""
  414. " => Text, tab www.fengshen157.com and indent related
  415. " """""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""
  416. " " Use spaces instead of tabs
  417. " set expandtab
  418. "
  419. " " Be smart when using tabs ;)
  420. " set www.567860.cn smarttab
  421. "
  422. " " 1 tab == 4 spaces
  423. " set shiftwidth=4
  424. " set tabstop=4
  425. "
  426. " " Linebreak on 500 characters
  427. " set lbr
  428. " set tw=500
  429. "
  430. " set ai "Auto indent
  431. " set si "Smart indent
  432. " set wrap www.huarenyl.cn/ "Wrap lines
  433. "
  434. "
  435. " """"""""""""""""""""""""""""""
  436. " " => Status line
  437. " """"""""""""""""""""""""""""""
  438. " " Always show the status line
  439. " set laststatus=2
  440. "
  441. " " Format the status line
  442. " "set statusline=\ www.hjd1956.com/ %{HasPaste()}%F%m%r%h\ %w\ \ CWD:\ %r%{getcwd()}%h\ \ \
  443. " Line:\ %l
  444. "
  445. "
  446. " """""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""
  447. " " => Mouse
  448. " """""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""
  449. " set mouse=a
  450. " set selection=www.2636666.cn exclusive
  451. " set selectmode=mouse,key
  452. "
  453. " """""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""
  454. " " => www.taohuayuan178.com Plugins
  455. " """""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""

6.插件的下載與安裝。

在~/.vim文件下有建一個doc 文件夾和plugin的文件夾。一般指導性的幫助文件會放到doc文件夾。插件的源碼等會放到plugin中。

可能用到的插件如下:此鏈接中有各種有用的插件大家可以看教程操作。

插件下載和配置:http://blog.csdn.net/wooin/article/details/1858917

用到的vim命令:http://www.thd178.com/ .net/sys/linux/52704.htm

註意事項:let g:winManagerWindowLayout=‘FileExplorer|TagList‘
nmap wm :WMToggle<www.mhylpt.com/ cr>

vim配置入門,到豪華版vim配置