Last call to make your voice heard! Our 2022 Developer Survey closes in less than a week. Take survey.

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
0 answers
12 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 ...
user avatar
  • 101
0 votes
0 answers
25 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'....
user avatar
  • 101
0 votes
0 answers
14 views

HTML Lsp missing format shortcut

I'm having a problem in Neovim with Lsp formatting in Html files. :checkhealth is Ok :LspInfo is Ok, html is attached I have a shortcut for formatting, buf_set_keymap("n", '<space>fo', ...
user avatar
0 votes
2 answers
216 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 ...
user avatar
  • 307
0 votes
0 answers
24 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 <...
user avatar
1 vote
0 answers
8 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 ...
user avatar
0 votes
1 answer
72 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() ...
user avatar
1 vote
0 answers
22 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 ...
user avatar
3 votes
1 answer
57 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 ·: ···/...
user avatar
0 votes
1 answer
30 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 ...
user avatar
  • 199
1 vote
2 answers
134 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 ...
user avatar
  • 115
1 vote
2 answers
138 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 ...
user avatar
3 votes
1 answer
116 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 ...
user avatar
  • 2,143
0 votes
0 answers
71 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 (<...
user avatar
  • 101
0 votes
0 answers
26 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 ...
user avatar
0 votes
0 answers
31 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 = ...
user avatar
  • 101
4 votes
0 answers
107 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 ...
user avatar
  • 161
0 votes
1 answer
81 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 ...
user avatar
1 vote
1 answer
26 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 \ ...
user avatar
  • 113
0 votes
1 answer
151 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:...
user avatar
1 vote
0 answers
36 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 (...
user avatar
0 votes
0 answers
76 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 ...
user avatar
  • 1,073
0 votes
1 answer
38 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 ...
user avatar
0 votes
0 answers
67 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 ...
user avatar
  • 2,081
1 vote
1 answer
67 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, ...
user avatar
  • 113
2 votes
0 answers
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?
user avatar
3 votes
0 answers
47 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 ...
user avatar
2 votes
1 answer
70 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 ...
user avatar
  • 353
7 votes
3 answers
8k 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....
user avatar
  • 735
0 votes
2 answers
250 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>:'<,'...
user avatar
  • 135
1 vote
0 answers
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 ...
user avatar
2 votes
2 answers
132 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. ...
user avatar
  • 55
1 vote
2 answers
38 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 ...
user avatar
  • 225
0 votes
2 answers
49 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, ...
user avatar
  • 830
0 votes
1 answer
50 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 ...
user avatar
1 vote
1 answer
95 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 ...
user avatar
1 vote
0 answers
86 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/...
user avatar
  • 1,767
0 votes
1 answer
61 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 ...
user avatar
0 votes
2 answers
213 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 ...
user avatar
  • 101
7 votes
1 answer
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?
user avatar
  • 3,383
2 votes
2 answers
506 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": [ { ...
user avatar
2 votes
1 answer
116 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 ...
user avatar
3 votes
2 answers
784 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 ...
user avatar
1 vote
1 answer
101 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,...
user avatar
  • 181
2 votes
2 answers
641 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 ...
user avatar
  • 33
0 votes
0 answers
750 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 ...
user avatar
1 vote
4 answers
2k 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 ...
user avatar
  • 11
1 vote
1 answer
218 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-...
user avatar
1 vote
3 answers
2k 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 ...
user avatar
  • 446
2 votes
1 answer
366 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 ...
user avatar
  • 23