As of May 31, 2023, we have updated our Code of Conduct.

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
1 answer
374 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 ...
Toothrot's user avatar
  • 3,089
4 votes
1 answer
157 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 ...
Eirik S.'s user avatar
  • 111
5 votes
1 answer
208 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, ...
jdowdell's user avatar
  • 151
7 votes
1 answer
1k 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 ...
lis2's user avatar
  • 171
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 ...
toogley's user avatar
  • 547
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. ...
toogley's user avatar
  • 547
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 ...
Rmano's user avatar
  • 748
5 votes
2 answers
1k 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 ...
orlp's user avatar
  • 310
5 votes
0 answers
192 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 ...
Nova's user avatar
  • 151
4 votes
0 answers
724 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 ...
LastSecondsToLive's user avatar
2 votes
2 answers
2k 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. ...
jmreicha's user avatar
  • 201
13 votes
1 answer
2k 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, ...
silviubogan's user avatar
4 votes
2 answers
2k 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: ...
iago-lito's user avatar
  • 1,102
10 votes
1 answer
188 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 ...
silviubogan's user avatar
1 vote
1 answer
636 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 ...
Toothrot's user avatar
  • 3,089
4 votes
0 answers
143 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. ...
Alexey's user avatar
  • 511
3 votes
1 answer
575 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 ...
user1135541's user avatar
  • 1,073
5 votes
1 answer
126 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 ...
Toothrot's user avatar
  • 3,089
3 votes
1 answer
192 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, ...
Cbhihe's user avatar
  • 241
20 votes
5 answers
2k 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? ...
iago-lito's user avatar
  • 1,102
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, ...
MaiaVictor's user avatar
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 ...
cxw's user avatar
  • 934
9 votes
1 answer
917 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,...
mgiuffrida's user avatar
1 vote
0 answers
182 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("...
firedev's user avatar
  • 2,312
18 votes
3 answers
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 ...
ZeroKelvinKeyboard's user avatar
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,312
7 votes
2 answers
11k 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}'...
Aaron Shen's user avatar
  • 2,439
3 votes
1 answer
165 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 ...
jcea's user avatar
  • 133
2 votes
1 answer
152 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 | <- ...
firedev's user avatar
  • 2,312
3 votes
3 answers
4k 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 ...
baxx's user avatar
  • 925
2 votes
2 answers
495 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: <...
roblogic's user avatar
  • 697
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,253
1 vote
1 answer
139 views

Is there a way to have sidescrolloff behave differently depending if I am end of a line?

I work in two broadly different ways in vim (that are relevant to this question): I am writing text or markdown-formatted content, writing paragraphs of text. In this case I am generally writing new ...
Andrew Ferrier's user avatar
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 ...
jjaderberg's user avatar
  • 3,339
1 vote
1 answer
189 views

Change formating of `\im' command in c.vim

I have recently installed the c.vim plugin. The only issue is when I type \im (automatically adds the main function) this is the way how it displays it. int main ( int argc, char *argv[] ) { ...
iProgram's user avatar
  • 1,569
23 votes
3 answers
3k views

How to write vertically?

Lets say I want to produce the following text in my document: % % Not Important % O -------------------------> % | % S | % o | % m | % e | % | % M | % s | % g | % | % ...
Allan Hasegawa's user avatar
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 ...
Greg's user avatar
  • 847
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

1 2 3
4