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.
39
questions with no upvoted or accepted answers
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 ...
5
votes
0
answers
332
views
How to stop vim from reformatting lines inside a codeblock in a markdown file?
I keep the a formatoption in vim when I'm modifying markdown files, so my lines are automatically kept to textwidth characters long, with automatic reformatting when I modify text.
How can I make ...
5
votes
0
answers
194
views
How to align a Latex table that uses \multicolumn?
I want to align a Latex table the way it appears in the final document.
There are various Vim plugins for aligning tables (2, 3, 4), but none of them handle the spanning cell correctly. The code ...
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 ...
4
votes
0
answers
744
views
Can't get autocmd with two events to work
I have the VIM Clang Format Plugin and I would like to format my code every time I save it.
This is in my current .vimrc:
" map to <Leader>cf in C++ code
autocmd FileType c,cpp,objc nnoremap ...
4
votes
0
answers
145
views
Formatting blocks of "commented out" text
I would like to be able to edit and format blocks of comments (in different markup and programming languages) as if the commenting characters (generally in the beginning of the lines) are ignored.
...
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 ...
2
votes
2
answers
814
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"
],
"...
2
votes
0
answers
46
views
Applying full auto-format to comments but not code
I am considering using Vim's auto-format feature (i.e., adding a to formatoptions). However, I can't seem to figure out a combination of options that will give me the configuration that I want. For ...
2
votes
0
answers
289
views
Possible to exclude comments from textwidth?
I recently discovered the textwidth setting, which lets me configure vim to insert a "smart" whitespace-delimited carriage return as I'm typing when my line of text exceeds my specified limit.
Is ...
2
votes
0
answers
152
views
How can I format objects wrapped inside curly braces?
It's pretty common for me to have code like this in Python and Javascript.
my_obj = [
{ id: 0, name: 'foo', age: 123 },
{ id: 1, name: 'foo', age: 321 }
]
What I'd like to automate is ...
2
votes
0
answers
139
views
Can someone explain the strange behaviour with indenting during reformatting?
Recently, someone noticed a strange behaviour with indenting during formatting with my LaTeX plugin, vimtex. I've researched it, and I've ended up creating a minimal example. Load the following code ...
2
votes
0
answers
188
views
Formatting with par, better padding
I've started using
set formatprg=par\ 66q\ g1\ j " keep double spaces, justify
which makes beautifully justified paragraphs. But it would be better if the algorithm preferred to pad after .:;, in ...
1
vote
1
answer
574
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'...
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 ...
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 ...
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 ...
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 ...
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 (...
1
vote
0
answers
938
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/...
1
vote
0
answers
1k
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 ...
1
vote
0
answers
51
views
expandtab tab as 2 spaces show visually as 6 columns
How can 2-space indenting be shown as 6 column tab-style indents when editing, while remaining as 2-spaces?
Background:
a team uses a convention of 2 spaces for indenting code
I prefer indenting of ...
1
vote
0
answers
87
views
Why are my bulleted lines automatically joining?
I use the a formatoption to make my text hard wrap, and the n formatoption to recognize numbered lists. The help says that the n option should use the formatlistpat regex to determine which lines not ...
1
vote
0
answers
58
views
Autoindent with minimal indentation
For some reason, Vim started to indent JavaScript in this crazy manner. I bet it's related to some settings in my syntax plugins, but I can't seem to figure out which ones are causing this behavior:
...
1
vote
0
answers
63
views
Incorrect formatting of file when calling nvim inside NodeJS script
I am formatting elixir files .ex with the help of a contributed plug-in for nvim like this on Windows:
cmd> nvim.exe -i NONE -n -E +"norm gg=G" -cwq c:/file.ex
This works fine when the command is ...
1
vote
0
answers
72
views
How do I reformat a paragraph using a different value for textwidth than the default one?
Sometimes I want to reformat a paragraph using gq but with a different value than the one set in my configuration for this filetype. Since this happens only occasionally within a buffer of such type (...
1
vote
0
answers
190
views
Indentation in three piece comments in javascript
I use Vim 7.4.2149 and the plugin pangloss/vim-javascript for js indentation. I need to get comments like:
/*
*
*/
But instead I get:
/*
*
*
*/
I'm not really interested in syntax ...
1
vote
0
answers
184
views
Using single quotes blows up syntax formatting in .js
Just noticed that using single quotes in javascript blows up automatic formatting sometimes:
See the public/sass/*.sass line:
Double quotes:
gulp.task('compile-sass', function(){
gulp
.src("...
1
vote
2
answers
505
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 ...
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 ...
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 ...
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 ...
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 ...
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 ...
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'....
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 <...
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 ...
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 = ...
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 ...