Vim 常用配置

$HOME/.vimrc 文件中加入以下配置

1
2
set expandtab
set tabstop=4

将现有文件的 Tab 转换为 空格

1
2
3
:set ts=4
:set expandtab
:%retab!
 1
 2
 3
 4
 5
 6
 7
 8
 9
10
11
12
13
14
15
16
17
18
autocmd BufNewFile *.sh exec ":call SetTitle()"
func SetTitle()
    if expand("%:e") == 'sh'
    call setline(1,"#!/bin/bash")
    call setline(2,"#")
    call setline(3,"#***************************************************************************")
    call setline(4,"# Author: liwanggui")
    call setline(5,"# Email: [email protected]")
    call setline(6,"# Date: ".strftime("%Y-%m-%d"))
    call setline(7,"# FileName: ".expand("%"))
    call setline(8,"# Description: This is a test script")
    call setline(9,"# Copyright (C): ".strftime("%Y")." All rights reserved")
    call setline(10,"#***************************************************************************")
    call setline(11,"#")
    call setline(12,"")
    endif
endfunc
autocmd BufnewFile * normal G
 1
 2
 3
 4
 5
 6
 7
 8
 9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
set expandtab
set tabstop=4
set shiftwidth=4
set ignorecase
set cursorline
set autoindent
set paste

autocmd BufNewFile *.sh exec ":call SetTitle()"
func SetTitle()
    if expand("%:e") == 'sh'
    call setline(1,"#!/bin/bash")
    call setline(2,"#")
    call setline(3,"#***************************************************************************")
    call setline(4,"# Author: liwanggui")
    call setline(5,"# Email: [email protected]")
    call setline(6,"# Date: ".strftime("%Y-%m-%d"))
    call setline(7,"# FileName: ".expand("%"))
    call setline(8,"# Description: This is a test script")
    call setline(9,"# Copyright (C): ".strftime("%Y")." All rights reserved")
    call setline(10,"#***************************************************************************")
    call setline(11,"#")
    call setline(12,"")
    endif
endfunc
autocmd BufnewFile * normal G