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
2answers
5k 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....
1
vote
1answer
123 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)...
0
votes
1answer
44 views

Make Line Numbers Appear in Documentation

I have set number in my init.vim (I am using neovim) and it works fine for any buffers I'm editing. However, I have to enter :set number into the command line to make line numbers appear in the ...
0
votes
1answer
28 views

Is there a soft/visual textwrap equivalent option? [duplicate]

I like textwidth, except that it inserts EOL characters, and that breaks what I consider to be a sentence. I'd like to go back to having a long sentence be a long sentence, but I want it visually ...
2
votes
2answers
414 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
37 views

Reformatting comments with gq, using spaces in 'comments'

I'm using Prettier to automatically reformat JavaScript (well, TypeScript, but same deal in this situation) source-code. It enforces a comment-style like this, with leading spaces replaced with ·: ···/...
1
vote
0answers
21 views

How to see offscreen undo changes?

Imagine a text file with some words on the first line, one-thousand blank lines, and some text on the last line. this is a first line of text. <1000 blank lines> Last line of text. From the ...
15
votes
2answers
4k views

Why Vim sets max text width to 79 instead of 80?

I'm a little puzzled about some default values in Vim. In particular, for gq{motion}, is said that [...] If the 'textwidth' option is 0, the formatted line length is the screen width (with a maximum ...
1
vote
2answers
58 views

How to syntax-highlight part of a file in a foreign language?

Using set syntax=lang we can override syntax highlighting of current buffer with lang. Suppose we're editing a Bash script and some string variables are actually HTML code. How to force vim to use ...
1
vote
2answers
86 views

Piping buffer through a command, handling failure gracefully

I want to be able to lint my code from within vim, using tools like clang-format and yapf and I'd rather do this without installing a more complex plugin. I can pipe the current buffer through a text ...
3
votes
1answer
72 views

Paste a column in a table

Suppose I have this file open in Vim: AXXK M(X) 1.1 1 1.2 8 And that the clipboard holds U(1X) MX1 MX2 How can I easily paste that content as a new column? I want: AXXK M(X) U(1X) 1.1 1 ...
0
votes
0answers
33 views

How do you get Vim/Neovim to stop hard wrapping comments?

I thought that with formatoptions-=c, vim wont automatically format comments, but for some reason with setlocal formatoptions=ant and textwidth=80, neovim is still hard wrapping markdown comments (<...
0
votes
0answers
22 views

Custom indent minified file

At work I'm forced to work on custom mapping-files which map relations between objects of different systems. These mappings, which are basically Jinja templates, are unfortunately stored in single ...
0
votes
0answers
26 views

Formatting with gg=G on *.cfg files (Nagios) results in bad indentation

Search-fu power is eluding me for this one. Have many Nagios (*.cfg) files under audit, using Vim to work on them. Notice that doing gg=G is not correctly formatting the files or a block if using = ...
4
votes
0answers
70 views

How to get bold comments in vim

I am trying to add bold comments to my vim files. What i mean, is to be able to get something like this: I saw other articles like this that allow to toggle bold comment. The proposed solutions from ...
1
vote
1answer
24 views

vimscript to insert function result is not inserting with proper formatting

I have a function that I want returning pre-indented xml: function! InsertStep() let stepTemplate = "<step index=\"\">\n \ <description></description>\n \ ...
0
votes
1answer
99 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:...
70
votes
8answers
45k 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 ...
0
votes
2answers
186 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
35 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
36 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 ...
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 ...
0
votes
1answer
36 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
42 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
47 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
29 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
41 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
56 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
1answer
218 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 ...
2
votes
2answers
518 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 ...
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
105 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
36 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
38 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
47 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 ...
3
votes
3answers
3k 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 ...
1
vote
1answer
90 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 ...
11
votes
5answers
5k views

set formatoptions in vimrc is being ignored

Vim automatically continues a comment when I press Enter in Insert mode, which I find helpful. However, I do not want the comment continued after pressing 'o' from normal mode to insert a new line ...
1
vote
0answers
42 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/...
2
votes
2answers
182 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-...
6
votes
1answer
3k 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?
59
votes
3answers
21k 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 ...
2
votes
2answers
527 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 ...
4
votes
2answers
1k views

How to set the relative indent after breaking Python lines?

When I insert a line break inside a line of Python 3 code, the remaining part of the line is indented by two additional tab widths (2 time 4 spaces) in the next line. # Before example_function(...
14
votes
3answers
5k views

automatically rewrap lines when writing markdown in VIM

Very often, I write markdown in VIM, and there will be paragraphs in those markdown. To help my editing, I setup my Vim to wrap a line on 80 chars. It works nice if I just keep typing, but the problem ...
0
votes
1answer
51 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
165 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 ...
5
votes
1answer
357 views

Can auto-format break at hyphens?

I write my email in vim, which dynamically inserts newlines after 72 characters. formatoptions=awtcql This works nicely, breaking at spaces. However, is there a way to make it break at hyphens as ...
3
votes
2answers
599 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 ...
2
votes
1answer
92 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 ...