VIM之個性化配置 .vimrc

  • 2019 年 10 月 5 日
  • 筆記

貼一個自己常用的vim配置文件,個人感覺這些配置不算臃腫,對於運維已經基本夠用了。

set shortmess=atI

syntax enable

syntax on "設置語法高亮

set nu

set ruler

set autoindent "設置自動縮進

set nocompatible

set magic

set confirm

set history=1000

set cursorline

highlight Comment ctermfg=lightblue guifg=darkblue

set cindent

set tabstop=4

set softtabstop=4 "設置軟製表符4個空格

set shiftwidth=4 "設置縮進4個空格

set smarttab

set si

set wrap

set showmatch

set smartindent

set cin

set hlsearch

au BufReadPost * if line("'"") > 0|if line("'"") <= line("$")|exe("norm '"")|else|exe "norm $"|endif|endif

" 下面是添加F4熱鍵自動加入文件頭注釋信息

map <F4> ms:call AddAuthor()<cr>'S

function AddAuthor()

    let n=1

    while n < 11

        let line = getline(n)

        if line=~'[#]*s**s*S*Lasts*modifieds*:s*S*.*$'

        call UpdateTitle()

        return

    endif

    let n = n + 1

    endwhile

    if &filetype == 'sh'

        call AddTitleForShell()

    elseif &filetype == 'python'

        call AddTitleForPython()

    else

        call AddTitleForC()

    endif

endfunction

function UpdateTitle()

    normal m'

    execute '/* Last modifieds*:/s@:.*$@=strftime(": %Y-%m-%d %H:%M")@'

    normal mk

    execute '/* Filenames*:/s@:.*$@=": ".expand("%:t")@'

    execute "noh"

    normal 'k

    echohl WarningMsg | echo "Successful in updating the copy right." |echohl None

endfunction

"" add comment for C

function AddTitleForC()

    call append(0,"/**********************************************************")

    call append(1," * Author        : Lee")

    call append(2," * Email         : [email protected]")

    call append(3," * Create time   : ".strftime("%Y-%m-%d %H:%M"))

    call append(4," * Last modified : ".strftime("%Y-%m-%d %H:%M"))

    call append(5," * Filename      : ".expand("%:t"))

    call append(6," * Description   : ")

    call append(7," * *******************************************************/")

    echohl WarningMsg | echo "Successful in adding the copyright." | echohl None

endfunction

"" add comment for Python

function AddTitleForPython()

    call append(0,"#!/usr/bin/python")

    call append(1,"# -*- coding: UTF-8 -*-")

    call append(2,"")

    call append(3,"# **********************************************************")

    call append(4,"# * Author        : Lee")

    call append(5,"# * Email         : [email protected]")

    call append(6,"# * Create time   : ".strftime("%Y-%m-%d %H:%M"))

    call append(7,"# * Last modified : ".strftime("%Y-%m-%d %H:%M"))

    call append(8,"# * Filename      : ".expand("%:t"))

    call append(9,"# * Description   : ")

    call append(10,"# **********************************************************")

    echohl WarningMsg | echo "Successful in adding the copyright." | echohl None

endfunction

"" add conment for shell

function AddTitleForShell()

    call append(0,"#!/bin/bash")

    call append(1,"# **********************************************************")

    call append(2,"# * Author        : Lee")

    call append(3,"# * Email         : [email protected]")

    call append(4,"# * Create time   : ".strftime("%Y-%m-%d %H:%M"))

    call append(5,"# * Last modified : ".strftime("%Y-%m-%d %H:%M"))

    call append(6,"# * Filename      : ".expand("%:t"))

    call append(7,"# * Description   : ")

    call append(8,"# **********************************************************")

endfunction