The Stack Overflow podcast is back! Listen to an interview with our new CEO.

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
0
votes
2answers
52 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 ...
0
votes
0answers
25 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
56 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
29 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
98 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
40 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
1answer
43 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
57 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
3answers
104 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
28 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
89 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
63 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
42 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
18 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 ...
3
votes
1answer
110 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
39 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
78 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 ...
3
votes
1answer
751 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
51 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</...
1
vote
1answer
65 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
32 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
1answer
138 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
64 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 (...
1
vote
1answer
112 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
61 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
25 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&...
9
votes
3answers
5k 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
116 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
65 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
30 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 ...
1
vote
0answers
35 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 ...
2
votes
0answers
103 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 ...
1
vote
0answers
41 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: ...
3
votes
2answers
335 views

Remove new line from result of system() [duplicate]

I would like to store the result of a system() call in a variable without the trailing ^@ character. At the moment I do something like var = system('command | xargs -i echo -n "{}"') but it feels ...
3
votes
1answer
124 views

Using `gq` to correctly wrap function arguments

Consider editing the code foo = long_function_name(var_one, var_two, var_three, var_four) where the textwidth 'column' occurs just after var_two. I would like to be able to press gqq on the line ...
1
vote
1answer
84 views

How to format quotes, so that Vim breaks long lines into multiple quotes on multiple lines?

For example, suppose I have this line of JavaScript: console.log( "This is a really long line that I want to format, and it is inside of a quote" ) I'd like to select the quote line in VISUAL-...
1
vote
1answer
96 views

formatoptions for hybrid (short markup + long paragraphs) content

I am trying to write my PhD thesis in vim using LaTeX So the documents will have two distinct types of content - markups that are relatively short, and paragraph text that is rather long. \begin{...
0
votes
1answer
677 views

How to format csv with regex

I have a csv that looks like this: 1,wer123,name,address1,age,2,cde789,name,address1,address2,age,3,529owq,name,address1,age and so on. I want this csv to be formatted as 1, wer123, name, ...
2
votes
1answer
56 views

How do I move by paragraphs, but end up *in* the paragraph?

So I often use repeated invocations of gqip to re-wrap paragraphs of text or comments. Unfortunately, the quickest way I've memorized for moving between paragraphs, }, lands me between them: Qui⁁ut ...
2
votes
1answer
67 views

strftime format support two letter day option

We use a date format that appends the day at the end of the date like so: 20180109tu@1730. Is there any way to get the two letter day format?
1
vote
0answers
314 views

vim + jq :: how to format possibly incorrect text in unsaved file [duplicate]

This is very similar to how-to-run-bash-command-over-current-file-and-replace-buffer-with-result But I need to know how I can access current buffer when the file does not exist? i.e. I open vim goto ...
2
votes
1answer
367 views

Getting vim with yapf to work with anaconda environments

I'm trying to figure out how to get yapf to use my current conda environment when resolving imports. Basically, I just see a ton of the following errors: physics.py|6 col 1 error| [import-error] ...
2
votes
1answer
231 views

Indentation like astyle - continuation lines

I currently use astyle -A8 -t8 -p -j <filename> to format the code in my C project. Is there a way to configure my .vimrc to follow the continuation line format that the above demands? For ...
1
vote
0answers
42 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
1answer
74 views

Split a block to multiple lines with respecting indenting

Context is Ruby. Lets say I have a long line which has a block which I want to have simply in multiple lines: let:(variable) { do.some.stuff(expressed_as_a_long_line { x }) } I'd like split this ...
1
vote
1answer
87 views

Vim equalprg: why does it fail silently on a bash script?

After the command :set equalprg=echo.sh, the equals command simply deletes the specified region. Here is echo.sh: #!/bin/bash echo "$1" Where is the input? I can assign equalprg to something like ...
1
vote
2answers
1k views

vim to interpret escape characters (“\n”, “\t”) as does echo

I need an option in vim to display a text file, say text-file, during the session as would echo -e `cat text-file` | vim - vim is given text-file text-file includes text with escape sequences, such ...
3
votes
1answer
166 views

How to set nowrapscan when formatting text with gq

When I was editing a fairly large text, I accidentally hit gq* instead of gq} and then vim apparently seemed to freeze a moment with the message search hit BOTTOM, continuing at TOP displayed in the ...
1
vote
2answers
133 views

Automatically add '>' at beginning of line following one starting with '>' when writing Markdown

When writing block quotes Markdown, I want to make vim act the same way it does with comment leaders and automatically start new lines with the '>'. I also want to be able to format text this way with ...