vim配置,幾個小時的奮戰

""gVim啓動窗口位置 大小
winpos  1366 768
set lines=40 columns=208 

"設定文件編碼
set fileencodings=utf-8,ucs-bom,gb18030,gbk,gb2312,cp936
syntax on

"配色風格
colorscheme desert 

"文本縮進設置
set tabstop=4
set shiftwidth=4
set autoindent
set cindent
set cinoptions={0,1s,t0,n-2,p2s,(03s,=.5s,>1s,=1s,:1s
set nu

"設置換行,自動換行"
set wrap 
set linebreak "整詞換行"

"查找替換相關設置
set hlsearch		"搜索結果高亮顯示
set incsearch       "查找單詞,自動進行搜索
set gdefault        "替換時,全部的行內匹配都被替代

"狀態欄相關設置
set statusline=[%F]%y%r%m%*%=[Line:%l/%L,Column:%c][%p%%]
set laststatus=2                         " 老是顯示狀態行 
set ruler                                " 在編輯過程當中,在右下角顯示光標位置的狀態行
"若是沒有下面這段就拷貝進來吧 雖然不知道幹什麼的
if &term=="xterm"
set t_Co=8
set t_Sb=^[[4%dm
set t_Sf=^[[3%dm
endif

"設定摺疊方式
set foldmethod=indent

"如下字符將被視爲單詞的一部分 (ASCII):
set iskeyword+=33-47,58-64,91-96,123-128

"打開文件自動跳轉到上次編輯的行
au BufReadPost * if line("'\"") > 0|if line("'\"") <= line("$")|exe("norm '\"")|else|exe "norm $"|endif|endif

"去掉兼容性"
set nocompatible

"Sets how many lines of history VIM har to remember
set history=400

"文件在外部被修改則自動保存
set autoread

" vim用戶界面
" 括號自動匹配
inoremap ( ()<ESC>i
inoremap ) <c-r>=ClosePair(')')<CR>
inoremap { {}<ESC>i
inoremap } <c-r>=ClosePair('}')<CR>
inoremap [ []<ESC>i
inoremap ] <c-r>=ClosePair(']')<CR>
inoremap < <><ESC>i
inoremap > <c-r>=ClosePair('>')<CR>

function ClosePair(char)
    if getline('.')[col('.') - 1] == a:char
        return "\<Right>"
    else
        return a:char
    endif
endf

"jsbeautify插件配置

"Turn on WiLd menu
set wildmenu

"Always show current position
set ruler

"The commandbar is 2 high
set cmdheight=2

"Show line number 顯示行號
set nu

"Set backspace
set backspace=eol,start,indent

"Bbackspace and cursor keys wrap to
set whichwrap+=<,>,h,l


"How many tenths of a second to blink
set mat=2

"下面設置peaksea配色方案
if ! has("gui_running")
    set t_Co=256
endif
" feel free to choose :set background=light for a different style
set background=dark
colors peaksea 

"編程相關的設置
filetype plugin on
filetype indent on
syn on
set showmatch     "括號匹配"
set ai!           "自動縮進
set autoindent    "自動對齊
set smartindent   "智能對齊 

" 模仿MS Windows中的保存命令: Ctrl+S
imap <C-s> <Esc>:wa<cr>i<Right>
nmap <C-s> :wa<cr>

"對NERD_commenter的設置
nmap <F3> :NERDTree  <CR>
"NERDTree Settings{
let NERDTreeWinPos ="left"						"將NERDTree的窗口設置在gvim窗口的左邊
let NERDTreeShowBookmarks=1						"當打開NERDTree窗口時,自動顯示Bookmarks
"}
"粘貼不變形
set paste
"netrw 文件瀏覽器 :e <PATH>

let g:netrw_winsize = 20   "瀏覽器寬度

"tags插件配置"
set tags=/home/twins/tags

"下面是對taglist插件的相關配置"
let Tlist_Show_One_File=1
let Tlist_Exit_OnlyWindow=1
let Tlist_Use_Right_Window=1

"下面是對windowsManager插件的相關配置"
let g:winManagerWindowLayout= 'FileExplorer|TagList'
let g:winManagerWidth = 20
let g:defaultExplorer = 0
nmap <C-w><C-b> :BottomExplorerWindow<cr>   
nmap <C-w><C-f> :FirstExplorerWindow<cr>      
nmap wm:WMToggle<cr>              

"miniBuffer插件
let g:miniBufExplMapWindowNavVim = 1
let g:miniBufExplMapWindowNavArrows = 1
let g:miniBufExplMapCTabSwitchBufs = 1
let g:miniBufExplModSelTarget = 1

"authorinfo插件的配置
let g:vimrc_author='twins'
let g:vimrc_email='jhsrcmh1992@gmail.com'
let g:vimrc_homepage='http://www.hit.edu.cn'
nmap <F4> :AuthorInfoDetect<cr> 

" ======= 編譯 && 運行 ======= "

" 編譯源文件
func! CompileCode()
	exec "w"   
	if &filetype == "c"
            exec "!gcc -Wall -std=c99 %<.c -o %<"
        elseif &filetype == "cpp"
            exec "!g++ -Wall -std=c++98 %<.cpp -o %<"
        elseif &filetype == "java"
            exec "!javac %<.java"
        elseif &filetype == "haskell"
            exec "!ghc --make %<.hs -o %<"
        elseif &filetype == "lua"
            exec "!lua %<.lua"
        elseif &filetype == "perl"
            exec "!perl %<.pl"
        elseif &filetype == "python"
            exec "!python %<.py"
        elseif &filetype == "ruby"
            exec "!ruby %<.rb"
        endif
endfunc

" 運行可執行文件
func! RunCode()
        exec "w"
        if &filetype == "c" || &filetype == "cpp" || &filetype == "haskell"
            exec "! %<.exe"
        elseif &filetype == "java"C
            exec "!java %<"
        elseif &filetype == "lua"
            exec "!lua %<.lua"
        elseif &filetype == "perl"
            exec "!perl %<.pl"
        elseif &filetype == "python"
            exec "!python %<.py"
        elseif &filetype == "ruby"
            exec "!ruby %<.rb"
		endif
endfunc

" Ctrl + C 一鍵保存、編譯
map <c-m><ESC> :call CompileCode()<cr>
imap <c-m><ESC>:call CompileCode()<cr>
vmap <c-m><ESC>:call CompileCode()<cr>

" Ctrl + R 一鍵保存、運行
map <C-r><ESC> :call RunCode()<cr>
imap <C-r><ESC>:call RunCode()<cr>
vmap <C-r><ESC>:call RunCode()<cr>

"對.vimrc配置文件的修改當即生效
autocmd! bufwritepost _vimrc source %

這個即是個人vim配置文件了。html

vim的可配置性很是強,它給人的也是一種個性化的享受。java

配置過程當中,有一個點出現問題,map過程當中,多了一個:回車不能用了。。粗心的孩子或許能找到問題所在。python

還有一個很是強大的參考:c++

https://github.com/feelinglucky/vimrc/blob/master/_vimrcgit

聽說史上最牛的vim配置文件:http://amix.dk/vim/vimrc.htmlgithub

相關文章
相關標籤/搜索