首页 > 代码库 > VIM之个性化配置 .vimrc

VIM之个性化配置 .vimrc

贴一个自己常用的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*Last\s*modified\s*:\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 modified\s*:/s@:.*$@\=strftime(": %Y-%m-%d %H:%M")@‘

    normal mk

    execute ‘/* Filename\s*:/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         : leeeee@gmail.com")

    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         : leeeee@gmail.com")

    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         : leeeee@gmail.com")

    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



VIM之个性化配置 .vimrc