Vim 高效文本编辑技巧全解析
1. 脚本缩进设置
为了使脚本缩进更符合规范,我们可以采用方法 2,在 sh.vim 文件中添加以下代码,将制表符设置为缩进 2 个空格,这也是一些 shell 脚本编码标准中常用的设置:
setlocal tabstop=2
setlocal shiftwidth=2
setlocal expandtab
setlocal softtabstop=2
setlocal autoindent
setlocal smartindent
除了制表符设置,还包含了 autoindent 和 smartindent 设置,它们能在编写代码块时自动处理缩进。添加这些缩进设置后,我们可以在 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" ]]; then
11 echo "This shows how smartindent works."
12 echo "This shows how autoind
超级会员免费看
订阅专栏 解锁全文
11

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



