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
2 votes
1 answer
124 views

Justify text with leading whitespace

To justify text on vim I use :set textwidth=77 and space+v to select and finally gq to justify the text. This is the result original: Most of the command-line options that you can use with GCC are ...
elbarna's user avatar
  • 157
0 votes
2 answers
40 views

Put C++ function arguments on individual lines

I often find myself having to reformat C++ function arguments and template parameters to occupy individual lines rather than being on the same line. Here are a few examples. Turn this template <...
SU3's user avatar
  • 227
1 vote
1 answer
49 views

Autocommand is executed multiple times on filetype

I am trying to auto format python files on save. first.py #!/usr/bin/python3 print( "first") second.py #!/usr/bin/python3 print( "second") py.vim def BlackFormat() :...
balki's user avatar
  • 355
0 votes
1 answer
41 views

Command to separate nested brackets over multiple lines

I am looking for a language-agnostic way to convert something like this: this(is, a, line(of, things)) to this: this( is, a, line( of, things ) ) I can handle the non-...
pvelayudhan's user avatar
1 vote
1 answer
570 views

How to load formatter.nvim with lazy.nvim?

I am trying to load formatter.nvim but I get this error: Lua Diagnostics undefined field 'setup' What is the path for the logs? This is my full configuration: return { 'mhartington/formatter.nvim'...
nbari's user avatar
  • 131
2 votes
1 answer
2k views

How to disable autoformating on save on LazyVim?

On LazyVim when I save a cpp file it is automatically formatted. It is possible to disable/enable it in the session using Spaceuf But I would like to disable that autoformatting on save functionality ...
Vivian De Smedt's user avatar
0 votes
1 answer
52 views

Cancelling formatting from formatprg when not successfully exited?

Some format programs refuse to format malformed code, but instead sends an error message to stderr and exits with non-zero status. Vim does not seem to care about that, and simply puts on the error ...
Futarimiti's user avatar
1 vote
2 answers
503 views

How to range format with nvim 0.9.0?

I don't set a mapping to format code because it is not something I do all the time. So previously, I used to have a command to format or range format as follows: " format code command! -range ...
paulodiovani's user avatar
1 vote
2 answers
241 views

How to format text with gq by cutting long lines but without joining shorter lines?

I don't understand what shall I set (I guess fo, but how?) for cutting lines that are longer than textwidth but without joining lines that are shorter. For example, assume that I have textwidth option ...
Barzi2001's user avatar
  • 481
0 votes
2 answers
168 views

How can I write a custom formatexpr to specify the point at which 'gq' wraps?

I don't want VIM to automatically wrap text, so setting textwidth is not a solution to this problem. This comment gives a useful outline, but I'm not really sure how to go about doing this. My first ...
AmagicalFishy's user avatar
0 votes
1 answer
21 views

Manually indenting lines with tabs

Lines can be indented with tab characters. And it is quite obvious the there are better ways to do that than manually adding a tab character to the beginning of each line. But how to discover these ...
Volker Siegel's user avatar
0 votes
3 answers
414 views

How can I auto-format long function calls in Python?

I am a Python programmer using Vim. When writing a long function call, it often exceeds the width of my document: a_long_python_function(with_some, additional, arguments, kwarg1=kwarg1, kwarg2=kwarg2, ...
Tyrion97's user avatar
0 votes
0 answers
480 views

Neovim `vim.lsp.buf.format{async=true}` cause buffer change?

I am using autocmd BufWritePre to do code format with vim.lsp.buf.format(). It is sync and stuck for seconds. But when I use vim.lsp.buf.format{async=true}. The buffer is been changed. Is there a way ...
linrongbin's user avatar
1 vote
0 answers
351 views

How to create a (lua) function to run a particular command in the shell on the currently open file, within neovim

If I'm working on a file I might want to run a particular command which uses the file within the shell. Example - running black (python formatter) on an open file. Ideally I'd like to be able to enter ...
baxx's user avatar
  • 995
0 votes
0 answers
88 views

Insert-mode gqip not idempotent?

I open Vim and add the following lines to a buffer (call this state INITIAL): xx xx xxx xx xxxx xx xxxxx xxxxxxxx xxxxx xxxxxxxxxxx x xxxxx xxx xxxx xxx x xx xxxxxx xxx xxxxxxx xxxxxx xx x xxx xx xxx ...
IssaRice's user avatar
  • 133
6 votes
1 answer
536 views

What does breakat&vim mean?

I'm trying to understand this SO answer. The snippet reads: :set nolist wrap linebreak breakat&vim
John Schmitt's user avatar
1 vote
1 answer
578 views

How are formatters in CoC configured?

I have been using CoC for a few weeks now and I quite like it. Recently I started configuring the formatting options. I have put "coc.preferences.formatOnSave": true and configured .clang-...
matko031's user avatar
2 votes
0 answers
13 views

How to get softtabstop to go back in spaces with backspace? [duplicate]

I watched a video tutorial about optimising tabs vs spaces. I made no changes but I noticed something in the video that isn't happening for me. When he pressed backspace, he went back one space at a ...
Vinn's user avatar
  • 649
3 votes
2 answers
197 views

Customising file formating and coding styles in vim?

At the moment I use prettier for formatting with vim (via Coc). The issue I have is that prettier is opinionated and, at the same time, inconsistent. With javascript, functions look like this: ...
Vinn's user avatar
  • 649
0 votes
3 answers
123 views

Convert a column of words to a paragraph

How can I convert a column of words (one word per line) to a paragraph using vim? For example, before: how to convert After: how to convert
Datta's user avatar
  • 1
1 vote
1 answer
1k views

How to configure Neoformat to use Prettier?

Installed Neoformat with Plug in init.vim for Neovim 0.7.2 on Linux Mint 19.3 I can't figure out how to get Neoformat to work with Prettier. I installed Prettier as a snap package in --devmode, so ...
wayan's user avatar
  • 11
8 votes
1 answer
393 views

Avoid breaking words before or after asterisk ('*')

If you have set wrap, sometimes you can see something like this: 5. A soft-wrapped line with an * italic* word. I would prefer Vim to not soft-wrap before or after asterisks, and so the same ...
user90726's user avatar
  • 113
1 vote
1 answer
118 views

Vim: reformat CSS from one-line to multi-line rules

I wanted to reformat the W3.CSS file to make it more readable and study it. I looked for an easy way to do this but couldn't find it (in vim-only way, obviously, the web are plenty of solutions and ...
Antonio's user avatar
  • 275
0 votes
0 answers
192 views

YAML / YML unwanted auto-formatting

YAML / YML unwanted auto-formatting The last days I made some configuration improvements of my vim environment, e.g. I installed vim-polyglot and coc and removed duplicated plugins within my vim-plug ...
abu_bua's user avatar
  • 133
0 votes
0 answers
47 views

How can I align chained methods in Ruby files?

I often use = to indent lines but my configuration doesn't fit my needs. Is there an option that indent lines like this: 'vim rocks'.capitalize .concat(' !') Instead of this: 'vim rocks'....
Sumak's user avatar
  • 103
8 votes
6 answers
23k views

How to configure neovim to properly format python code?

I have neovim 0.8.0 installed. I have neovim/nvim-lspconfig plugin installed. I have installed pyright language server on my system (pip install pyright) I have configured neovim to use the pyright ...
lesnik's user avatar
  • 441
0 votes
0 answers
180 views

How to paste append and verical aligment multiple lines text in vim?

Is there any convenient way to format text block-1 to block-2 by vim? block-1 #include <stdio.h> #include "math.h" #include <iostream> #include <fstream> #include <...
Mirasire's user avatar
3 votes
0 answers
21 views

Prevent breaking at commas followed by tildes with `gq`

When I add m to formatoptions and have nonzero textwidth, Vim will insert line breaks after commas followed by tildes when I do gq in Normal mode. In my case, Vim sometimes inserts a line break at ...
user38527's user avatar
0 votes
1 answer
396 views

Is there a way to let sqlformat or another SQL formatter change only a selection within a file in VIM?

I added a shortcut in VIM so that I can press Esc and ,pt to get the automatic sql formatting from sqlformat command. Taken from Can VIM autoindent SQL?. "autocmd FileType sql call SqlFormatter() ...
questionto42's user avatar
1 vote
0 answers
26 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 ...
Jordan Mandel's user avatar
3 votes
1 answer
183 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 ·: ···/...
ELLIOTTCABLE's user avatar
0 votes
1 answer
35 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 ...
Harv's user avatar
  • 219
2 votes
2 answers
376 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 ...
moo's user avatar
  • 155
2 votes
2 answers
659 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 ...
Zeta.Investigator's user avatar
3 votes
1 answer
333 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 ...
Quasímodo's user avatar
  • 2,416
0 votes
0 answers
34 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 ...
Philipp Heller's user avatar
0 votes
0 answers
55 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 = ...
alemani's user avatar
  • 101
6 votes
0 answers
495 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 ...
needle's user avatar
  • 181
1 vote
1 answer
303 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 ...
Jordan Mandel's user avatar
1 vote
1 answer
37 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 \ ...
jbu's user avatar
  • 113
0 votes
1 answer
311 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:...
sidgujrathi's user avatar
1 vote
0 answers
39 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 (...
user2741831's user avatar
1 vote
2 answers
453 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 ...
niekas's user avatar
  • 1,545
0 votes
1 answer
61 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.stack.imgur.com/uh7Uc.png Since those text lines have a lot of words vim distribute the whole single line in several sublines(...
GhostOrder's user avatar
0 votes
0 answers
261 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 ...
Steven Lu's user avatar
  • 2,231
1 vote
1 answer
154 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, ...
berkes's user avatar
  • 113
2 votes
0 answers
33 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?
The Masked Rebel's user avatar
4 votes
0 answers
51 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 ...
Frostbitten's user avatar
2 votes
1 answer
119 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 ...
JohnDoe's user avatar
  • 363
10 votes
3 answers
18k 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....
baxx's user avatar
  • 995