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.
22
questions
65
votes
3
answers
24k
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 ...
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 '. ',...
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 ...
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 ...
16
votes
3
answers
6k
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 ...
1
vote
1
answer
202
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{...
17
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 ...
6
votes
2
answers
942
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. ...
5
votes
1
answer
197
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 ...
5
votes
1
answer
223
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 ...
5
votes
1
answer
434
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 ...
4
votes
1
answer
423
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 ...
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: ...
3
votes
1
answer
106
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 ...
3
votes
1
answer
153
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 ...
3
votes
1
answer
515
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, ...
3
votes
1
answer
148
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 ...
2
votes
2
answers
742
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)...
2
votes
2
answers
178
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.
...
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 ...
0
votes
2
answers
284
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 ...
0
votes
1
answer
184
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</...