Keywords: Mac OS X; Linux; vim; vimrc

" A vimrc file.

" When started as "evim", evim.vim will already have done these settings.
if v:progname =~? "evim"

" Use Vim settings, rather than Vi settings (much better!).
" This must be first, because it changes other options as a side effect
set nocompatible

" allow backspacing over everything in insert mode
set backspace=indent,eol,start

if has("vms")
    set nobackup " do not keep a backup file, use versions instead
    set backup " keep a backup file
set history=50 " keep 50 lines of command line history
set ruler " show the cursor position all the time
set showcmd " display incomplete commands
set incsearch " do incremental searching
set number
set tabstop=4 "show existing tab with 4 spaces width
set expandtab
set shiftwidth=4
set cursorline "highlight the current line

" For Win32 GUI: remove 't' flag from 'guioptions': no tearoff menu entries
" let &guioptions = substitute(&guioptions, "t", "", "g")

" Don't use Ex mode, use Q for formatting
map Q gq

" CTRL-U in insert mode deletes a lot. Use CTRL-G u to first break undo,
" so that you can undo CTRL-U after inserting a line break.
inoremap <C-U> <C-G>u<C-U>

" In many terminal emulators the mouse works just fine, thus enable it.
if has('mouse')
    set mouse=a

" Switch syntax highlighting on, when the terminal has colors
" Also switch on highlighting the last used search pattern.
if &t_Co > 2 || has("gui_running")
    syntax on
    set hlsearch

" Vim color scheme
set background=light
colorscheme desert

" Vimdiff color scheme
highlight DiffAdd cterm=bold ctermfg=10 ctermbg=17 gui=none guifg=bg guibg=Red
highlight DiffDelete cterm=bold ctermfg=10 ctermbg=17 gui=none guifg=bg guibg=Red
highlight DiffChange cterm=bold ctermfg=10 ctermbg=17 gui=none guifg=bg guibg=Red
highlight DiffText cterm=bold ctermfg=10 ctermbg=88 gui=none guifg=bg guibg=Red

" Only do this part when compiled with support for autocommands.
if has("autocmd")

    " Enable file type detection.
    " Use the default filetype settings, so that mail gets 'tw' set to 72,
    " 'cindent' is on in C files, etc.
    " Also load indent files, to automatically do language-dependent indenting.
    filetype plugin indent on

    " Put these in an autocmd group, so that we can delete them easily.
    augroup vimrcEx

        " For all text files set 'textwidth' to 80 characters.
        autocmd FileType text setlocal textwidth=80

        " When editing a file, always jump to the last known cursor position.
        " Don't do it when the position is invalid or when inside an event handler
        " (happens when dropping a file on gvim).
        " Also don't do it when the mark is in the first line, that is the default
        " position when opening a file.
        autocmd BufReadPost *
            \ if line("'\"") > 1 && line("'\"") <= line("$") |
            \ exe "normal! g`\"" |
            \ endif

    augroup END


    set autoindent " always set autoindenting on

endif " has("autocmd")

" Convenient command to see the difference between the current buffer and the
" file it was loaded from, thus the changes you made.
" Only define it when not defined already.
if !exists(":DiffOrig")
    command DiffOrig vert new | set bt=nofile | r ++edit # | 0d_ | diffthis
         \ | wincmd p | diffthis

" Save and load file in vim without login in as root
command W :execute ':w !sudo tee % > /dev/null' | :edit!

" Removes the trailing spaces
"autocmd FileType c,cpp,java,php,m,tex,gp autocmd BufWritePre %s/\s\+$//g

" Vim netrw settup
let g:netrw_liststyle = 1
let g:netrw_banner = 0
let g:netrw_browse_split = 2
let g:netrw_winsize = 24
let g:netrw_altv = 1
augroup ProjectDrawer
autocmd VimEnter * :Vexplore
augroup END

" =============================================================================
" The following configurations need third-part software to cooperate
" =============================================================================

runtime macros/matchit.vim
" source $VIMRUNTIME/macros/matchit.vim
" matlab vim
" integration of mlint code checker with :make command
autocmd BufEnter *.m compiler mlint
" use F5 to run .m file
au FileType matlab map <buffer> <silent> <F5> :w<CR>:!matlab -nodesktop -nosplash -r "try, run(which('%')), end, quit" <CR><CR>
au FileType matlab set foldmethod=syntax foldcolumn=2 foldlevel=33
" Octave
""autocmd FileType octave setlocal keywordprg=xterm\ -e\ info\ octave\ --vi-keys\ --index-search
"augroup filetypedetect
" au! BufRead,BufNewFile *.m,*.oct set filetype=octave
"augroup END

" Powerline statusline
set rtp+=/usr/lib/python3.4/site-packages/powerline/bindings/vim/
" Always show statusline
set laststatus=2
" Use 256 colors
set t_Co=256

" LanguageToolCheck
"let g:languagetool_jar='/opt/languagetool-3.6/languagetool-commandline.jar'

" Vim-LaTeX: leave the cursor where it was after compiling
let g:Tex_GotoError=0

Note: 最后一段是讲在如何配置MATLAB, 使你能够在 vim 中编程和运行matlab, 如果你们感兴趣,会在以后博文 (link) 中提及。

类似地,也有 Octave, Language Tool Check, Powerline, vim-LaTeX 等的配置。

Posted in Vim

5 thoughts on “vim: 个人vimrc 文件配置

Leave a Reply

Fill in your details below or click an icon to log in: Logo

You are commenting using your account. Log Out /  Change )

Google photo

You are commenting using your Google account. Log Out /  Change )

Twitter picture

You are commenting using your Twitter account. Log Out /  Change )

Facebook photo

You are commenting using your Facebook account. Log Out /  Change )

Connecting to %s