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
4
votes
2answers
1k views

How to set the relative indent after breaking Python lines?

When I insert a line break inside a line of Python 3 code, the remaining part of the line is indented by two additional tab widths (2 time 4 spaces) in the next line. # Before example_function(...
3
votes
5answers
802 views

How to conveniently add ornate headers to source code?

Currently I’m adding source sections manually, e.g.: /******************************************************************************* * entry point *******************...
5
votes
1answer
169 views

gqip for VHDL comments does not work

After I set syntax=vhdl and set fo=tcq, running gqip on the following paragraph does not work as expected: -- Lorem ipsum dolor sit amet, -- tempor incididunt ut labore et dolore magna aliqua. Ut ...
13
votes
3answers
1k views

How to automatically lower case the second letter of a word?

When I have to type a lot of text I often tend to keep my finger pressed on shift when I write the first letter of a sentence which often give: [...]end of sentence. NEw sentence[...] Here the E of ...
1
vote
3answers
339 views

Conversion from XML to KML

I have an XML file with this format (there could be some leading spaces): <Latitude>23.1138</Latitude> <Longitude>8.2898</Longitude> ... <Latitude>19....
0
votes
2answers
971 views

How to remove line breaks in xml tags?

I often have to write XML where text-width has been manually set by another editor: <context> <p>Here is a paragraph about some stuff that happened and someone did a nice ...
5
votes
1answer
459 views

Make autoformating insert a line break instead of two spaces after full stop

I noticed that vi's auto format adds two spaces after a full stop. I wonder how this can be changed, i.e., insert just one space after a full stop, or even a line break. The application is in using a ...
4
votes
1answer
363 views

Vim Pandoc & Headers

When using vim-pandoc, I'm having some funny behavior with headers: For instance, if I position the cursor on a word and press v-a-w and then <localleader> - i, I get italics. if I position ...
2
votes
2answers
477 views

Pandoc and formatting

I'm using the vim-pandoc and vim-pandoc-syntax bundles in neovim. I'm converting the markdown to a docx file and I'm seeing that I need to do a double space in order to get a carriage return in the ...
3
votes
1answer
180 views

How to search and format a text range?

I want to format a block of text and I am using a range to select the leading comment of a function. It's all lines starting with // .... I'm using the range :?^[^\/][^\/]?+1,/^[^\/][^\/]/-1 to ...
3
votes
1answer
76 views

Switching back and forth between two text layout conventions of input to LaTeX

While using git and other versioning systems, it is very useful that text lines occupy no more than (say) 80 characters. It is also more comfortable to edit text with vi if lines are note excessively ...
2
votes
1answer
45 views

Opening a new line without returning the carriage

Say I want to begin letters like this: Dear world, hello. What's the simplest way to define a mapping that opens a new line preserving the cursor's horizontal position?
4
votes
2answers
1k views

How can I make vim's flowing aware of email replies?

Problem summary I use vim to edit emails that I send with mutt. I also use format=flowed, which "reflows" text. That is, lines are limited to a fixed number of characters, and a "soft wrap" is ...
6
votes
2answers
464 views

Is it possible to create a folding inside a single line?

The chapter 28 of User Manual says the following about folding: Folding is used to show a range of lines in the buffer as a single line on the screen. And all the examples of folding that I've ...
2
votes
1answer
80 views

A script and keybindings to look for VIM commands in a file, and then execute them on that file

This is a followup question to Auto sorting of lists of include files, which explains the motivation. EDIT I am looking for a script and/or keybindings to look for VIM commands in a file, and then ...
2
votes
1answer
72 views

Difference between autoformat and autoindent

What is difference between autoformat and autoindent? What are most popular solutions in text formating in vim of both of these methods?
2
votes
0answers
163 views

Formatting with par, better padding

I've started using set formatprg=par\ 66q\ g1\ j " keep double spaces, justify which makes beautifully justified paragraphs. But it would be better if the algorithm preferred to pad after .:;, in ...
2
votes
1answer
95 views

Conflict: concealment and paragraph formatting

When formatting paragraphs with concealed elements, the formatting program does not take into account that some characters are invisible, and renders some lines shorter than the rest, when using the ...
4
votes
1answer
358 views

Formatting with par and justified option

I just learnt from a vimcast (#18) that one can format paragraphs justified. This seemed very attractive to me, but I had one problem with it: I use double spaces after the end of sentences to ...
4
votes
1answer
130 views

Format options setting collapses lines

I set up this nifty custom function to help me use Vim for word processing: func! WordProcessorMode() setlocal formatoptions=ant setlocal textwidth=60 setlocal wrapmargin=0 endfu com! WP ...
5
votes
1answer
164 views

How to wrap plain text honoring existing text indent?

With at least these settings: expandtab textwidth=79 sw=4 ts=4 fo=tcq If I have a long line of text that starts with a * (like a C/javadoc comment) it will honor the current indent level when I gqq, ...
7
votes
1answer
794 views

Neovim format ruby code like rubocop

is there any chance to format code to satisfy rubocop? By default my neovim is indenting code like that: class Test attr_accessor :a, :b, :c, :d, :e, :f end However, it would be nicer to have ...
3
votes
1answer
131 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 ...
5
votes
2answers
584 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
1answer
169 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
2answers
692 views

Reformat within comment

In my vimrc I have the following: vmap Q gw nmap Q gwap set formatoptions+=cj set formatoptions-=t This disables automatic text wrapping, and allows me to correctly wrap the paragraph my cursor is ...
4
votes
0answers
141 views

How to align a Latex table that uses \multicolumn?

I want to align a Latex table the way it appears in the final document. There are various Vim plugins for aligning tables (2, 3, 4), but none of them handle the spanning cell correctly. The code ...
3
votes
0answers
563 views

Can't get autocmd with two events to work

I have the VIM Clang Format Plugin and I would like to format my code every time I save it. This is in my current .vimrc: " map to <Leader>cf in C++ code autocmd FileType c,cpp,objc nnoremap ...
2
votes
2answers
1k views

visual mode gq not reflowing comment block

I am looking for an easy way to reflow blocks of comments (in GO). According to this post I should be able to just run gq on a block and it will reflow automatically, but this doesn't seem to work. ...
13
votes
1answer
1k views

Unexplained gq indentation issue

I insert this text in Vim: t tttt ttttttttt tt tttt tt ttt tttttt-tttt-ttttttt tttttttttttttttttttttttttttttttttttttttttttttttttttttt ttttt ttt ttt tttttt ttttttt tttt ttttttt: ttttttt tt ttttttt, ...
4
votes
2answers
918 views

Remove unecessary indents while keeping the relative indentation

I am looking for a transformation that would change this text: text indented text double indented text indented again to: ...
10
votes
1answer
179 views

How to temporarily make gq consider hyphen (-) a normal word, to not indent the following lines in the same paragraph

I have tried this in a JavaScript file after disabling smartindent and autoindent options, with textwidth = 80, but it is still the same. It also happens automatically because of the textwidth option ...
0
votes
1answer
432 views

Hiding text as entered

Is there a way to hide all text that is being entered, just as passwords are hidden? so that the cursor moves but the output is æquivalent to spaces, until the function is turned off? Variants of this ...
3
votes
0answers
133 views

Formatting blocks of “commented out” text

I would like to be able to edit and format blocks of comments (in different markup and programming languages) as if the commenting characters (generally in the beginning of the lines) are ignored. ...
3
votes
1answer
436 views

Auto Indent (the = key) of C switch block

For the following switch block: If I select the switch block and apply the auto format command, the = key, I get the following: The block is formatted correctly in the first image, but it gets ...
5
votes
1answer
121 views

Edit comments as if separate lines?

Is there a way to edit comments so that they will all be aligned without having to align them manually with tab? i.e., How can I get something like that? some text %comment some more text ...
3
votes
1answer
160 views

How to convert code to html **with** arbitrary html page breaks?

Thanks to @BobHyam's question and to @BenjiFischer's answer on the list vim_use@googlegroups.com, I found out how to print to hardcopy while integrating form feeds: in ~/.vimrc " ^L by analogy, ...
17
votes
4answers
1k views

Merge blocks by interleaving lines

Is there a dedicated way to merge two blocks of text by interleaving lines, like passing from this: a1 a2 a3 a4 b1 b2 b3 b4 to that: a1 b1 a2 b2 a3 b3 a4 b4 in a few commands? ...
3
votes
1answer
416 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, ...
5
votes
1answer
164 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 ...
9
votes
1answer
786 views

Auto-format: wrapping later in line when inserting text

After reading help textwith and help fo-table, I expected that when I set set textwidth=20 " for demonstration set formatoptions=tcq then inserting text would always eventually cause a line to wrap,...
0
votes
0answers
180 views

Using single quotes blows up syntax formatting in .js

Just noticed that using single quotes in javascript blows up automatic formatting sometimes: See the public/sass/*.sass line: Double quotes: gulp.task('compile-sass', function(){ gulp .src("...
17
votes
3answers
2k views

Blocking changes to read only file

When using Vim to edit a read only file it will just provide a warning the first time it is edited but allow any changes to take place. I can understand this behaviour could be useful for someone ...
4
votes
1answer
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: ...
6
votes
2answers
10k views

How to format xml or html's attributes into multiple lines instead of lining up on one line?

I'm using plugin Chiel92/vim-autoformat auto formatting xml files. So the default format program used for xml file is tidy. The way it formats xml file is like below: <List id='list' items='{/sss}'...
3
votes
1answer
151 views

Indentation with “#.” start of paragraph

When I type 1. blah blah blah Vim recognizes the 1. prefix and it indents the rest of the paragraph tidy. I would like to configure Vim to do the same thing with #. literal prefix, since ReST files ...
2
votes
1answer
115 views

`gq` with left whitespace intact

When I have heredoc and I format it with gq I want it to be aligned in a way so each line starts at the same column like this: Long text goes here ... 80 chars | <- ...
3
votes
3answers
3k views

Run macro over a visual selection with line movements

I can find an answer to a similar problem here, however although I can get that example to function I can't get what I want to do to work. Here is the example text to be edited, a partial section of ...
2
votes
2answers
404 views

Tips for quickly formatting a single line of XML?

I have a log file with lots of web service XML data (example follows). Ideally I would like to just go to a line and type ,x to create pretty formatted XML for readability. Response XML: <...
19
votes
4answers
3k 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 '. ',...