一、安裝vim
vim的作用在這裏不用多說,debian系統必備吧
su -
aptitude install vim
查看vim安裝路徑
dpkg -L vim
二、配置vim
如果是用戶自己使用該軟件在可以在 /home/lenovo/下創建新文件 .vimrc (如果存在則不需要重新建立),這種方法是針對用戶自己的,並不是所有的用戶
如果針對所有的用戶則可以直接修改 /etc/vim/vimrc 文件,/etc爲系統配置文件夾,修改該文件夾下的內容對所有用戶都使用,但是一般情況下不建議修改
三、打造debian系統下的 sourceinsight
1、安裝ctags
ctags是以下介紹軟件的基礎,所以首先安裝該軟件
ctags在debian下的軟件名稱爲exuberant_ctags
aptitude install exuberant_ctags
2、安裝taglist————高校瀏覽源代碼
在 taglist 官網下載文件
解壓文件
unzip software_name.zip -d new_dir
3、如果感覺taglist都是bug的話,可以嘗試使用tagbar
在tagbar官網下載文件
解壓文件
4、安裝winmanager————文件管理器和窗口管理器
在winmanager官網下載文件
解壓文件
unzip software_name.zip -d new_dir
5、安裝supertab————代碼補全
在supertab官網下載文件
解壓文件
unzip software_name.zip -d new_dir
6、安裝Srcexpl————查看函數定義
在Srcexpl官網下載
解壓文件
7、將以上解壓的文件中有關vim,txt 的上級目錄——即autoload, plugin 等,分別複製到 /usr/share/vim/vim74目錄下,不然會出錯。因爲該插件文件不完整
四、編譯~/.vimrc或者 /etc/vim/vimrc
代碼如下:
" All system-wide defaults are set in $VIMRUNTIME/debian.vim and sourced by
" the call to :runtime you can find below. If you wish to change any of those
" settings, you should do it in this file (/etc/vim/vimrc), since debian.vim
" will be overwritten everytime an upgrade of the vim packages is performed.
" It is recommended to make changes after sourcing debian.vim since it alters
" the value of the 'compatible' option.
" This line should not be removed as it ensures that various options are
" properly set to work with the Vim-related packages available in Debian.
runtime! debian.vim
" Uncomment the next line to make Vim more Vi-compatible
" NOTE: debian.vim sets 'nocompatible'. Setting 'compatible' changes numerous
" options, so any other options should be set AFTER setting 'compatible'.
" set compatible
" Vim5 and later versions support syntax highlighting. Uncommenting the next
" line enables syntax highlighting by default.
syntax on
" If using a dark background within the editing area and syntax highlighting
" turn on this option as well
" set background=dark
" Uncomment the following to have Vim jump to the last position when
" reopening a file
"if has("autocmd")
" au BufReadPost * if line("'\"") > 1 && line("'\"") <= line("$") | exe "normal! g'\"" | endif
"endif
" Uncomment the following to have Vim load indentation rules and plugins
" according to the detected filetype.
"if has("autocmd")
" filetype plugin indent on
"endif
" The following are commented out as they cause vim to behave a lot
" differently from regular Vi. They are highly recommended though.
set showcmd " Show (partial) command in status line.
set showmatch " Show matching brackets.
"set matchtime=1
set ignorecase " Do case insensitive matching
"set smartcase " Do smart case matching
"set incsearch " Incremental search
"set autowrite " Automatically save before commands like :next and :make
"set hidden " Hide buffers when they are abandoned
"set mouse=a " Enable mouse usage (all modes)
set selection=exclusive
set selectmode=mouse,key
set nu "show numberLine
set tabstop=4 "the width of tab key
set softtabstop=4 "uniform indentation
set shiftwidth=4
set nocompatible "remove the consistency problem of vi
set laststatus=2 "always display the 2st statusline
set autoread "if file was updated,autoread
filetype on "surveillance filetype
" the content which will be displayed in status line
set statusline=%F%m%r%h%w\ [FORMAT=%{&ff}]\ [TYPE=%Y]\ [POS=%l,%v][%p%%]\ %{strftime(\"%d/%m/%y\ -\ %H:%M\")}
"autocmd VimEnter * nested TrinityToggleAll can not be used
" nmap <F9> :TrinityToggleAll<CR>
""""""""""""""""""""""""""""""""""""""""""""""""""
" Tagbar Setting
""""""""""""""""""""""""""""""""""""""""""""""""""
" let g:tagbar_ctags_bin='/usr/bin/ctags'
"execute command to open tagbar when vim was open
autocmd VimEnter * nested TagbarOpen
let g:tagbar_expand=1
let g:tagbar_singleclick=1
let g:tagbar_autoshowtag=1
let g:tagbar_updateonsave_maxlines=10000
let g:tagbar_left=1
let g:tagbar_width=30
""""""""""""""""""""""""""""""""""""""""""""""""""
" Taglist Setting
""""""""""""""""""""""""""""""""""""""""""""""""""
" let Tlist_Sort_Type = "name" " sort by name
" let Tlist_Use_Left_Window = 1 " display taglist window on the left side
" let Tlist_Compart_Format = 1 " the mode fo compressinng
" let Tlist_File_Fold_Auto_Close = 0 " do not close other file's taglist
" let Tlist_Enable_Fold_Column = 0 " do not display the folding tree
" let Tlist_Exit_OnlyWindow = 1 "if the last window is taglist,then quit vim
" let Tlist_Show_Menu = 1 "display tlist menu
" let Tlist_Show_One_File=1 "only show one taglist
" let Tlist_Use_SingleClick=1 "Single Click to open Tag
" let Tlist_Auto_Update=1 " update taglist automatically
" set tags=tags;
" set autochdir
" let Tlist_Auto_Open=1 "open Taglist default
""""""""""""""""""""""""""""""""""""""""""""""""""
" SrcExpl Setting
""""""""""""""""""""""""""""""""""""""""""""""""""
"nmap <F7> :SrcExplToggle<CR>
let g:SrcExpl_winHeight = 8
let g:SrcExpl_refreshTime = 100
let g:SrcExpl_jumpKey = "<ENTER>"
let g:SrcExpl_gobackKey = "<SPACE>"
let g:SrcExpl_searchLocalDef = 1
let g:SrcExpl_isUpdateTags = 0
" // Use 'Exuberant Ctags' with '--sort=foldcase -R .' or '-L cscope.files' to
" // create/update the tags file
let g:SrcExpl_updateTagsCmd = "ctags --sort=foldcase -R ."
" // Set "<F12>" key for updating the tags file artificially
let g:SrcExpl_updateTagsKey = "<F12>"
" " // Set "<F3>" key for displaying the previous definition in the jump list
let g:SrcExpl_prevDefKey = "<F3>"
" " // Set "<F4>" key for displaying the next definition in the jump list
let g:SrcExpl_nextDefKey = "<F4>"
let g:SrcExpl_pluginList = [
\ "__Tag_List__",
\ "_NERD_tree_",
\ ]
"autocmd vimenter * SrcExplToggle
autocmd VimEnter * nested SrcExplToggle
""""""""""""""""""""""""""""""""""""""""""""""""""
" Nerd_Tree Set
""""""""""""""""""""""""""""""""""""""""""""""""""
autocmd vimenter * NERDTree
"open a NERDTree automatically when vim starts up
autocmd StdinReadPre * let s:std_in=1
autocmd VimEnter * if argc() == 0 && !exists("s:std_in") | NERDTree | endif
autocmd bufenter * if (winnr("$") == 1 && exists("b:NERDTreeType") && b:NERDTreeType == "primary") | q | endif
let g:NERDTreeWinPos="right"
let g:NERDTreeWinSize=25
let NERDTreeShowBookmarks=1
let NERDTreeMouseMode=3 "single click to file
"change default arrows
let g:NERDTreeDirArrows = 1
let g:NERDTreeDirArrowExpandable = '▸'
let g:NERDTreeDirArrowCollapsible = '▾'
""""""""""""""""""""""""""""""""""""""""""""""""""
" Automatic indentation for C programs
""""""""""""""""""""""""""""""""""""""""""""""""""
set smartindent
set autoindent
set cindent
""""""""""""""""""""""""""""""""""""""""""""""""""
"C,C++ compile and run by F5
"""""""""""""""""""""""""""""""""""""""""""""""""""
map <F5> :call CompileRunGcc()<CR>
func! CompileRunGcc()
exec "w"
if &filetype == 'c'
exec "!g++ % -o %<"
exec "!time ./%<"
elseif &filetype == 'cpp'
exec "!g++ % -o %<"
exec "!time ./%<"
elseif &filetype == 'java'
exec "!javac %"
exec "!time java %<"
elseif &filetype == 'sh'
:!time bash %
elseif &filetype == 'python'
exec "!time python2.7 %"
elseif &filetype == 'html'
exec "!firefox % &"
elseif &filetype == 'go'
exec "!time go run %"
elseif &filetype == 'mkd'
exec "!~/.vim/markdown.pl % > %.html &"
exec "!firefox %.html &"
endif
endfunc
""""""""""""""""""""""""""""""""""""""""""""""""""
"debug C,C++ F8
""""""""""""""""""""""""""""""""""""""""""""""""""
map <F8> :call Rungdb()<CR>
func! Rungdb()
exec "w"
exec "!g++ % -g -o %<"
exec "!gdb ./%<"
endfunc
""""""""""""""""""""""""""""""""""""""""""""""""
" when built .c .h .sh .java file,
" automatically insert file header
""""""""""""""""""""""""""""""""""""""""""""""""
autocmd BufNewFile *.cpp,*.[ch],*.sh,*.java exec ":call SetTitle()"
func SetTitle()
if &filetype == 'sh'
call setline(1,"\########################")
call append(line("."), "\# File Name: ".expand("%"))
call append(line(".")+1, "\# Author: Zhendong Yu")
call append(line(".")+2, "\# mail: [email protected]")
call append(line(".")+3, "\# Created Time: ".strftime("%c"))
call append(line(".")+4, "\########################")
call append(line(".")+5, "\#!/bin/bash")
call append(line(".")+6, "")
else
call setline(1, "/*********************************")
call append(line("."), " > File Name: ".expand("%"))
call append(line(".")+1, " > Author: Zhendong Yu")
call append(line(".")+2, " > Mail: [email protected] ")
call append(line(".")+3, " > Created Time: ".strftime("%c"))
call append(line(".")+4, " *****************************/")
call append(line(".")+5, "")
endif
if &filetype == 'cpp'
call append(line(".")+6, "#include<iostream>")
call append(line(".")+7, "using namespace std;")
call append(line(".")+8, "")
endif
if &filetype == 'c'
call append(line(".")+6, "#include<stdio.h>")
call append(line(".")+7, "")
endif
"after built file,
"automatically positlinged to the end of the file
"autocmd BufNewFile * normal G
endfunc
autocmd BufNewFile * normal G
""""""""""""""""""""""""""""""""""""""""""""""""""
"optimized code format F6
""""""""""""""""""""""""""""""""""""""""""""""""""
map <F6> :call FormartSrc()<CR><CR>
"define FormartSrc()
func FormartSrc()
exec "w"
if &filetype == 'c'
exec "!astyle --style=ansi -a --suffix=none %"
elseif &filetype == 'cpp' || &filetype == 'hpp'
exec "r !astyle --style=ansi --one-line=keep-statements -a --suffix=none %> /dev/null 2>&1"
elseif &filetype == 'perl'
exec "!astyle --style=gnu --suffix=none %"
elseif &filetype == 'py'||&filetype == 'python'
exec "r !autopep8 -i --aggressive %"
elseif &filetype == 'java'
exec "!astyle --style=java --suffix=none %"
elseif &filetype == 'jsp'
exec "!astyle --style=gnu --suffix=none %"
elseif &filetype == 'xml'
exec "!astyle --style=gnu --suffix=none %"
else
exec "normal gg=G"
return
endif
exec "e! %"
endfunc
""""""""""""""""""""""""""""""""""""""""""""""""""
" Automatic completion for C programs
""""""""""""""""""""""""""""""""""""""""""""""""""
:inoremap ( ()<ESC>i
:inoremap ) <c-r>=ClosePair(')')<CR>
: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
set completeopt=longest,menu
" Source a global configuration file if available
if filereadable("/etc/vim/vimrc.local")
source /etc/vim/vimrc.local
endif