Fork me on GitHub

daydayup863

人生就像一杯茶,不会苦一辈子,但总会苦一阵子。

0%

Linux vim常用配置

列举一些有用的vim小功能, 能有效的避免重复造轮子.

安装 spf-13-vim

1
2
3
https://github.com/spf13/spf13-vim

https://learnku.com/articles/24924

vim新建文件时, 按F4既可以添加作者信息

~/.vimrc中追加如下内容

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
27
28
29
30
31
32
33
34
35
36
37
38
39
40
"进行版权声明的设置
""添加或更新头
map <F4> :call TitleDet() <cr>'s
function AddTitle()
call append(0,"/********************************************************")
call append(1,"* Author : ×××")
call append(2,"* Email : ×××@×××.com")
call append(3,"* Last modified : ".strftime("%Y-%m-%d %H:%M"))
call append(4,"* Filename : ".expand("%:t"))
call append(5,"* Description : ")
call append(6,"*********************************************************/")
echohl WarningMsg | echo "Successful in adding the copyright." | echohl None
endf
"更新最近修改时间和文件名
function UpdateTitle()
normal m'
execute '/# *Last modified:/s@:.*$@\=strftime(":\t%Y-%m-%d %H:%M")@'
normal ''
normal mk
execute '/# *Filename:/s@:.*$@\=":\t\t".expand("%:t")@'
execute "noh"
normal 'k
echohl WarningMsg | echo "Successful in updating the copy right | echohl None
endfunction
"判断前10行代码里面,是否有Last modified这个单词,
"如果没有的话,代表没有添加过作者信息,需要新添加;
"如果有的话,那么只需要更新即可
function TitleDet()
let n = 1
"默认为添加
while n < 7
let line = getline(n)
if line =~ '^\#\s*\S*Last\smodified:\S*.*$'
call UpdateTitle()
return
endif
let n = n+1
endwhile
call AddTitle()
endfunction

vim新建python或者bash脚本添加固定内容

~/.vimrc中追加如下内容

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
autocmd BufNewFile *.py,*.sh, exec ":call SetTitle()"
let $author_name = "taot.jin"
let $author_email = "taot.jin@q.com"

func SetTitle()
if &filetype == 'sh'
call setline(1,"\###################################################################")
call append(line("."), "\# File Name: ".expand("%"))
call append(line(".")+1, "\# Author: ".$author_name)
call append(line(".")+2, "\# mail: ".$author_email)
call append(line(".")+3, "\# Created Time: ".strftime("%c"))
call append(line(".")+4, "\#=============================================================")
call append(line(".")+5, "\#!/bin/bash")
call append(line(".")+6, "")
else
call setline(1,"\###################################################################")
call append(line("."), "\# File Name: ".expand("%"))
call append(line(".")+1, "\# Author: ".$author_name)
call append(line(".")+2, "\# mail: ".$author_email)
call append(line(".")+3, "\# Created Time: ".strftime("%c"))
call append(line(".")+4, "\#=============================================================")
call append(line(".")+5, "\#!/usr/bin/python")
call append(line(".")+5, "\# -*- coding: utf-8 -*-")
"call append(line(".")+6, "")
endif
endfunc

vim新建markdown文件时添加固定信息

~/.vimrc中追加如下内容

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
autocmd BufNewFile *.md, exec ":call SetTitle1()"
let $author_name = "taot.jin"
let $author_email = "taot.jin@q.com"

func SetTitle1()
call setline(1,"---")
call append(line("."), "title: ")
call append(line(".")+1, "date: ".strftime("%Y-%m-%d"))
call append(line(".")+2, "tags: ")
call append(line(".")+3, "categories: ")
call append(line(".")+4, "top: ")
call append(line(".")+5, "description: ")
call append(line(".")+6, "password: ")
call append(line(".")+7, "")
call append(line(".")+8, "---")
endfunc
-------------本文结束感谢您的阅读-------------
听说,打赏我的人都找到了真爱

欢迎关注我的其它发布渠道