现在的位置: 首页 > 综合 > 正文

vim的安装和配置

2018年05月18日 ⁄ 综合 ⁄ 共 5498字 ⁄ 字号 评论关闭

vim的安装和配置

命令:sudo apt-get install vim

配置vim支持C/C++的自动补全

(1)安装ctags:sudo apt-get install ctags

下载插件clang:http://www.vim.org/scripts/script.php?script_id=3302

在使用clang插件之前先安装LLVM,Clang,下载:http://llvm.org/releases/ 或者 http://download.csdn.net/detail/bizhu12/5188110

clang : http://download.csdn.net/detail/bizhu12/5188097

如果下载的是源码,则将Clang的源码放到LLVM目录下的tools里,然后回到LLVM目录下执行

./configure  接着执行 make ,完成后执行 make
install
  

下载cpp_src,支持STL补全:http://www.vim.org/scripts/script.php?script_id=2358

解压后复制到/usr/include/c++中,然后使用ctags生成tags文件:

sudo ctags -R --c++-kinds=+p --fields=+iaS --extra=+q --language-force=C++ . (后面有个. ,表示当前目录)

然后退到include文件夹中

sudo ctags -R .

然后在 .vimrc文件中加入

set tags+=/usr/include/tags

set tags+=/usr/include/c++/tags

(2)安装:vim clang_complete.vmb -c 'so %' -c 'q'(使用vim打开clang_complete.vmb)

最后会在 .vim文件夹中发现clang_complete相关的文件,这个插件要比omnicomplete插件好多了

这两个插件不能同时存在,要使用omnicomplete插件的话,安装教程:http://www.cnblogs.com/xkfz007/articles/2501888.html

在vim的配置文件中 .vimrc中

复制代码
1 let g:clang_complete_auto=1
2 let g:clang_complete_copen=1
3 let g:clang_periodic_quickfix=0
4 let g:clang_snippets=1
5 let g:clang_close_preview=1
6 let g:clang_user_options='-IIncludePath'
7 let g:clang_complete_macros=1
8 let g:clang_hl_errors=1
9 let g:clang_complete_patterns=1
复制代码

 

其他配置选项可以看它的帮助文档

(3)安装SuperTab,支持Tab健补全

下载:http://www.vim.org/scripts/script.php?script_id=1643

安装:

1. Download supertab.vmb
to any directory. 

2. Open the file in vim ($ vim supertab.vmb). 

3. Source the file (:so %).

我的 .vimrc文件

复制代码
  1 set iskeyword+=_,$,@,%,#,-
  2 set t_Co=256
  3 set number
  4 "set guifont=WenQuanYi Micro Hei Mono\ 10.0
  5 "set guifontset=Microsoft\ YaHei\ 11
  6 set wildmenu
  7 set backupcopy=yes
  8 set nobackup 
  9 set autochdir
 10 set magic
 11 set autowrite
 12 "set cursorline
 13 "colorscheme desert
 14 "colorscheme   neon
 15 set showmatch
 16 " 使回格键(backspace)正常处理indent, eol, start等
 17 
 18 set backspace=indent,eol,start
 19 
 20 " 允许backspace和光标键跨越行边界
 21 autocmd FileType c,cpp map <buffer> <leader><space> :w<cr>:make<cr>
 22 
 23 language messages zh_CN.utf-8
 24 let &termencoding=&encoding
 25 set fileencodings=utf-8,gbk
 26 set fileencodings=ucs-bom,utf-8,cp936,gb18030,big5,euc-jp,euc-kr,latin1
 27 
 28 set whichwrap+=<,>,h,l
 29 " 可以在buffer的任何地方使用鼠标(类似office中在工作区双击鼠标定位)
 30 set viminfo+=!
 31 set mouse=a
 32 
 33 set nowrap
 34 set selection=exclusive
 35 
 36 set selectmode=mouse,key
 37 
 38 "不要使用vi的键盘模式,而是vim自己的
 39 
 40 set nocompatible
 41 
 42 " 设置当文件被改动时自动载入
 43  set autoread
 44 
 45 " 去掉输入错误的提示声音
 46 
 47 set noeb
 48 
 49 " 在处理未保存或只读文件的时候,弹出确认
 50 
 51 set confirm
 52 
 53 "//
 54 "在编辑过程中,在右下角显示光标位置的状态行
 55 set ruler
 56 ""默认情况下,寻找匹配是高亮度显示的,该设置关闭高亮显示
 57 set nohls
 58 
 59 "设置匹配模式,类似当输入一个左括号时会匹配相应的那个右括号
 60 set showmatch
 61 "//
 62 
 63 " 在行和段开始处使用制表符
 64 set smartcase
 65 set smartindent
 66 set smarttab
 67 set wildmode=list:full
 68 set noscrollbind
 69 set ignorecase
 70 set hlsearch
 71 filetype plugin on
 72 filetype indent on
 73 set autoread
 74 filetype plugin indent on
 75 
 76 let Tlist_Ctags_Cmd = '/usr/local/bin/ctags'
 77 
 78 
 79   
 80 nnoremap <C-TAB> :tabnext<CR>
 81 nnoremap <C-S-TAB> :tabprev<CR>
 82 nnoremap <silent><F3> :NERDTree  <CR>
 83 "保存
 84 "
 85 map <F2> :call Save()<CR>
 86 func! Save()
 87     if (&filetype=="c" || &filetype == "cpp" || &filetype=="h")
 88     exec "w"
 89     exec "!ctags -f ~/.tags -R *.c *.cpp *.h"
 90         else
 91         exec "w"
 92     endif
 93 endfunc
 94 
 95 
 96 
 97 
 98 "inoremap <F8> <C-x><C-o>
 99 set updatetime=100
