编写期泛型
前言
Go语言,编写期泛型,仅供娱乐。
视频里的编辑器看起来像是 Sublime Text
在 VS Code 中实现
第一幕

直接照着敲

第二幕

按住
Shift
,再按方向键↑
,↓
,←
,→
,即可选中内容
按住Shift
,再按一下End
,即可选中当前光标位置到本行末尾,不包括本行结尾的换行符
按住Shift
与Ctrl
,再按一下End
,即可选中当前光标位置到文件末尾,包括文件末尾的换行符(如果有的话)

按住Shift
与Ctrl
,再按一下End

依次按下 Ctrl + C
Ctrl + V
Ctrl + V
,显然,第一次粘贴是覆盖了被选中的文本本身

VS Code 菜单栏: 选择 → 列选择模式
快捷键,按住Ctrl
与Alt
,再按方向键↑
或↓
,即可向上或向下进行列选择,此时按Esc
键可以退出列选择,返回当前行
快捷键,按住Alt
与Shift
,再使用鼠标拖动,即可进行列选择
列选择,再敲一下u
即可

第三幕


转换为大写,一般的编辑器都支持这个功能,只是 VS Code 默认没有设置快捷键
可以使用Ctrl + Shift + P
唤出命令面板,键入大写
或upper
,即可使用该功能

继续列选择,依次键入内容,并选中下一列内容(Shift + →
),使用命令转换为大写



当然,你可能注意到视频里的回退了一下,这是为了复制这些类型,用于后面的粘贴操作,在列选择模式下,选中至末尾(Shift + End
),然后按一下Ctrl + C
,复制这些类型,然后使用词首字母大写命令

第四幕


粘贴,→
,空格,粘贴

第五幕



VS Code 格式化文档
Shift + Alt + F
这里就是照着敲,然后在指定位置插入分号,视频里的操作应该是输入分号后保存(Ctrl + S
),保存操作触发了格式化文档(Go
的特性),笔者这台电脑没有安装 Go
,自然也就没有 go fmt
命令用于格式化文档,那就这样吧



在 Notepad++ 中实现
主要是一些快捷键不同,在这里列举一下吧:
- 列选择
Alt + Shift + ↑
Alt + Shift + ↓
- 转成大写
Ctrl + Shift + U
- 转成小写
Ctrl + U
- 每词转成仅首字母大写
Alt + U

Notepad++ 需要安装插件来实现格式化代码
后记
当然,Go 语言在 1.18 版本中引入了泛型。