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.
188
questions
0
votes
1
answer
79
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 ...
1
vote
2
answers
179
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 ...
0
votes
2
answers
53
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 ...
0
votes
1
answer
18
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 ...
0
votes
3
answers
117
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, ...
0
votes
0
answers
245
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 ...
1
vote
0
answers
136
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 ...
0
votes
0
answers
63
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 ...
6
votes
1
answer
498
views
What does breakat&vim mean?
I'm trying to understand this SO answer. The snippet reads:
:set nolist wrap linebreak breakat&vim
0
votes
0
answers
290
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-...
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 ...
3
votes
2
answers
79
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:
...
0
votes
3
answers
70
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
0
votes
1
answer
538
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 ...
8
votes
1
answer
355
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 ...
1
vote
1
answer
78
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 ...
0
votes
0
answers
161
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 ...
0
votes
0
answers
41
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'....
6
votes
6
answers
13k
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 ...
0
votes
0
answers
145
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 <...
3
votes
0
answers
18
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 ...
0
votes
1
answer
275
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()
...
1
vote
0
answers
23
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 ...
3
votes
1
answer
161
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 ·:
···/...
0
votes
1
answer
34
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
2
answers
310
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 ...
2
votes
2
answers
448
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 ...
3
votes
1
answer
275
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
0
answers
31
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
0
answers
47
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 = ...
6
votes
0
answers
393
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
1
answer
161
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 ...
1
vote
1
answer
32
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
1
answer
256
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:...
1
vote
0
answers
38
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 (...
1
vote
2
answers
314
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 ...
0
votes
1
answer
50
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
0
answers
201
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
1
answer
140
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
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?
4
votes
0
answers
50
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
1
answer
105
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 ...
9
votes
3
answers
15k
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....
0
votes
2
answers
655
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
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 ...
2
votes
2
answers
178
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
2
answers
46
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
2
answers
79
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
1
answer
55
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 ...
1
vote
1
answer
106
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 ...