Linux 之shell腳本設定開頭固定格式
每次進入shell都要設定開頭,很麻煩,現修改vim組態檔即可,
[root@node01 ~]vim .vimrc
將下列內容復制進檔案
set ignorecase
set cursorline
set autoindent
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: XiaoMa")
call setline(5,"#QQ: 1060389294")
call setline(6,"#Date: ".strftime("%Y-%m-%d"))
call setline(7,"#FileName: ".expand("%"))
call setline(8,"#URL: http://www.baidu.com")
call setline(9,"#Description: The test script")
call setline(10,"#Copyright (C): ".strftime("%Y")." All rights reserved")
call setline(11,"#********************************************************************")
call setline(12,"")
endif
endfunc
autocmd BufNewFile * normal G
之后新建一個shell ,開頭就會有固定的格式,

這是在root用戶下的配置,切換到用戶使用shell 可能還是什么都沒有,不過一般都是用root用戶進行機器的管理,
如果想在普通用戶上,就需要把root目錄下的.vimrc檔案拷貝到用戶家目錄下
這里我以hadoop用戶舉例
[hadoop@node01 ~]sudo cp /root/.vimrc ./
不加sudo 沒有權限進入root,這樣就把檔案復制過來了,再次創建檔案就會出現默認的格式,
轉載請註明出處,本文鏈接:https://www.uj5u.com/qita/177083.html
標籤:其他
上一篇:[網路安全]SSH遠程連接
下一篇:Linux之正則運算式
