关于ubuntu10.04
对vim配置的修正

VIM配置一个

Thomas posted @ Apr 08, 2010 10:09:55 PM in Linux with tags windows 备份 config vim linux ubuntu , 6146 阅读

        用VIM这个超级编辑器的时间应该是从去年开始的,大概记得是因为gedit在某些方面实在无法满足我的需求,但是一直认为vim过于繁琐于是就从未尝试过,后来发现scite用了一段时间感觉还不错,而且配置起来也不是很麻烦,但是时间长了还是发现scite一样不是我想要的那种编辑器,当时又很有意思的看到一篇emacs和vim的文章于是便动了邪念,把Emacs和VIM都装上了,结果vim的小巧直接让我将Emacs打入了冷宫,客观的来说Emacs也是很不错的。后来总是想见识下这个神用的编辑器(Emacs)到底如何,google了一下发现那个配置有点麻烦,向我这样的懒人就放弃了一睹其真风采的想法。于是很专一的在web上寻找vim的配置,也算是配置了个七七八八,能满足需求了,但是心理总是不爽,因为第一次的配置基本是什么都不明白装了一堆的plugin,也许是受到firefox的影响总感觉vim变的很慢,便想重新配置一次VIM但是懒散的我却始终没能拿出勇气,但是因一次不可逆的误操作,使我不得不从新配置他,配置完成了,插件基本用的不多,感觉清爽了很多,心理也不那么别扭了,正好贴出来就当是一个备份好了,有喜欢的朋友也可以拿去进行修改,让他成为你手边的一个编辑利器。

文章来源:微笑

        先贴两张图片,说明一些东西。

        GUI环境下的GVIM:

Terminal环境的VIM:

P.S. 之所以要作一些说明是因您状态栏上有一些内容不做说明的话是很让人感到匪夷所思的。

下面是整个配置文件,所用到的插件都有名称,需要的可以去官方进行下载,东西不是很多,还有这里的themes我用的是一个叫tango2的暗色themes也可以在官方得到。

另外就是ctags这个可以从这里得到,压缩包内含有两个文件,带.exe后缀的为windows环境下的版本,不带后缀的为Linux下的版本,这个ctags我是放在了运行时目录下的。

 

"""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""
" Version 1.2 - 18/04/10
" By Jack
"
" fixed:
"   add makeprg for c/c++ and java
"   add some Colorscheme
"   add a plugin(a.vim) and remove a plugin(yankring.vim)
"   Change the window's size: 83x24
"       When I used it, I think the window is very small, so I had changed it.
"   fixed the bug of the function in Compile and Run 
"       at the Version 1.1 there is a big bug, when you compile the cpp or c "language you can't call the right compiler, now I have fixed it.
"
" Plugins Included:
"	> minibufexpl.vim
"		Makes it easy to get an overview of buffers
"	> bufexplorer.vim
"		Maker if easy to switch between buffers
"	> yankring.vim(Removed)
"		A useful plugins when using the clipboard
"	> surround.vim
"		Makes it easy to work with surrounding text
"	> snipMate.vim
"		Snippets for many languages
"	> fuzzyfinde
"		Find files
"	> taglist.vim
"		This plugins must used the bin file of ctags
"	> NERD_tree.vim
"		Show a tree
"	> calendar.vim
"		A calendar
"	> javabrowser.vim
"		Look like the taglist, but only for java languange
"	> a.vim
"	    switch .h and .cpp
"
"""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""

"""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""
" The encoding setting for Windows
"""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""
set enc=utf-8
set fenc=utf-8
set fileencodings=utf-8,UCS-bom,gb18030,gb2312,gbk,latin1
set termencoding=utf-8
set ffs=unix,dos,mac
set langmenu=zh_CN.UTF-8
source $VIMRUNTIME/delmenu.vim
source $VIMRUNTIME/menu.vim
language messages zh_CN.utf-8
""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""

"""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""
" General
"""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""
" Set the num of the command line's history
set history=200

" Set the scrollbar in left
set guioptions-=r
set guioptions+=l

" Enable FileType
filetype on
" Enable filetype plugin
filetype plugin on

" Enable indent
filetype indent on

" Set to auto read when a file is changed from the outside
set autoread

" no nocompatible
set nocompatible

" Set a map leader to ','
let mapleader = ","
let g:mapleader = ","

" Set backspace config
set backspace=eol,start,indent
set whichwrap+=<,>,h,l

" Ignore case when searching
set ignorecase

" Highlight search things
set hlsearch

