天天看點

Vim編輯器基本設定

Vim編輯器基本設定

"設定編碼
set encoding=utf-8  
set fileencodings=ucs-bom,utf-8,cp936,gb18030,big5,euc-jp,euc-kr,latin1
set fileformats=unix,dos,mac  
set termencoding=utf-8                                                                                                                                     
set formatoptions+=m
set formatoptions+=B

"顯示行号
set ruler                       " show the current row and column "
set number                      " show line numbers "
set nowrap          
set showcmd                     " display incomplete commands "                                                                                          
set showmode                    " display current modes "
set showmatch                   " jump to matches when entering parentheses "
set matchtime=2 
"突出顯示光标
set cursorcolumn
set cursorline

"Tab制表符設定
set expandtab                   " expand tabs to spaces "
set smarttab        
set shiftround

"查找配置
set hlsearch                    " highlight searches "
set incsearch                   " do incremental searching, search as you type "
set ignorecase                  " ignore case when searching "
set smartcase                   " no ignorecase if Uppercase char present "

"其用滑鼠
set mouse=a
set selection=exclusive
set selectmode=mouse,key

"顯示括号比對
set showmatch

"設定縮進
set autoindent smartindent shiftround                                                                                                                      
set shiftwidth=4    
set tabstop=4       
set softtabstop=4                " insert mode tab and backspace use 4 spaces "

"設定粘貼格式
set paste

"顯示空格和tab鍵
set listchars=tab:>-,trail:-

"總是顯示狀态欄
set laststatus=2
"顯示光标目前位置
set ruler

set nocompatible                " don't bother with vi compatibility "
set autoread                    " reload files when changed on disk, i.e. via `git checkout` "
set shortmess=atI   
                    
set magic                       " For regular expressions turn magic on "
set title                       " change the terminal's title "
set nobackup                    " do not keep a backup file "                                                                                           
                    
set noerrorbells                " don't beep "
set visualbell t_vb=            " turn off error beep/flash "
set t_vb=           
set timeoutlen=500

"打開檔案類型檢測"
filetype on
filetype plugin on
filetype indent on

autocmd FileType python set tabstop=4 shiftwidth=4 expandtab ai
autocmd FileType ruby set tabstop=2 shiftwidth=2 softtabstop=2 expandtab ai
autocmd BufRead,BufNew *.md,*.mkd,*.markdown set filetype=markdown.mkd

autocmd BufNewFile *.py,*.sh exec ":call AutoSetFileHead()"
function! AutoSetFileHead()
    " .sh "
    if &filetype == 'sh'
        call setline(1, "\#!/bin/bash")
    endif                                                                                                                                                  
         
    " python "     
    if &filetype == 'python'
        call setline(1, "\#!/usr/bin/env python")
        call append(1, "\# encoding: utf-8")
    endif

    normal G
    normal o
    normal o
endfunc

autocmd FileType c,cpp,java,go,php,javascript,puppet,python,rust,twig,xml,yml,perl autocmd BufWritePre <buffer> :call <SID>StripTrailingWhitespaces()
fun! <SID>StripTrailingWhitespaces()
    let l = line(".")                                                                                                                                      
    let c = col(".")
    %s/\s\+$//e     
    call cursor(l, c)
endfun
           

繼續閱讀