Questions tagged [formatting]

Questions about how to format a file with vim - this includes, but is not limited to, foldings, indents, wrappings, and so on.

Filter by
Sorted by
Tagged with
66 votes
3 answers
26k views

How can I get vim to stop putting comments in front of new lines?

I'm editing my .vimrc file, and I am including comments. When I have a comment like this: " example comment And then hit enter at the end of the line after finishing the comment, the next line is ...
Greg's user avatar
  • 857
20 votes
4 answers
4k views

How to set up Vim to work with one sentence per line?

I'm currently writing a lot of plain text (and LaTeX with minimal formatting in paragraphs), and it would be nice if I could set up vim to keep each sentence (for simplicity, text terminated by a '. ',...
Alex's user avatar
  • 1,293
29 votes
5 answers
3k views

How can I reformat a multi-line string in Vim when using the Python filetype?

Let's assume I am editing some Python code in Vim that looks a bit like: myobj.myfunc("Some string parameter that goes on and on and on and on and sometimes doesn't" "split ...
Andrew Ferrier's user avatar
10 votes
4 answers
1k views

Line number specific text-width setting

I use gvim for writing emails and use tw=72 to break long lines. Now I also edit basic mail headers in the same document, e.g. I am adding recipients to my mail. Now with tw=72 it also breaks every ...
mxmehl's user avatar
  • 261
18 votes
3 answers
7k views

automatically rewrap lines when writing markdown in VIM

Very often, I write markdown in VIM, and there will be paragraphs in those markdown. To help my editing, I setup my Vim to wrap a line on 80 chars. It works nice if I just keep typing, but the problem ...
Jason Hu's user avatar
  • 1,345
1 vote
1 answer
207 views

formatoptions for hybrid (short markup + long paragraphs) content

I am trying to write my PhD thesis in vim using LaTeX So the documents will have two distinct types of content - markups that are relatively short, and paragraph text that is rather long. \begin{...
Dr Krishnakumar Gopalakrishnan's user avatar
18 votes
2 answers
5k views

Why Vim sets max text width to 79 instead of 80?

I'm a little puzzled about some default values in Vim. In particular, for gq{motion}, is said that [...] If the 'textwidth' option is 0, the formatted line length is the screen width (with a maximum ...
Atcold's user avatar
  • 343
6 votes
2 answers
993 views

How do I make Vim respect Markdown headers when formating text?

I want to use the combination gggqG to go to the top of the file and format the whole file from there, so that it fits into my 80 col textwidth border. But when I do, vim ignores my markdown headers. ...
toogley's user avatar
  • 547
5 votes
1 answer
456 views

How can I make text formatting ignore concealed characters?

Question Working with text and various markup languages in Vim I have recently experimented with the conceal feature to hide some of the more verbose markup. I switch conceal off when writing and ...
jjaderberg's user avatar
  • 3,439
5 votes
1 answer
208 views

Text formatting CVS-friendly

I have seen this very interesting article: http://dustycloud.org/blog/vcs-friendly-patchable-document-line-wrapping/ --- basically it is a suggestion for hard-breaking lines of text (for example, in ...
Rmano's user avatar
  • 748
5 votes
1 answer
244 views

Is there a way to push existing text left while inserting (e.g., insert right-aligned text)?

In insert mode, typing normally moves the cursor right and pushes text to the right of the cursor farther to the right on the line. I am typing some right-aligned text and am wondering - is there a ...
cxw's user avatar
  • 964
4 votes
1 answer
1k views

How to prevent vim-jsx from mangling my indentation?

Looks like the issue is caused by vim-jsx. Given: componentDidMount: function() { ▐$.ajax({ }); I press enter to move $.ajax onto a new line and the top line folds as well: componentDidMount: ...
firedev's user avatar
  • 2,362
4 votes
1 answer
461 views

Using `gq` to correctly wrap function arguments

Consider editing the code foo = long_function_name(var_one, var_two, var_three, var_four) where the textwidth 'column' occurs just after var_two. I would like to be able to press gqq on the line ...
rwolst's user avatar
  • 405
3 votes
1 answer
111 views

How do I move by paragraphs, but end up *in* the paragraph?

So I often use repeated invocations of gqip to re-wrap paragraphs of text or comments. Unfortunately, the quickest way I've memorized for moving between paragraphs, }, lands me between them: Qui⁁ut ...
ELLIOTTCABLE's user avatar
3 votes
1 answer
525 views

Vim "gq" command doesn't recognize Haskell-style comments

I have a Haskell file on VIM with a Haskell-style comment block: When I select that comment block on visual mode... And press gq, I expected VIM to format my comment to something like: But instead, ...
MaiaVictor's user avatar
3 votes
1 answer
157 views

How to avoid indenting after a line that starts with a number?

I use Vim to write longer sequences of body text. It does automatic formatting, which generally works nicely. If I have a sentence that ends in a number, say a date or a year, and that number happens ...
ravnsgaard's user avatar
3 votes
1 answer
151 views

Make vim respect custom, defined paragraph when formatting text?

Let's say I have that text in my file: At vero eos et accusamus et iusto odio dignissimos ducimus qui blanditiis praesentium voluptatum deleniti atque corrupti quos dolores et quas molestias ...
toogley's user avatar
  • 547
2 votes
1 answer
2k views

How to disable autoformating on save on LazyVim?

On LazyVim when I save a cpp file it is automatically formatted. It is possible to disable/enable it in the session using Spaceuf But I would like to disable that autoformatting on save functionality ...
Vivian De Smedt's user avatar
2 votes
2 answers
797 views

set formatprg dynamically based on textwidth?

I've set formatprg in my vimrc to use the par text formatter when I type gq. setg formatprg=par\ -w90 When I'm in a buffer whose textwidth has been set (e.g. the gitcommit filetype sets textwidth=72)...
ivan's user avatar
  • 1,430
2 votes
2 answers
190 views

How to disable auto insertion of comment header when pressing enter, but keep auto insertion of header when auto wrapping comment?

When editing c and cpp files, this is the behavior I want to achieve: When typing a comment line of the form // Line..., pressing <CR> should not add the comment header // in the next line. ...
Diggs's user avatar
  • 75
1 vote
4 answers
2k views

Remove ^H from gvim

I am trying to direct data from manpage to gvim file but it's not properly formatted. Example: In manpage it is shown as NAME (bold) But in gvim its printed as N^HNA^HAM^HME^HE. Similarly for ...
vikas's user avatar
  • 11
0 votes
1 answer
201 views

Automatically reindent lines filtered through formatprg

I have following xml file: <?xml version="1.0" encoding="UTF-8"?> <graph id="G" edgedefault="undirected"> <edge id="e6" source="n5" target="n4"> <data key="d1">1.1</...
Hotschke's user avatar
  • 4,640
0 votes
2 answers
167 views

How can I write a custom formatexpr to specify the point at which 'gq' wraps?

I don't want VIM to automatically wrap text, so setting textwidth is not a solution to this problem. This comment gives a useful outline, but I'm not really sure how to go about doing this. My first ...
AmagicalFishy's user avatar
0 votes
2 answers
313 views

Vi formatting to ignore a section of text

I do a lot of plain text file editing, and many times I need to mark a section of text as 'DO NOT FORMAT' as it is pre-formatted, or even contains ascii art. Many years ago I did this by marking the ...
anthony's user avatar
  • 101