" Make search act like search in modern browers
set incsearch

" No backup
set nobackup

" The command line enhance
set wildmenu

" Always show current position
set ruler

" set the commandbar height
set cmdheight=1

"Change buffer -whitout saving
set hid

" Always show num lines
set nu

" Set magic on, for regular expressions
set magic

" Show matching bracets when text indicator is over them
set showmatch
set mat=2

" Enable syntax
syntax enable

" Set text, tab and indent related
set expandtab
set shiftwidth=4
set tabstop=4
set smarttab
set lbr
set tw=500
" Auto indent
set ai
" Smart indent
set si
set wrap
" C-style indent
set cindent
set cinoptions={0,1s,t0,n-2,p2s,(03s,=.5s,>1s,=1s,:1s
if &term=="xterm"
    set t_Co=8
    set t_Sb=^[[4%dm
    set t_Sf=^[[3%dm
endif
""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""

""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""
" Color and Fonts and face
""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""
" Colorscheme
if has("gui_running")
    set guioptions-=T
    set guioptions-=m
    set t_Co=256
    set background=dark
    "    colorscheme tango2
    colorscheme desertEx
    set lines=24 columns=83
else
    set background=dark
    colorscheme zellner
endif

" Fonts
if has("win32")
    set gfn=Megatops_ProCoder_1.0:h10:cANSI
else
    set gfn=DejaVuSansMono\ 9
    set shell=/bin/bash
endif

" Always show statuslin
set laststatus=2
set statusline=%<%f%h%m%r%=%b\ 0x%B\ \ %l,%c%V\ %P

set statusline=%f\%h%1*%m%r%w%0*[%{strlen(&filetype)?&filetype:'none'},%{&encoding},%{&fileformat}]\ %b\ 0x%B\ %=%(%l,%c%V%)\ %<%p%%\ [%L]\ \ %{strftime('%H:%M\ %m-%d\ %A')}
""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""

""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""
" BufExplorer plugin
""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""
let g:bufExplorerDefaultHelp=0
let g:bufExplorerShowRelativePath=1
""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""

""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""
" Minibuffer plugin
""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""
let g:miniBufExplModSelTarget = 1
let g:miniBufExplorerMoreThanOne = 2
let g:miniBufExplModSelTarget = 0
let g:miniBufExplUseSingleClick = 1
let g:miniBufExplMapWindowNavVim = 1
let g:miniBufExplSplitBelow = 0
" let g:miniBufExplVSplit=15
let g:bufExplorerSortBy = "name"

autocmd BufRead,BufNew :call UMiniBufExplorer

map <leader>u :TMiniBufExplorer<cr>:TMiniBufExplorer<cr>
""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""

""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""
"tag list
""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""
set tags=tags;
set autochdir
if has("win32")
    let Tlist_Ctags_Cmd = $vim.'\vimfiles\ctags'
else
    let Tlist_Ctags_Cmd = '~/.vim/ctags'
endif
let Tlist_Sort_Type = "name"
let Tlist_Show_Menu = 0
let Tlist_Show_One_File=1
let Tlist_Exit_OnlyWindow = 1
""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""

""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""
" NeoComplCache plugin
""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""
let g:NeoComplCache_EnableAtStartup = 1 
let g:NeoComplCache_SmartCase = 1
let g:NeoComplCache_EnableCamelCaseCompletion = 1
let g:NeoComplCache_EnableUnderbarCompletion = 1
if has("win32")
    let g:NeoComplCache_SnippetsDir = $vim.'\vimfiles\snippets'
else
    let g:NeoComplCache_SnippetsDir = '~/.vim/snippets'
endif
""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""

"""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""
" Some useful map
"""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""
" Fast saving
nmap <leader>w :w!<cr>

" Fast saving all files
map <leader>aw :brower confirm wa<cr>
" use ctrl+s to saving in insert and normal
map <c-s> <esc> :w!<cr>
imap <c-s> <esc> :w!<cr>a

" Fast selecting all
nmap <leader>a ggVG

" use ctrl+a to selecting all texts
imap <c-a> <esc> ggVG
nmap <c-a> <esc> ggVG

" Fast editing of the .vimrc
map <leader>e :e! ~/.vimrc<cr>

" When .vimrc is edited, reload it
" autocmd! bufwritepost vimrc source ~/.vimrc<cr>
map <leader>s :source ~/.vimrc<cr>

" Remove the Windows ^M -when the encodings gets messed up
noremap <leader>m mmHmt:%s/<c-v><cr>//ge<cr>'tzt'm

" Remove noh
map <F12> :%s/\s*$//g<cr>:noh<cr>''

" Show toolbar and menubar
map <silent> <F2> :if &guioptions =~# 'T' <bar>
            \set guioptions-=T <bar>
            \set guioptions-=m <bar>
            \else <bar>
            \set guioptions+=T <bar>
            \set guioptions+=m <bar>
            \endif <cr>

" Tlist and javabrowser
map <silent> <F8> :if &ft =~? 'java' <bar>
            \JavaBrowser <cr>
            \else <bar>
            \Tlist <cr>
            \endif <cr>

" The NERDTree plugin
map <F9> :NERDTree <cr>

" The Calendar plugin
map <leader>c :Calendar <cr>

" Compile
map <F5> <leader>w :call Compile() <cr>

" Run the programmer
map <F6> :call Run() <cr>
"map <F6> :! ./%< <cr>

""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""

"""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""
" The function
"""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""
" Statusline about
function! CurDir()
    let curdir = substitute(getcwd(),'/Users/amir/',"~/","g")
    return curdir
endfunction

" Compile the program   
function! Compile()
    if &ft is 'c'
        exec "w"
        exec "!gcc\ -Wall\ %\ -o\ %<"
    elseif &ft is 'cpp'
        exec "w"
        exec "!g++\ -Wall\ %\ -o\ %<"
    elseif &ft is 'java'
        exec "!javac\ -d\ .\ %"
    endif
endfunction

" Run the program
function! Run()
    if &ft is 'java'
        exec "w"
        exec "!java\ %<"
    elseif &ft is 'c'
        exec "w"
        exec "!\ ./%<"
    elseif &ft is 'cpp'
        exec "w"
        exec "!\ ./%<"
    elseif &ft is 'python'
        exec "w"
        exec "!python\ %"
    endif
endfunction
"""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""

"""""""""""""""""""""""""""About languange"""""""""""""""""""""""""""
" C/C++ Plugins Included: 
"   =>c.vim
"   =>OmniCppComplete
" JAVA Plugins Included:
"   =>JavaBrowse
"   =>javacomplete
" Python Plugins Included:
"   =>pydiction
"""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""

"""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""
" C/C++
"""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""
" make setting
au FileType c set makeprg=gcc\ -Wall\ %\ -o\ %<
au FileType cpp set makeprg=g++\ -Wall\ %\ -o\ %<
"""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""

"""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""
" Java
"""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""
" make setting
au FileType java set makeprg=javac\ -d\ .\ %

" Run the programmer
"au FileType java map <F6> :!java %< <cr>

" JavaBrowse
if has("win32")
    au FileType java let JavaBrowser_Ctags_Cmd = $vim.'\vimfiles\ctags'
else
    au FileType java let JavaBrowser_Ctags_Cmd = '~/.vim/ctags'
endif
" javacomplete
if has("autocmd")
    au FileType java set omnifunc=javacomplete#Complete
    au FileType java set completefunc=javacomplete#CompleteParamsInfo
endif
"""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""

"""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""
" Python
"""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""
" autocomplete
if has("autocmd")
    autocmd FileType python set complete+=k~/.vim/ftplugin/pydiction isk+=.,(
endif

" The syntax
au FileType python set syntax=python
"""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""

 

 

 P.S.: 需要说的是虽然这里作了windows的配置但是并未在windows环境下试用过,不保证出问题,需要的可以进行一下修改,还有就是windows环境下的字体名称是:Megatops_ProCoder_1.0.ttf。还有需要说的是那个工具栏和菜单栏,我去掉了,看着不舒服,按F2就可以显示出来,F5为编译,F6是运行,其他映射快捷操作可以看配置文件中的" Some useful map部分,最好是总览一下,因为有些映射是在其他位置的。  以上配置均在ubuntu下完成。

VIM是很好用的一个编辑器,他的操作十分的简洁,当你看不到工具栏,菜单栏而依然可以将他运用自然,不像现在流行的编辑器,非要加上很多的按钮,大眼一看好像很专业,可是一用起来,那些按钮就显得十分的反覆了,要不就是找不到,要不就是你需要的根本没有,总之上面那条工具栏根本不是用来节省时间形成快捷工作用的。

本文为原创转载请注明微笑 Creative Commons License
转载时请遵循 “署名-非商业用途-保持一致” 的创作共用协议

登录 *


loading captcha image...
(输入验证码)
or Ctrl+Enter