Vim option for automatically inserting ">" at start of line

vim

Solution

Got it! To `.vimrc`, add

set formatoptions+=o

This automatically inserts the "comment leader" (character sequence indicating a comment, or, in the case of literate Haskell, the Haskell code) at the start of the line.

For more information on the options accepted by `formatoptions`, type `:help fo-table`.

Problem

Suppose I have a file `test.c` containing the following: ``` // line 1 // line 2 ``` If I open this file in Vim and navigate to the first line in normal mode, then type `o`, I get the following: ``` // line 1 // // line 2 ``` Now suppose I have a file `test.lhs` (literate Haskell) containing ``` > data X = A | B > data Y = C | D ``` If I open this file and navigate to the first line in normal mode, then type `o`, I get ``` > data X = A | B > data Y = C | D ``` Question: How can I make Vim automatically insert `>` at the start of the line for the `.lhs` file, similar to how `//` is automatically inserted for the `.c` file?

Original source