如何防止 Vim 缩进括号中的换行文本

发布于 2024-07-13 07:45:47 字数 399 浏览 8 评论 0原文

这个问题困扰了我很长时间,我尽了最大的努力,但找不到解决的办法。

当我编辑文本(特别是乳胶,但这并不重要)文件时,我希望它在 80 列时自动换行。 它会这样做,除非我碰巧位于括号子句的中间,它会缩进文本,这非常烦人。 例如,这工作正常,

Here is some text... over
two lines.

但这不行。

Here is some text... (over
                      two
                      lines

如果有人能告诉我如何关闭它(仅适用于文本/乳胶文件),我将非常感激。 大概这与 C 中期望的行为有关,但我仍然不明白出了什么问题。

This has bugged me for a long time, and try as I might I can't find a way round it.

When I'm editing text (specifically latex, but that doesn't matter) files, I want it to auto-wrap at 80 columns. It does this, except if I happen to be in the middle of a parenthetical clause, it indents the text which is very annoying. For example, this works fine

Here is some text... over
two lines.

but this doesn't

Here is some text... (over
                      two
                      lines

If anyone can tell me how to turn this off (just for text/latex files) I'd be really grateful. Presumably it has something to do with the fact that this is desired behaviour in C, but I still can't figure out what's wrong.

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(6

ゝ偶尔ゞ 2024-07-20 07:45:48
:set nocindent

其他选项不执行任何操作,文件类型检测也不会更改它。

:set nocindent

The other options do nothing, and the filetype detection doesn't change it.

没企图 2024-07-20 07:45:48

您可能需要关闭三个选项:set noai、set nosi 和 setnocin(autoindent、smartindent 和 cindent)。

There are three options you may need to turn off: set noai, set nosi, and setnocin (autoindent, smartindent, and cindent).

放赐 2024-07-20 07:45:48

这可能是相关的,当从 gui 粘贴到终端窗口时,vim 无法区分粘贴模式,因此为了阻止发生任何奇怪的事情:

set paste

然后粘贴文本

set nopaste

我在尝试粘贴 xml 文本时遇到了类似的问题,它只会继续缩进。 :)

gvim,vim 的 GUI 版本,可以检测粘贴模式。

This may be related, when pasting from gui into terminal window, vim cannot distinguish paste modes, so to stop any odd things from occuring:

set paste

then paste text

set nopaste

I had similar issues trying to paste xml text, it would just keep indenting. :)

gvim, the gui version of vim, can detect paste modes.

埋情葬爱 2024-07-20 07:45:48

您可以查看自动缩进选项:

自动缩进 - ai

开始新行时从当前行复制缩进(键入
在插入模式下或使用“o”或“O”命令时)。 如果你不
在新行中输入 except 的任何内容,然后输入 or
,缩进再次被删除。 当自动缩进打开时,
格式化(使用“gq”命令或当您达到“textwidth”时
插入模式)使用第一行的缩进。 什么时候
'smartindent' 或 'cindent' 上的缩进被更改为特定
案例。 当“粘贴”选项被重置时,“自动缩进”选项被重置
放。 {与Vi的小区别:删除缩进后的时候
输入 或 ,向上或向下移动时光标位置为
删除缩进后; Vi 将光标置于已删除的某处
缩进}。

You can have a look at the autoindent option :

autoindent - ai

Copy indent from current line when starting a new line (typing
in Insert mode or when using the "o" or "O" command). If you do not
type anything on the new line except and then type or
, the indent is deleted again. When autoindent is on,
formatting (with the "gq" command or when you reach 'textwidth' in
Insert mode) uses the indentation of the first line. When
'smartindent' or 'cindent' is on the indent is changed in specific
cases. The 'autoindent' option is reset when the 'paste' option is
set. {small difference from Vi: After the indent is deleted when
typing or , the cursor position when moving up or down is
after the deleted indent; Vi puts the cursor somewhere in the deleted
indent}.

怎言笑 2024-07-20 07:45:48

来自官方 Vim 文档

文件类型插件缩进

这三个开关非常聪明
机制:

  1. 文件类型检测。 每当你开始编辑文件时,Vim 都会尝试
    弄清楚这是什么类型的文件
    是。 当你编辑“main.c”时,Vim 会
    请参阅“.c”扩展名和
    将其识别为“c”文件类型。
    当您编辑以
    "#!/bin/sh", Vim 会将其识别为
    “sh”文件类型。 文件类型
    检测用于语法
    突出显示和其他两个
    下面的项目。 请参阅|文件类型|。

  2. 使用文件类型插件文件许多不同的文件类型都可以使用
    不同的选择。 例如,
    当你编辑“c”文件时,这是非常
    将 'cindent' 选项设置为有用
    自动缩进行。 这些
    常用的选项设置有
    包含在 Vim 的文件类型插件中。
    您也可以添加自己的,请参阅
    |写入文件类型插件|。

  3. 使用缩进文件编辑程序时,可以对行进行缩进。
    通常是自动计算的。
    Vim 附带了这些缩进规则
    多种文件类型。 看
    |:文件类型缩进| 和
    'indentexpr'。

From the official Vim documentation

filetype plugin indent on

This switches on three very clever
mechanisms:

  1. Filetype detection. Whenever you start editing a file, Vim will try to
    figure out what kind of file this
    is. When you edit "main.c", Vim will
    see the ".c" extension and
    recognize this as a "c" filetype.
    When you edit a file that starts with
    "#!/bin/sh", Vim will recognize it as
    a "sh" filetype. The filetype
    detection is used for syntax
    highlighting and the other two
    items below. See |filetypes|.

  2. Using filetype plugin files Many different filetypes are edited with
    different options. For example,
    when you edit a "c" file, it's very
    useful to set the 'cindent' option to
    automatically indent the lines. These
    commonly useful option settings are
    included with Vim in filetype plugins.
    You can also add your own, see
    |write-filetype-plugin|.

  3. Using indent files When editing programs, the indent of a line can
    often be computed automatically.
    Vim comes with these indent rules for
    a number of filetypes. See
    |:filetype-indent-on| and
    'indentexpr'.

挽容 2024-07-20 07:45:48

:set noai

设置不自动缩进 tt 可能是 smartindent。 查看文档,看看是否可以找到更多内容

http://www.vim.org/ htmldoc/indent.html

:set noai

sets no auto indent tt may be smartindent though. Check out the doc and see if you can find something more

http://www.vim.org/htmldoc/indent.html

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文