100 let g:SuperTabRetainCompletionType=0
101 "let g:SuperTabDefaultCompletionType="context"
102 let g:SuperTabDefaultCompletionType="<C-X><C-U>"
103 
104 
105 au CursorMovedI,InsertLeave * if pumvisible() == 0|silent! pclose|endif
106 set completeopt=menuone,menu,longest ",preview
107 
108 let g:AutoComplPop_NotEnableAtStartup = 1
109 let g:AutoComplPop_IgnoreCaseOption=1
110 set ignorecase
111 
112 highlight Pmenu  ctermbg=white ctermfg=black
113 highlight PmenuSel ctermbg=blue ctermfg=black
114 
115 let g:clang_complete_auto=1
116 let g:clang_complete_copen=1
117 let g:clang_periodic_quickfix=0
118 let g:clang_snippets=0
119 let g:clang_close_preview=1
120 "let g:clang_use_library=1
121 let g:clang_user_options='-IIncludePath'
122 let g:clang_complete_macros=1
123 let g:clang_hl_errors=1
124 let g:clang_complete_patterns=1
125 
126 set nocp
127 
128 set nocompatible
129 filetype plugin on 
130 
131 
132 
133 " <TAB> completion.
134 inoremap <expr><TAB> pumvisible() ? "\<C-n>" : "\<TAB>"
135 map <Leader><TAB>en :NeoComplCacheEnable<CR>
136  " snippets expand key
137 "imap <silent> <C-e> <Plug>(neocomplcache_snippets_expand)
138 "smap <silent> <C-e> <Plug>(neocomplcache_snippets_expand)
139 set tags+=/usr/include/tags
140 set tags+=/usr/include/c++/tags
141 
142 "map <C-F9> :!ctags -R --c++-kinds=+p --fields=+iaS --extra=+q .<CR>
143 
144 " F5编译C/C++程序
145 
146  map <F5> :call CompileRunGcc()<CR>
147  func! CompileRunGcc()
148  exec "w"
149 " exec "!rm -f %<.o"
150  if &filetype == "c"
151      exec "!gcc -Wall -lm % -o %<.o -I . "
152  elseif &filetype == "cpp"
153          exec "!g++ -Wall -lm % -o %<.o -I .  " 
154  endif
155  "exec "!echo % 文件编译完成"
156  endfunc
157  "F6执行
158  map <F6> :call RunApp()<CR>
159  func! RunApp() 
160  exec "! ./%<.o"
161  endfunc
162  "F7调试
163  map <S-F6> :call AppDebug()<CR>
164  func! AppDebug()
165  exec "w"
166  exec "!rm -f %<.o"
167  if &filetype == "c"
168      exec "!gcc -g % -o %<.o -I . "
169  elseif &filetype == "cpp"
170      exec "!g++ -g % -o %<.o -I .  "
171  endif
172  exec "!gdb %<.o"
173  endfunc
174 
175 " 在输入模式下移动光标,彻底抛弃方向键
176 inoremap <C-h> <left>
177 inoremap <C-j> <C-o>gj
178 inoremap <C-k> <C-o>gk
179 inoremap <C-l> <Right>
180 inoremap <M-h> <C-o>b
181 inoremap <M-l> <C-o>w
182 inoremap <C-a> <Home>
183 inoremap <C-e> <End>
184 
185 
186 autocmd FileType c  map <buffer> <leader><space> :w<cr>:make<cr>
187 map <F7> :w <CR> :make<CR> :copen<CR><CR>
188 map <C-F7> :call OpenWin()<CR>
189 let g:isopen = 1
190 func! OpenWin()
191      if g:isopen == 0
192              let g:isopen = 1
193          exec "cw"
194      elseif g:isopen == 1
195          let g:isopen = 0
196          exec "cclose"
197      endif
198 endfunc
199 
200 hi Number    ctermfg=darkcyan
201 hi Comment    ctermfg=blue
复制代码

 

六 终端命令行的颜色

在.bashrc文件添加

PS1='${debian_chroot:+($debian_chroot)}\[\033[00;32m\]\u@\h\[\033[00m\]:\[\033[00;34m\]\w\[\033[00m\]\$ '

它们分别是30 (黑色)、31 (红色)、32 (绿色)、33 (黄色)、34 (蓝色)、35 ( 紫红色)、36 (青色)和37 (白色)。对于底色也有8种颜色可供选择,只需要将字体颜色的3修改为4即可,例如40、41、42、43、44、45、46、47。

【上篇】
【下篇】

抱歉!评论已关闭.