Vim高效文本编辑技巧全解析
1. 脚本缩进设置
在编写脚本时,合适的缩进设置能让代码更加清晰易读。我们可以通过在 sh.vim 文件中添加以下内容,将制表符设置为缩进 2 个空格,这也是一些 shell 脚本编码标准中常用的设置:
setlocal tabstop=2
setlocal shiftwidth=2
setlocal expandtab
setlocal softtabstop=2
setlocal autoindent
setlocal smartindent
除了制表符设置, autoindent 和 smartindent 选项也很有用。 autoindent 会重复上一行的缩进,而 smartindent 会为特定的程序结构(如函数和 if 语句)提供缩进。添加这些设置后,我们可以在 shell 脚本中添加以下内容进行测试:
1 #! /bin/bash
2
3 # This is a shell script to demonstrate features in vim.
4 # It doesn't really do anything, it just shows what we can do.
5
6 # Constants
7 A=1
8 B=2
9
10 if [[ "$A" == "$B" ]
超级会员免费看
订阅专栏 解锁全文
29

被折叠的 条评论
为什么被折叠?



