之前用vscode编辑器。fp快捷键能很快打印出fmt.Printf的操作。换到goland,想要实现类似的操作,需要自己设置Live templates。
<实现步骤>
(0) 打开setting->editor->live templates。然后新增一个template。
定义缩写名称(abbreviation):fp。
(1) template text输入:
fmt.Printf("$VAR2$:%+v\n",$VAR$)
(2) 编辑模板变量(edit template variables):
VAR complete()
VAR2 VAR
<实现效果>
输入fp加回车,就能输出:fmt.Printf(“:%+v\n”,)。然后你只要输入VAR的名称。VAR2就会同步VAR的值。
设置 postfix Completion实现vscode类似的fp快捷键
步骤:
1、打开 settings,并进入 Editor | General | Postfix Completion。
2、点击 Add 按钮
3、输入下面的表达式:
fmt.Printf("$EXPR$:%#v\n",$EXPR$)
$END$
参数的含义:
$EXPR$ captures the expression before the dot. //捕捉到点之前的表达式。
$END$ defines the position of the cursor after the template is expanded. //定义了模板展开后光标的位置。
<实现效果>
输入 a.fp 回车 => fmt.Printf(“a:%+v\n”,a)
官网教程:https://www.jetbrains.com/help/go/auto-completing-code.html#postfix_completion