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?
In Vim normal mode, you can type 0 to move to the start of the line and $ to the end of the line. The start or end of the line can be blank characters. But if you just want to move to the first or the last non-blank character of the line, you can type ^ and g_ respectively.
By default, Vim command line uses Ctrl-B to go to the beginning of the line. Execute :h cmdline-editing to see more key bindings. Save this answer.
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
.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With