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
2 answers
67 views

How can I expand one line to multiple lines, pairing two attributes?

How can I expand one line to multiple lines, pairing two attributes? Sample input (my input has nearly a thousand lines): Mission Rewards ---------------------------------- Mission: [id: 1 , name:...
FromTheStackAndBack's user avatar
1 vote
2 answers
74 views

Move Lines in a File to the same Column

For example I have this file: abc line1 def line2 ghijk line3 lmno line4 pqrstu line5 vwxyz line6 I want to format the file to look like this: abc line1 def line2 ghijk line3 lmno line4 ...
Bog's user avatar
  • 469
2 votes
1 answer
143 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
  • 179
0 votes
2 answers
129 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
62 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
119 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
1k 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
5 votes
2 answers
6k 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
60 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
714 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
273 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
  • 550
0 votes
2 answers
308 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
28 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
603 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
1 vote
0 answers
418 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
  • 1,025
0 votes
0 answers
95 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
560 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
775 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
  • 771
3 votes
2 answers
359 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
  • 771
0 votes
3 answers
227 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
2k 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
442 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
  • 123
1 vote
1 answer
139 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
  • 287
0 votes
0 answers
220 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
48 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
10 votes
6 answers
29k 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
  • 471
0 votes
0 answers
192 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
27 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
454 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
27 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
196 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
36 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
411 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
805 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
368 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,466
0 votes
0 answers
35 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
58 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
548 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
375 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
342 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
40 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
526 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,575
0 votes
1 answer
70 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
279 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,251
1 vote
1 answer
165 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
34 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
54 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
129 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