vim 中的哪些设置可以抵消 smartindent 拒绝缩进 shell 脚本中的 # 注释? [英] What setting in vim counteracts smartindent's refusal to indent # comments in shell scripts?

查看:11
本文介绍了vim 中的哪些设置可以抵消 smartindent 拒绝缩进 shell 脚本中的 # 注释?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我最近开始使用 vim 7(以前是 vim 6)和 smartindent 设置.在大多数情况下,它运行良好,尽管我习惯于在大括号后输入制表符,这几乎适得其反.

然而,有一种疯狂的行为.在编辑 shell 脚本时,我尝试在当前缩进级别创建注释,但是 smartindent 与它无关.它坚持注释必须在 0 级(无缩进).更糟糕的是,它会破坏右移('>>' 和朋友),因此它们不起作用.这是彻头彻尾的不服从,我想知道解决它的最佳方法是什么?

(我也不热衷于 smartindent 关于在 if 之后缩进 then 的想法.)

首选解决方案将使我免于手动抨击 - 我很懒惰.一种选择是在编辑 shell 脚本时关闭 smartindent(其余部分保持开启)".另一种选择是关于如何找到 smartindent 的控制脚本以及如何编辑以更改我不喜欢的特征的指南.最后一个选项(我不需要关于如何做的建议 - 只是暗示它是恢复理智的最佳或唯一方法)是不设置 smartindent.

我看到了关于(PHP 和)烦人的 vim 缩进规则"的模糊相关问题;它没有为我提供直接的答案,尽管其中提到的 cindent 和相关项目实际上是答案的一部分.

解决方案

找到缩进文件,(例如我系统上的/usr/share/vim/vim71/indent/sh.vim)

这一行看起来像问题:

<前>setlocal indentkeys-=:,0#

也许您可以在 .vimrc 中修复此问题或手动加载自定义缩进文件.

它看起来比我想象的要复杂,但也许缩进文件中有一些你需要修复的特殊设置.

第二次看起来我完全错了,请查看:

输入哈希后恢复缩进

howto-configure-vim-to-not-put-comments-at-the-beginning-of-lines-while-editing

I recently started using vim 7 (previously vim 6) and the smartindent setting. For the most part, it works well, though I'm so used to typing a tab after an open brace that it is almost counter-productive.

However, there is one piece of maniacal behaviour. When editing a shell script, I try to create a comment at the current indent level, but smartindent will have nothing to do with it. It insists that the comment must be at level 0 (no indent). What's worse, it breaks shift-right ('>>' and friends) so that they do not work. This is outright insubordination, and I'd like to know what's the best way to fix it?

(I'm also not keen on smartindent's ideas about indenting then after if.)

Preferred solutions will save me manual bashing - I'm being lazy. One option would be 'turn off smartindent when editing shell scripts (leave it on for the rest)'. Another option would be guidelines on how to find the control script for smartindent and what to edit to change the characteristics I don't like. The final option (which I don't need advice on how to do - just the hint that it is the best, or only, way to restore sanity) is to leave smartindent unset.

I saw the vaguely related question on "(PHP and) annoying vim unindent rules"; it doesn't provide me with the direct answer, though maybe the cindent and related items mentioned in there are in fact part of the answer.

解决方案

Find the indent file, (e.g. /usr/share/vim/vim71/indent/sh.vim on my system)

This line looks like the problem:

setlocal indentkeys-=:,0#

Perhaps you can fix this in your .vimrc or load a custom indent file manually.

edit: It looks more complicated than I thought, but maybe there is something specifically set in the indenting file that you would need to fix.

2nd edit: Looks like I was completely wrong, Check out:

Restoring indent after typing hash

or

howto-configure-vim-to-not-put-comments-at-the-beginning-of-lines-while-editing

这篇关于vim 中的哪些设置可以抵消 smartindent 拒绝缩进 shell 脚本中的 # 注释?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