1. $ ls -l /etc/
2. $ vim /etc/vimrc
3. 在vimrc 最后一行添加 set bs=4 // 設置tab 鍵位4格
4. 重新打開vim,生效。
另:
set nu //顯示行號
set nonu //不顯示行號
set expandtab //把tab 顯示成空格
set shiftwidth=4 //自動縮進4格
set softtabstop=4 //tab 顯示成4個空格
set ignorecase //忽略大小寫
在 /etc/vimrc 中添加一下信息后,新建test.sh 文件,按 F4 鍵就可以添加注釋信息。
69"自動添加文件的注釋信息
70 map <F4> :call TitleDet2() <cr>'s
71 function AddTitle2()
72 call append(0,"#!/bin/bash")
73 call append(1,"# Author : Philly")
74 call append(2,"# Email : ")
75 call append(3,"# Last modified: ".strftime("%Y-%m-%d %H:%M"))
76 call append(4,"# Filename : ".expand("%:t"))
77 call append(5,"# Description: ")
78 call append(6,"# ***********************************/")
79 echohl WarningMsg | echo "Successful in adding the copyright." | echohl None
80 endf
81 " 更新最近修改時間和文件名
82 function UpdateTitle2()
83 normal m' " vim 內置的標記位置的方法
84 execute '/# *Last modified:/s@:.*$@\=strftime(":\t%Y-%m-%d %H:%M")@'
85 normal ''
86 normal mk
87 execute '/# *Filename:/s@:.#$@\=":\t\t".expand("%:t")@'
88 execute "noh"
89 normal 'k
90 echohl WarningMsg | echo "Successful in updating the copyright." | echoh l None
91 endfunction
92
93 "判斷如果前10行代碼里面,是否有 Last modified 這個單詞,
94 "如果沒有的話,代表沒有添加過作者信息,需要新添加;
95 "如果有的話,那么只需要更新即可
96 function TitleDet2()
97 let n=1
98 "默認為添加
99 while n < 7
100 let line = getline(n)
101 if line =~ '^\#s*\S*Last\smodified:\S*.*$'
102 call UpdateTitle2()
103 return
104 endif
105 let n = n + 1
106 endwhile
107 call AddTitle2()
108 endfunction