Vim使用心得

来源:互联网 发布:在淘宝买狗狗安全吗 编辑:程序博客网 时间:2024/06/11 10:28

一、安装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: zhendongzd@163.com")         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: zhendongzd@163.com ")         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


0 0