Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to prevent Vim indenting wrapped text in parentheses

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.

like image 599
Draemon Avatar asked Feb 11 '09 11:02

Draemon


People also ask

How do I turn off auto indent in vim?

To turn off autoindent when you paste code, there's a special "paste" mode. Then paste your code. Note that the text in the tooltip now says -- INSERT (paste) -- . After you pasted your code, turn off the paste-mode, so that auto-indenting when you type works correctly again.

Why does Vim auto indent?

autoindent essentially tells vim to apply the indentation of the current line to the next (created by pressing enter in insert mode or with O or o in normal mode. smartindent reacts to the syntax/style of the code you are editing (especially for C). When having it on you also should have autoindent on.

How do I fix tabs in Vim?

Fix indentation in the whole file Start in the top of a file (to get there, press gg anywhere in the file.). Then press =G , and Vim will fix the indentation in the whole file. If you don't start in the beginning of the file, it will fix indentation from current line to the bottom of file.


5 Answers

:set nocindent

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

like image 57
Draemon Avatar answered Oct 13 '22 01:10

Draemon


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

like image 31
chaos Avatar answered Oct 13 '22 02:10

chaos


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.

like image 34
Rich Avatar answered Oct 13 '22 00:10

Rich


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

like image 33
claf Avatar answered Oct 13 '22 00:10

claf


: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

like image 43
Henry B Avatar answered Oct 13 '22 00:10

Henry B