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
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 (...
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
1answer
31 views

Vim doesn't respect the initial tab distance of a paragraph

I have lines of text like these (each of one are single lines): https://i.imgur.com/FIB3Zbj.png Since those text lines have a lot of words vim distribute the whole single line in several sublines(I ...
0
votes
0answers
16 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 ...
1
vote
1answer
31 views

Using cindent and/or `gq` to wrap long function arguments to one-per-line

When a line becomes too long, I would like to wrap the function call with a "one argument per line" syntax: For the example: :set textwidth=50. Given: long_function_name(argument_one, ...
2
votes
0answers
27 views

Reformatting a tab in vim [closed]

I am new to vim, and I'm facing an interesting problem. I need to reformat a file so that the indentation is consistent. How do I do this?
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 ...
2
votes
1answer
47 views

Vim Markdown treat fenced codeblock as comment

I use a rather nifty automatic text formatting for Markdown: (Seen https://asciidoc.org/userguide.html#X61) augroup TXT | au! autocmd FileType asciidoc,markdown \ setlocal autoindent expandtab ...
1
vote
0answers
2k views

How to format files on save using black with neovim and coc

I'm trying to have python files format on save using black and neovim, with coc. Coc config I have the following coc config: { "coc.preferences.useQuickfixForLocations": true, "coc....
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
2answers
100 views

How to format a JSON snippet in a non-JSON file using jq?

I've got, in this case, a Perl module which has some JSON snippets inside of it. I'd like to be able to select the embedded JSON and format it via jq. So far I've got: :vnoremap jq <esc>:'<,'...
1
vote
0answers
12 views

Get comments LINED UP in 65c816 asm syntax [duplicate]

I've been writing some 65c816 assembly lately. They have some interesting commenting conventions that I was hoping VIM could help me with. LDA $E7 ; You see, they BEQ IfZero ...
2
votes
2answers
57 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
2answers
26 views

Autoindent unordered lists that start with a hyphen in cpp files

The context I've the following options in my vimrc set formatoptions=cnroqj set textwidth=80 When editing tex files, lines whose content is longer than &textwidth is splitted and formatted as ...
0
votes
2answers
37 views

How to join or format paragraphs in a file quickly

When I want to share my markdown file to others, I would like to join lines or format lines for all paragraphs in my file quickly. File in formatted version: # head 1 Lorem ipsum dolor sit amet, ...
0
votes
1answer
46 views

Unintended automatic join behavior and move in editting

I have to following lines in my .vimrc file (being .vimrc is irrelevant, other files the same), noremap D "_d "Make Y behave like other capitals (C, D) nnoremap Y y$ When I started to delete "_d ...
1
vote
1answer
77 views

Reformat code: breaking lines and aligning on a character

I am writing code in R, specifically using the Tidyverse packages. There is extensive use of the pipe %>% to chain functions together. The lines become long, so it is recommended to break them up ...
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/...
0
votes
1answer
48 views

How to break lines into a certain amount of characters?

I have a long text file (300 lines), and I would like to format it so each line is not longer than 50 characters. For example, we have: I have a really long text, I have a really long text, I have a ...
0
votes
2answers
130 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 ...
4
votes
1answer
2k views

How to clang-format the current buffer on save?

Whats the best way to clang-format a C/C++/GLSL a buffer on save, that does nothing in the case there is no clang-format file found for a project?
2
votes
2answers
283 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
1answer
68 views

Configure formatting to indent all lines of a numbered list (enum-list)?

How to make vim respect the enumerated list indentation also on consecutive, not only on the second line? I.e. so that pressing gq on: 1. A long line reaching near &tw. following text on the ...
3
votes
2answers
415 views

Can I mark some piece of text as bold?

For example, lets say I have a line like: Hello, this should be bold. Then is there any way to change one or more words to be bold, so it will appear on the screen as: Hello, this should be ...
1
vote
1answer
72 views

How to make vim syntax files look nice? [duplicate]

I often get really long lines, such as: syntax region SomeName start=/some_pattern/ end=/some other pattern/ contained contains=SomeOtherName,YetAnotherName,EvenMoreNames,More,MoreAgain,KeepsGoing,...
2
votes
2answers
311 views

Format / Indent c++ as you type inside expressions

In visual studio, that code : for(int x=0;x<10;x++) {} becomes that code : for (int x = 0; x < 10; x++) { } as soon as you hit enter. I was wondering, is it possible, and if so, how can I ...
0
votes
0answers
536 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 ...
1
vote
4answers
1k 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 ...
1
vote
1answer
113 views

How to format with `gq` using the same settings as when editing the text

I have the following options set (in ~/.config/vim/ftplugin/asciidoc.vim): setlocal wrap setlocal textwidth=0 setlocal wrapmargin=0 setlocal formatoptions=l And when I'm writing text, it's not hard-...
1
vote
3answers
1k views

Is there a way to split a word by characters?

I'm trying to write a 2D matrix of characters. I can get a string of random characters with pwgen 4 1, for example. That gives me something like this. ia6e Is there a way to split this string up by ...
1
vote
1answer
179 views

NeoVim: Single-Line Comments Also Format the Next Line [duplicate]

So, I started using NeoVim a little while ago and discovered a rather annoying quirk when using C++-style single-line comments // in source code of any language. Specifically, when you create a new ...
1
vote
1answer
65 views

How can I format a function declaration to force curly brace at the end of the line?

I have big portions of code where functions are formatted with the opening curly brace on the next line, like this : function foo() { } I'm trying to figure out how to search / replace in order to ...
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 ...
4
votes
1answer
213 views

Insert comma on new line in array

I like to format my arrays like this: myArray = [ "lorem" , "ipsum" , "dolor" , "sit" , "amet" ]; If I open a new line below the "amet" line, I ...
0
votes
2answers
53 views

How to convert a sequence of words to a list?

I have the following strings (whitespace and line wise separated) in a file mks asksö askndl ebre nakkl sadj and would like to have it formatted as follows ["mks", "asksö", "askndl"], ["ebre", "...
1
vote
1answer
184 views

xml ftplugin overrides textwidth

I would like to hard wrap XML files during editing. In every other filetype my set textwidth=80 works fine. But in XML something overrides the insertion of line breaks. I tried adding t to ...
5
votes
1answer
2k views

what are the usage of equalprg and formatprg

If I want to format a few lines, should I choose equalprg (using = operator) or formatprg (using gq operator)? Both of them are for some kind of formatting. But what are the differences.
0
votes
1answer
100 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</...
2
votes
1answer
159 views

How to make vim display ZWNJ characters correctly?

When I insert a ZWNJ character into text, vim displays <200c> instead of it. Is it possible to make vim to behave normally with this character, like GUI editors? Or is it possible to hide (and ...
1
vote
1answer
38 views

how reformat kegg reconstruct pathway in vim?

I need to reformat the kegg reconstruct pathway output, I have something like this in file1: 00550 Peptidoglycan biosynthesis (2) K01000 K02563 00511 Other glycan degradation (8) K01190 K01191 ...
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 ...
2
votes
2answers
409 views

How to autoformat a multi-line string

I want to format a multiline string according to a textwidth of 32. group: - normal: scalar - multiline: "Lorem ipsum dolor sit amet, consetetur sadipscing elitr, sed diam nonumy eirmod tempor ...
1
vote
2answers
239 views

separating folds with constant amount of newlines

Is there a succinct way to separate folds, open or closed, by the same number of newlines throughout the buffer? I'm using fold by indent. The goal is two visible blank lines between each fold (...
2
votes
1answer
281 views

Highlight whitespace using matchadd

I'm trying to use matchadd to highlight different occurrences of whitespace. However, sometimes it doesn't work for some reason. Here is the code: highlight GroupA guibg=lightgreen highlight ...
0
votes
2answers
104 views

Search and replace a pattern with new line except for a pattern

I am having a very long line file, I have to break the line into number of small lines. Example: < this>is a testing< /this>< next>testing< /next>< tested>successfully&...
0
votes
1answer
28 views

Automatic format: how to insert needed amount of spaces for vertical aligning? [duplicate]

Given code: <option id='Nicole' data-language='en-AU'>Australian English - female - Nicole</option> <option id='Russell' data-language='en-AU'>Australian English - female - Russell&...
54
votes
7answers
31k views

How to format JSON file in Vim

Given a file with a large JSON object all on one line like {"versions":[{"count":2,"version":""},{"count":1,"version":"1.1.1"},{"count":14,"version":"2.9"},{... How can I format this to be human ...
1
vote
1answer
236 views

How can I automatically preform operations when a vim *window* is resized?

I'm setting up NeoFormat/ALEfix-style code reformatting, and I'd really like to have it automatically and fluidly reformat the code as the window is resized. This is possible for whole-viewport vim-...
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
1answer
36 views

How can I align the comment at the end of sentences when the comment predictor is already shown?

I want to align commens on multiple lines neatly, and found the following question and answer (I used the tabular package), but then I found out that it needs the comment specifier NOT to be shown on ...