"basic
"常用编程一些基本设置
syntax enable
set nocompatible
set backspace=2 "设置退格键可用
set tabstop=4<span style="white-space:pre"> </span>"设置制表符(tab键)的宽度
set softtabstop=4 "设置软制表符的宽度
set shiftwidth=4 " (自动) 缩进使用的4个空格
set autoindent " 设置自动对齐(缩进):即每行的缩进值与上一行相等;使用 noautoindent 取消设置
set cindent<span style="white-space:pre"> </span>" 使用 C/C++ 语言的自动缩进方式
set number<span style="white-space:pre"> </span>"显示行数<span style="white-space:pre"> </span>
"set showmatch "自动匹配模式 不好用又延迟
set mouse=a "Enable mouse usage (all modes) "使用鼠标
set ruler<span style="white-space:pre"> </span>" 标尺,用于显示光标位置的行号和列号,逗号分隔。每个窗口都有自己的标尺。如果窗口有状态行,标尺在那里显示。否则,它显示在屏幕的最后一行上。
set showcmd<span style="white-space:pre"> </span>" 命令行显示输入的命令
set incsearch<span style="white-space:pre"> </span>" 输入字符串就显示匹配点
set sidescroll=1
set whichwrap=b,s,<,>,[,] "光标从行首和行末时可以跳到另一行去
set foldmethod=marker
filetype off
"插件管理器Bundle 以及基本的插件
"
"Brief help
":BundleList - list configured bundles
":BundleInstall(!) - install(update) bundles
":BundleSearch(!) foo - search(or refresh cache first) for foo
":BundleClean(!) - 删除插件首先要在.vimrc中注释掉插件相应的行,再运行该命令
"see :h vundle for more details or wiki for FAQ
""NOTE: comments after Bundle command are not allowed..
set rtp+=~/.vim/bundle/vundle/
call vundle#rc()
Bundle 'gmarik/vundle'
Bundle 'Lokaltog/vim-powerline'
Bundle 'scrooloose/nerdtree.git'
Bundle 'altercation/vim-colors-solarized'
Bundle 'plasticboy/vim-markdown'
Bundle 'taglist.vim'
Bundle 'L9'
Bundle 'ctrlp.vim'
Bundle 'Command-T'
Bundle 'vim-coffee-script'
filetype plugin indent on
"solarized
"使用vim_solarized配色 官方文档给的配置
set t_Co=16
set background=dark
let g:solarized_termtrans = 1
colorscheme solarized
"powerline
set laststatus=2
let g:Powerline_symbols = 'fancy'
"--ctags setting--
"" 按下F5重新生成tag文件,并更新taglist
"常用tag命令用法:
"Ctrl+] 跳到当前光标下单词的标签
"Ctrl+O 返回上一个标签
"Ctrl+T 返回上一个标签
"按F5重新更新ctag的数据库标志 我自己用的是linux kernel版本作为查询linux底层API函数用
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+=~/arm/linux-2.6.24.7/tags "add new tags file(刚刚生成tags的路径,在ctags -R 生成tags文件后,不要将tags移动到别的目录,否则ctrl+]时,会提示找不到源码文件)
"set tags+=./tags 表示在当前工作目录下搜索tags文件
"set tags+=~/arm/linux-2.6.24.7/ tags表示在搜寻tags文件的时候,也要搜寻~/arm/linux-2.6.24.7/文件夹下的tags文件。
"-- WinManager setting --
let g:winManagerWindowLayout='FileExplorer|TagList' " 设置我们要管理的插件
"let g:persistentBehaviour=0 " 如果所有编辑文件都关闭了,退出vim
"设置快捷键 wm(小写) 打开文件管理串口
nmap wm :WMToggle<cr>
"taglist
"
let Tlist_Ctags_Cmd='ctags' "因为我们放在环境变量里,所以可以直接执行
let Tlist_Show_One_File = 1
let Tlist_Exit_OnlyWindow = 1 "当taglist是最后一个分割窗口时,自动推出vim
let Tlist_File_Fold_Auto_Close=1 "非当前文件,函数列表折叠隐藏
"let Tlist_Use_Right_Window = 1 "设置窗口位置在右
"let Tlist_Use_Left_Window = 1 "设置窗口位置在左
"let Tlist_GainFocus_On_ToggleOpen = 1
let Tlist_Process_File_Always=1 "实时更新tags
let Tlist_Ctags_Cmd = '/usr/bin/ctags' "ctag安装目录引用
"let Tlist_Auto_Open=1
let g:winManagerWidth = 30 "设置窗口宽度
set autochdir
"设置快捷键tl打开或者关闭taglist窗口
map <silent> <leader>tl :TlistToogle<cr>
"markdown-mode
let g:vim_markdown_folding_disabled=1
"keymap
"let mapleader = ','
"nnoremap <leader>d :NERDTreeToggle<CR>
"nnoremap <leader>t :TlistToggle<CR>
"nnoremap <leader>c :CtrlP<CR>
"-- omnicppcomplete setting --
"常用快捷键
"Ctrl+P 向前切换成员
"Ctrl+N 向后切换成员
"Ctrl+E 表示退出下拉窗口, 并退回到原来录入的文字
"Ctrl+Y 表示退出下拉窗口, 并接受当前选项
"其他补全方式:
"Ctrl+X Ctrl+L 整行补全
"Ctrl+X Ctrl+N 根据当前文件里关键字补全
"Ctrl+X Ctrl+K 根据字典补全
"Ctrl+X Ctrl+T 根据同义词字典补全
"Ctrl+X Ctrl+I 根据头文件内关键字补全
"Ctrl+X Ctrl+] 根据标签补全
"Ctrl+X Ctrl+F 补全文件名
"Ctrl+X Ctrl+D 补全宏定义
"Ctrl+X Ctrl+V 补全vim命令
"Ctrl+X Ctrl+U 用户自定义补全方式
"Ctrl+X Ctrl+S 拼写建议
"
"" 按下F3自动补全代码,注意该映射语句后不能有其他字符,包括tab;否则按下F3会自动补全一些乱码
imap <F3> <C-X><C-O>
" 按下F2根据头文件内关键字补全
imap <F2> <C-X><C-I>
set completeopt=menu,menuone " 关掉智能补全时的预览窗口
let OmniCpp_MayCompleteDot = 1 " autocomplete with .
let OmniCpp_MayCompleteArrow = 1 " autocomplete with ->
let OmniCpp_MayCompleteScope = 1 " autocomplete with ::
let OmniCpp_SelectFirstItem = 2 " select first item (but don't insert)
let OmniCpp_NamespaceSearch = 2 " search namespaces in this and included files
let OmniCpp_ShowPrototypeInAbbr = 1 " show function prototype in popup window
let OmniCpp_GlobalScopeSearch=1 " enable the global scope search
let OmniCpp_DisplayMode=1 " Class scope completion mode: always show all members
"let OmniCpp_DefaultNamespaces=["std"]
let OmniCpp_ShowScopeInAbbr=1 " show scope in abbreviation and remove the last column
let OmniCpp_ShowAccess=1
set tags+=/usr/include/c++/tags
" -- MiniBufferExplorer --
"let g:miniBufExplMapWindowNavVim = 1 "按下Ctrl+h/j/k/l,可以切换到当前窗口的上下左右窗口
"let g:miniBufExplMapWindowNavArrows = 1 "按下Ctrl+箭头,可以切换到当前窗口的上下左右窗口
"let g:miniBufExplMapCTabSwitchBufs = 1 "启用以下两个功能:Ctrl+tab移到下一个buffer并在当前窗口打开;Ctrl+Shift+tab移到上一个buffer并在当前窗口打开;ubuntu好像不支持
"let g:miniBufExplMapCTabSwitchWindows = 1 "启用以下两个功能:Ctrl+tab移到下一个窗口;Ctrl+Shift+tab移到上一个窗口;ubuntu好像不支持
"let g:miniBufExplModSelTarget = 1 "不要在不可编辑内容的窗口(如TagList窗口)中打开选中的buffer
"let g:bufExplorerMaxHeight=30
"let g:miniBufExplorerMoreThanOne=1
" 常用命令
" <Tab> 移到上一个buffer
" <Shift-Tab> 移到下一个buffer
" <Enter> 打开光标所在的buffer
" d 删除光标所在的buffer
"-- QuickFix setting --
" c编译模块,一个自动编译连接运行程序
"------------------------------------------------------------------------------
" < 判断操作系统是否是 Windows 还是 Linux >
"------------------------------------------------------------------------------
if(has("win32") || has("win64") || has("win95") || has("win16"))
let g:iswindows = 1
else
let g:iswindows = 0
endif
"------------------------------------------------------------------------------
" < 判断是终端还是 Gvim >
"------------------------------------------------------------------------------
if has("gui_running")
let g:isGUI = 1
else
let g:isGUI = 0
endif
"------------------------------------------------------------------------------
" < 编译、连接、运行配置 >
"------------------------------------------------------------------------------
" F9 一键保存、编译、连接存并运行
map <F7> :call Run()<CR>
imap <F7> <ESC>:call Run()<CR>
" Ctrl + F7 一键保存并编译
map <c-F7> :call Compile()<CR>
imap <c-F7> <ESC>:call Compile()<CR>
" Ctrl + F10 一键保存并连接
map <c-F10> :call Link()<CR>
imap <c-F10> <ESC>:call Link()<CR>
let s:LastShellReturn_C = 0
let s:LastShellReturn_L = 0
let s:ShowWarning = 1
let s:Obj_Extension = '.o'
let s:Exe_Extension = '.exe'
let s:Sou_Error = 0
let s:windows_CFlags = 'gcc\ -fexec-charset=gbk\ -Wall\ -g\ -O0\ -c\ %\ -o\ %<.o'
let s:linux_CFlags = 'gcc\ -Wall\ -g\ -O0\ -c\ %\ -o\ %<.o'
let s:windows_CPPFlags = 'g++\ -fexec-charset=gbk\ -Wall\ -g\ -O0\ -c\ %\ -o\ %<.o'
let s:linux_CPPFlags = 'g++\ -Wall\ -g\ -O0\ -c\ %\ -o\ %<.o'
func! Compile()
exe ":ccl"
exe ":update"
if expand("%:e") == "c" || expand("%:e") == "cpp" || expand("%:e") == "cxx"
let s:Sou_Error = 0
let s:LastShellReturn_C = 0
let Sou = expand("%:p")
let Obj = expand("%:p:r").s:Obj_Extension
let Obj_Name = expand("%:p:t:r").s:Obj_Extension
let v:statusmsg = ''
if !filereadable(Obj) || (filereadable(Obj) && (getftime(Obj) < getftime(Sou)))
redraw!
if expand("%:e") == "c"
if g:iswindows
exe ":setlocal makeprg=".s:windows_CFlags
else
exe ":setlocal makeprg=".s:linux_CFlags
endif
echohl WarningMsg | echo " compiling..."
silent make
elseif expand("%:e") == "cpp" || expand("%:e") == "cxx"
if g:iswindows
exe ":setlocal makeprg=".s:windows_CPPFlags
else
exe ":setlocal makeprg=".s:linux_CPPFlags
endif
echohl WarningMsg | echo " compiling..."
silent make
endif
redraw!
if v:shell_error != 0
let s:LastShellReturn_C = v:shell_error
endif
if g:iswindows
if s:LastShellReturn_C != 0
exe ":bo cope"
echohl WarningMsg | echo " compilation failed"
else
if s:ShowWarning
exe ":bo cw"
endif
echohl WarningMsg | echo " compilation successful"
endif
else
if empty(v:statusmsg)
echohl WarningMsg | echo " compilation successful"
else
exe ":bo cope"
endif
endif
else
echohl WarningMsg | echo ""Obj_Name"is up to date"
endif
else
let s:Sou_Error = 1
echohl WarningMsg | echo " please choose the correct source file"
endif
exe ":setlocal makeprg=make"
endfunc
func! Link()
call Compile()
if s:Sou_Error || s:LastShellReturn_C != 0
return
endif
let s:LastShellReturn_L = 0
let Sou = expand("%:p")
let Obj = expand("%:p:r").s:Obj_Extension
if g:iswindows
let Exe = expand("%:p:r").s:Exe_Extension
let Exe_Name = expand("%:p:t:r").s:Exe_Extension
else
let Exe = expand("%:p:r")
let Exe_Name = expand("%:p:t:r")
endif
let v:statusmsg = ''
if filereadable(Obj) && (getftime(Obj) >= getftime(Sou))
redraw!
if !executable(Exe) || (executable(Exe) && getftime(Exe) < getftime(Obj))
if expand("%:e") == "c"
setlocal makeprg=gcc\ -o\ %<\ %<.o
echohl WarningMsg | echo " linking..."
silent make
elseif expand("%:e") == "cpp" || expand("%:e") == "cxx"
setlocal makeprg=g++\ -o\ %<\ %<.o
echohl WarningMsg | echo " linking..."
silent make
endif
redraw!
if v:shell_error != 0
let s:LastShellReturn_L = v:shell_error
endif
if g:iswindows
if s:LastShellReturn_L != 0
exe ":bo cope"
echohl WarningMsg | echo " linking failed"
else
if s:ShowWarning
exe ":bo cw"
endif
echohl WarningMsg | echo " linking successful"
endif
else
if empty(v:statusmsg)
echohl WarningMsg | echo " linking successful"
else
exe ":bo cope"
endif
endif
else
echohl WarningMsg | echo ""Exe_Name"is up to date"
endif
endif
setlocal makeprg=make
endfunc
func! Run()
let s:ShowWarning = 0
call Link()
let s:ShowWarning = 1
if s:Sou_Error || s:LastShellReturn_C != 0 || s:LastShellReturn_L != 0
return
endif
let Sou = expand("%:p")
let Obj = expand("%:p:r").s:Obj_Extension
if g:iswindows
let Exe = expand("%:p:r").s:Exe_Extension
else
let Exe = expand("%:p:r")
endif
if executable(Exe) && getftime(Exe) >= getftime(Obj) && getftime(Obj) >= getftime(Sou)
redraw!
echohl WarningMsg | echo " running..."
if g:iswindows
exe ":!%<.exe"
else
if g:isGUI
exe ":!gnome-terminal -e ./%<"
else
exe ":!./%<"
endif
endif
redraw!
echohl WarningMsg | echo " running finish"
endif
endfunc
" 按下F6,执行make clean
"map <F6> :make clean<CR><CR><CR>
" 按下F7,执行make编译程序,并打开quickfix窗口,显示编译信息
"map <F7> :make<CR><CR><CR> :copen<CR><CR>
" 按下F8,光标移到上一个错误所在的行
map <F8> :cp<CR>
" 按下F9,光标移到下一个错误所在的行
map <F9> :cn<CR>
" 以上的映射是使上面的快捷键在插入模式下也能用
"imap <F6> <ESC>:make clean<CR><CR><CR>
"imap <F7> <ESC>:make<CR><CR><CR> :copen<CR><CR>
imap <F8> <ESC>:cp<CR>
imap <F9> <ESC>:cn<CR>
转载请注明原文地址: https://ju.6miu.com/read-1125977.html