如何防止括号中的Vim缩进包装文本

时间:2022-08-04 20:33:49

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

当我正在编辑文本(特别是乳胶,但没关系)文件时,我希望它在80列自动换行。它是这样做的,除非我碰巧在括号子句的中间,它缩进了非常烦人的文本。例如,这很好

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.

如果有人能告诉我如何关闭它(仅用于文本/乳胶文件),我将非常感激。据推测,它与C中所需的行为有关,但我仍然无法弄清楚什么是错的。

6 个解决方案

#1


:set nocindent

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

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

#2


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

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

#3


You can have a look at the autoindent option :

您可以查看autoindent选项:

autoindent - ai

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}.

在开始新行时键入当前行的缩进(在“插入”模式下键入或使用“o”或“O”命令时)。如果您没有在新行上键入任何内容,然后键入或,则会再次删除缩进。当autoindent打开时,格式化(使用“gq”命令或在插入模式下达到'textwidth'时)使用第一行的缩进。当“smartindent”或“cindent”出现时,缩进在特定情况下会发生变化。设置'paste'选项后,'autoindent'选项被重置。 {与Vi的小差异:在输入时删除缩进或者,向上或向下移动时的光标位置是在删除的缩进之后; Vi将光标放在已删除的缩进中的某个位置}。

#4


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

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

set paste

then paste text

然后粘贴文字

set nopaste

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

我有类似的问题试图粘贴xml文本,它只会保持缩进。 :)

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

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

#5


From the official Vim documentation

来自官方的Vim文档

filetype plugin indent on

filetype插件缩进

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|.

    文件类型检测。每当你开始编辑文件时,Vim会试着弄清楚这是什么类型的文件。当您编辑“main.c”时,Vim将看到“.c”扩展名并将其识别为“c”文件类型。当您编辑以“#!/ bin / sh”开头的文件时,Vim会将其识别为“sh”文件类型。文件类型检测用于语法突出显示,以及下面的其他两个项目。见| 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|.

    使用filetype插件文件使用不同的选项编辑许多不同的文件类型。例如,当您编辑“c”文件时,设置“cindent”选项以自动缩进行非常有用。这些常用的选项设置包含在文件类型插件中的Vim中。您也可以添加自己的,请参见| 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'.

    使用缩进文件编辑程序时,通常可以自动计算行的缩进。 Vim附带了许多文件类型的缩进规则。见|:filetype-in​​dent-on |和'indentexpr'。

#6


:set noai

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

设置没有自动缩进tt可能是聪明的。查看文档,看看是否可以找到更多内容

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

#1


:set nocindent

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

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

#2


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

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

#3


You can have a look at the autoindent option :

您可以查看autoindent选项:

autoindent - ai

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}.

在开始新行时键入当前行的缩进(在“插入”模式下键入或使用“o”或“O”命令时)。如果您没有在新行上键入任何内容,然后键入或,则会再次删除缩进。当autoindent打开时,格式化(使用“gq”命令或在插入模式下达到'textwidth'时)使用第一行的缩进。当“smartindent”或“cindent”出现时,缩进在特定情况下会发生变化。设置'paste'选项后,'autoindent'选项被重置。 {与Vi的小差异:在输入时删除缩进或者,向上或向下移动时的光标位置是在删除的缩进之后; Vi将光标放在已删除的缩进中的某个位置}。

#4


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

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

set paste

then paste text

然后粘贴文字

set nopaste

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

我有类似的问题试图粘贴xml文本,它只会保持缩进。 :)

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

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

#5


From the official Vim documentation

来自官方的Vim文档

filetype plugin indent on

filetype插件缩进

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|.

    文件类型检测。每当你开始编辑文件时,Vim会试着弄清楚这是什么类型的文件。当您编辑“main.c”时,Vim将看到“.c”扩展名并将其识别为“c”文件类型。当您编辑以“#!/ bin / sh”开头的文件时,Vim会将其识别为“sh”文件类型。文件类型检测用于语法突出显示,以及下面的其他两个项目。见| 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|.

    使用filetype插件文件使用不同的选项编辑许多不同的文件类型。例如,当您编辑“c”文件时,设置“cindent”选项以自动缩进行非常有用。这些常用的选项设置包含在文件类型插件中的Vim中。您也可以添加自己的,请参见| 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'.

    使用缩进文件编辑程序时,通常可以自动计算行的缩进。 Vim附带了许多文件类型的缩进规则。见|:filetype-in​​dent-on |和'indentexpr'。

#6


:set noai

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

设置没有自动缩进tt可能是聪明的。查看文档,看看是否可以找到更多内容

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