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.

26 questions with no upvoted or accepted answers
Filter by
Sorted by
Tagged with
4
votes
0answers
183 views

How to stop vim from reformatting lines inside a codeblock in a markdown file?

I keep the a formatoption in vim when I'm modifying markdown files, so my lines are automatically kept to textwidth characters long, with automatic reformatting when I modify text. How can I make ...
4
votes
0answers
140 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
32 views

More intelligent automatic formatting

I use vim to edit latex files and the automatic formatting option (formatoptions+=a) works very well, since you can enter text anywhere in the paragraph and vim will reformat the entire paragraph. The ...
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 ...
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. ...
2
votes
2answers
298 views

format sparse json files for legibility

Situation I have a large, hierarchical json file with many single entries, like so: { "tokens": [ "payload, a string" ], "values": [ { ...
2
votes
0answers
26 views

Applying full auto-format to comments but not code

I am considering using Vim's auto-format feature (i.e., adding a to formatoptions). However, I can't seem to figure out a combination of options that will give me the configuration that I want. For ...
2
votes
0answers
186 views

Possible to exclude comments from textwidth?

I recently discovered the textwidth setting, which lets me configure vim to insert a "smart" whitespace-delimited carriage return as I'm typing when my line of text exceeds my specified limit. Is ...
2
votes
0answers
111 views

How can I format objects wrapped inside curly braces?

It's pretty common for me to have code like this in Python and Javascript. my_obj = [ { id: 0, name: 'foo', age: 123 }, { id: 1, name: 'foo', age: 321 } ] What I'd like to automate is ...
2
votes
0answers
118 views

Can someone explain the strange behaviour with indenting during reformatting?

Recently, someone noticed a strange behaviour with indenting during formatting with my LaTeX plugin, vimtex. I've researched it, and I've ended up creating a minimal example. Load the following code ...
2
votes
0answers
162 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 ...
1
vote
0answers
30 views

Vim formarts postgres wrong

I use vims autoformat feature a lot. But it doesn't work properly for postgres CREATE TABLE foo (fooid INT, foosubid INT, fooname TEXT); INSERT INTO foo VALUES (1, 2, 'three'); INSERT INTO foo VALUES (...
1
vote
0answers
22 views

Disable text wrapping in vim

There's a very weird thing that occurs when I type a comment that it inserts a newline after a max-width which I don't want to have done. For example: here is me typing it in: https://gyazo.com/...
1
vote
0answers
39 views

expandtab tab as 2 spaces show visually as 6 columns

How can 2-space indenting be shown as 6 column tab-style indents when editing, while remaining as 2-spaces? Background: a team uses a convention of 2 spaces for indenting code I prefer indenting of ...
1
vote
1answer
112 views

Dynamically toggle formatoptions based on input

Question: Is there a way to control the indentation + comment leader input, when adding a new line? Details: I am trying to set formatoptions-=cro when inserting a new line (in specific syntax region)...
1
vote
0answers
63 views

Why are my bulleted lines automatically joining?

I use the a formatoption to make my text hard wrap, and the n formatoption to recognize numbered lists. The help says that the n option should use the formatlistpat regex to determine which lines not ...
1
vote
0answers
51 views

Autoindent with minimal indentation

For some reason, Vim started to indent JavaScript in this crazy manner. I bet it's related to some settings in my syntax plugins, but I can't seem to figure out which ones are causing this behavior: ...
1
vote
0answers
49 views

Incorrect formatting of file when calling nvim inside NodeJS script

I am formatting elixir files .ex with the help of a contributed plug-in for nvim like this on Windows: cmd> nvim.exe -i NONE -n -E +"norm gg=G" -cwq c:/file.ex This works fine when the command is ...
1
vote
0answers
42 views

How do I reformat a paragraph using a different value for textwidth than the default one?

Sometimes I want to reformat a paragraph using gq but with a different value than the one set in my configuration for this filetype. Since this happens only occasionally within a buffer of such type (...
1
vote
0answers
171 views

Indentation in three piece comments in javascript

I use Vim 7.4.2149 and the plugin pangloss/vim-javascript for js indentation. I need to get comments like: /* * */ But instead I get: /* * * */ I'm not really interested in syntax ...
0
votes
0answers
20 views

Vim Formatter vs VsCode Formatter Problem with GIT

I am using Vim (neovim) for the past couple of weeks now. I am facing one problem with the way vim formats the code. My other team members uses vscode which formats JS file on Save something like this:...
0
votes
0answers
17 views

Is it possible to apply formatters only for selected lines using ALE Vim plugin?

I want to format only a part of file and keep the rest unchanged using ALE. I imagine that its kinda possible by providing a fragment of code for example for black formatter and replacing the selected ...
0
votes
0answers
17 views

How to configure formatoptions for markdown?

I really like how vim paragraph auto format works for markdown. The one place where it falls flat on its face is when editing/formatting code and log output that I want to put into the markdown (maybe ...
0
votes
0answers
21 views

Prevent weird R formatting after curly braces on the same level

When using the magrittr package, having a code block that starts and ends on the same level of indentation results in vim formatting all subsequent lines one indent too far. How do I stop this ...
0
votes
0answers
554 views

Autofix a single line in ALE

When prettier tells me to take one line with a whole object and put every property on a new line, I want a key to autofix that. I know prettier has things that can be auto-fixed, but I have no idea ...
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("...