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
1answer
105 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
115 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
652 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
126 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
477 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
140 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 ...
4
votes
2answers
404 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
114 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
469 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
792 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. ...
11
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
270 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
149 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
269 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
116 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
368 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
117 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
150 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, ...
15
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
348 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
151 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
551 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
177 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("...
14
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
8k 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
136 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
97 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 | <- ...
2
votes
2answers
2k 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
352 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: <...
17
votes
4answers
2k 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 '. ',...
1
vote
1answer
112 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 ...
5
votes
1answer
302 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 ...
1
vote
1answer
161 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[] ) { ...
22
votes
3answers
2k 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 | % | % ...
54
votes
3answers
17k 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 ...
24
votes
4answers
2k 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 very" ...

1 2 3