为vim添加UltiSnips插件
使用Vundle来安装插件,将下面两个插件放入.vimrc中Vundle配置位置
1
2
|
Plugin 'SirVer/ultisnips' " Track the engine.
Plugin 'honza/vim-snippets' " Snippets are separated from the engine. Add this if you want them:
|
配置快捷键来启动代码片段以及代码片段内跳转位置,注意需要与YouCompleteMe的启动键位不一样
1
2
3
|
let g:UltiSnipsExpandTrigger="<leader><tab>"
let g:UltiSnipsJumpForwardTrigger="<c-j>"
let g:UltiSnipsJumpBackwardTrigger="<c-k>"
|
为.md文件与.json文件增加代码片段
代码片段所在的位置为~/.vim/bundle/vim-snippets/UltiSnips,我们需要为.md以及.json格式文件增加代码片段.
为.md增加的代码片段如下:
1
2
3
4
5
6
7
8
|
snippet head "hugo blog head" b
---
title: ${1:title}
date: ${2:`date +%Y-%m-%d`}
tags: $3
---
$0
endsnippet
|
通过输入head,然后使用即可生成代码片段.
为.json增加的代码片段如下:
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
|
snippet ss-s "shadowsocks-server" b
{
"server": ${1:"216.189.174.152"},
"local_address": "127.0.0.1",
"local_port": 1080,
"port_password":
{
${2:"443"}: ${3:"shadowpassword1"},
${4:"1080"}:${5:"shadowpassword2"}
},
"timeout": 600,
"method": ${6:"aes-256-cfb"},
"fast_open": true
}$0
endsnippet
snippet ss-c "shadowsocks-client" b
{
"server":${1:"216.189.174.152"},
"local_address":"127.0.0.1",
"local_port":1080,
"server_port":${2:443},
"password":${3:"shadowpassword1"},
"timeout":300,
"method":${4:"aes-256-cfb"}
}$0
endsnippet
|
这样通过使用ss-c,和ss-s就可以很容易的配置ss了.
2018-10-19更新
更改在markdown.snippets中增加的head,为了自动填写文件名称
写Python代码的时候给文件前面加描述的时候突然想起来得给markdown加一个自动填写文件名.
1
2
3
4
5
6
7
8
|
snippet head "hugo blog head" b
---
title: ${1:`!p snip.rv = snip.basename`}
date: ${2:`date +%Y-%m-%d`}
tags: $3
---
$0
endsnippet
|
参考
Meet UltiSnips
UltiSnips 让 Vim 飞起来