Linux環境.vimrc 設置,自動添加Python源文件頭信息

syntax on
set ts=4
set autoindent
set smartindent
set cindent shiftwidth=4
set softtabstop=4
autocmd FileType c set expandtab
autocmd FileType cpp set expandtab
autocmd FileType php set expandtab
autocmd FileType python set expandtab
set nobackup
set backupcopy=no
set hlsearch
set incsearch

"定製的python自動添加頭信息"
function My_python_header()
    let line1 = getline(1)
    let line2 = getline(2)
    if match('\#!/', line1) == 0
        exec 1
        normal O
        call setline(1, '#!/usr/local/bin/python')
    endif
    if match("\#", line2) == 0 && (match("-", line2)  != 2 || (match("code", line2) != 2))
        exec 2
        normal O
        call setline(2, '# vim: set ts=4 et sw=4 sts=4 fileencoding=utf-8 :')
    endif
endfunction

au FileType python call My_python_header()


 

發表評論
所有評論
還沒有人評論,想成為第一個評論的人麼? 請在上方評論欄輸入並且點擊發布.
相關文章