mkdir -p ~/.vim/ftplugin
vi ~/.vim/ftplugin/log.vim
function DateInsert()
$delete
read !date
endfunction
:call DateInsert()
:function
中没有DateInsert():filetype
:set filetype=log
:function DateInsert
:call DateInsert()
:visual
但是每次都要手动设置filetype么?
能否自动检测呢?
:h filetype
mkdir ~/.vim/ftdetect
vi ~/.vim/ftdetect/log.vim
echo "i am a log!"
set filetype=log
vi a.log
:call DateInsert()
:nnoremap Di :call DateInsert()<CR>
nnoremap
n
normal 正常模式noremap
不再递归映射Di
可以用Di
可以刷新时间:autocmd BufWritePre *.log call DateInsert()
autocmd
是命令的名字BufWritePre
是{events} 是触发条件 保存buffer
之前*.log
是{file_pattern} 是文件模式为*.log
call DateInsert()
是{cmd} 具体执行的命令:wq
cat a.log
:autocmd
:autocmd! FileWritePre *.log
vi ~/.vim/ftplugin
:autocmd BufWritePre *.log call DateInsert()
*.log
呢*
的话log
文件DateInsert()
了:h autocmd
augroup cprograms
autocmd BufReadPost *.c *.h :set sw=4 sts=4
autocmd BufReadPost *.cpp :set sw=3 sts=3
augroup END
autocmd cprograms BufReadPost *.c *.h :set sw=4 sts=4
autocmd cprograms BufReadPost *.cpp :set sw=3 sts=3
:autocmd! cprograms
:autocmd BufReadPost *.gsm set filetype=asm
BufReadPost
是读取之后set filetype=asm
:autocmd Filetype text source ~/.vim/abbrevs.vim
Filetype text
vi a.txt
可以触发Filetype text
source ~/.vim/abbrevs.vim
:autocmd BufNewFile *.[ch] 0read ~/sktletons/skel.c
BufNewFile *.[ch]
BufNewFile
新建缓存文件的时候*.[ch]
*.c或者*.h
0read ~/sktletons/skel.c
:autocmd FileChangedShell * nested edit
touch oeasy.txt oeasy.txt.new
vi
:echo expand("%:t")
:e oeasy.txt
:echo expand("%:t")
:echo "hello i am " . expand("%:t")
autocmd BufReadPost * echo "hello i am " . expand("%:t")
:h expand
hello i am eval.txt
:doautocmd BufReadPost oeasy.txt
oeasy.txt
BufReadPost oeasy.txt
对应的自动命令autocmd
:autocmd BufReadPost *.new excute "doautocmd BufReadPost " . expand("<afile>:r")
autocmd BufReadPost *.new
*.new
打开之后对应的自动命令excute "doautocmd BufReadPost " . expand("<afile>:r")
oeasy.txt.new
oeasy.txt
打开后的自动命令excute "doautocmd BufReadPost oeasy.txt"
:autocmd BufReadPost *.log normal G
*.log
的时候normal
进入正常模式,在正常模式下:autocmd BufReadPost *.txt excute "normal ggONew entry:\<Esc>" | 1read !date
autocmd BufReadPost *.txt
excute "normal ggONew entry:\<Esc>" | 1read !date
normal ggONew entry:\<Esc>
在第一行写字|
然后执行1read !date
在第二行写日期{event}
触发事件{pattern}
文件模式{cmd}
具体执行命令{augroup}
命令组public
在java
文件里面就可以改变颜色呢??🤔