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
3
votes
1
answer
699
views
How to set nowrapscan when formatting text with gq
When I was editing a fairly large text, I accidentally hit gq* instead of gq} and then vim apparently seemed to freeze a moment with the message search hit BOTTOM, continuing at TOP displayed in the ...
1
vote
2
answers
291
views
Automatically add '>' at beginning of line following one starting with '>' when writing Markdown
When writing block quotes Markdown, I want to make vim act the same way it does with comment leaders and automatically start new lines with the '>'. I also want to be able to format text this way with ...
1
vote
3
answers
795
views
simple map to right align text selection within visual block?
This should be easy but it seems to be a blind spot in vim. I'm looking for a short one line mapping, let's say to <leader>r, to right-align text inside a visual block selection. For example, ...
2
votes
2
answers
742
views
set formatprg dynamically based on textwidth?
I've set formatprg in my vimrc to use the par text formatter when I type gq.
setg formatprg=par\ -w90
When I'm in a buffer whose textwidth has been set (e.g. the gitcommit filetype sets textwidth=72)...
5
votes
2
answers
4k
views
Expand <TAB> into 2 spaces when and only when editing HTML
My current configuration makes vim automatically expand TAB to 4 spaces for me:
" Define tab as 4 spaces
" Taken from http://stackoverflow.com/questions/1878974/redefine-tab-as-4-spaces
set tabstop=4 ...
3
votes
1
answer
153
views
How to avoid indenting after a line that starts with a number?
I use Vim to write longer sequences of body text. It does automatic formatting, which generally works nicely. If I have a sentence that ends in a number, say a date or a year, and that number happens ...
2
votes
1
answer
907
views
vim cannot access variable in autocmd
I am trying to configure prettier-eslint and prettier-standard as the js formatter with neoformat:
" neoformat should try formatprg where available
let g:neoformat_try_formatprg = 1
augroup vimrc
" ...
1
vote
1
answer
97
views
How to repeat a certain operation across lines of code? [duplicate]
I need to repeat a certain operation across several lines of code spread through out the code base. For instance,
x = y;
needs to be replaced with
EQUATE(x,y);
However each instance needs to be ...
3
votes
1
answer
262
views
prevent neovim from breaking one markdown bullet point into multiple ones
I have this markdown text:
* Lorem Ipsum is simply dummy text of the printing and typesetting industry. Lorem Ipsum has been the industry's standard dummy text ever since the 1500s, when an unknown ...
1
vote
0
answers
66
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 (...
2
votes
0
answers
268
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 ...
4
votes
1
answer
6k
views
What is the significance of "Incomplete last line" when opening a file?
I occasionally open a file with vim and see something like this:
"<file name>" [Incomplete last line][dos format] 71 lines, 2912 characters
I understand all of that information except ...
16
votes
3
answers
6k
views
automatically rewrap lines when writing markdown in VIM
Very often, I write markdown in VIM, and there will be paragraphs in those markdown. To help my editing, I setup my Vim to wrap a line on 80 chars. It works nice if I just keep typing, but the problem ...
0
votes
1
answer
384
views
Vim: plugin to change all decimal points?
CSV.vim plugin has an ability to change the column deliminator/separator. I would like to find a plugin by which I can change all decimal points (such as comma) to dot, does there exist plugin to do ...
-1
votes
1
answer
718
views
CSV columns visually divided in the separators to equal spaces like tabstops with CSV.vim?
When you open a CSV file with the CSV.vim plugin the separators, such as semicolons, do not visually divide the columns in a format like the screenshot below. How can I visually separate the columns ...
5
votes
1
answer
463
views
Can auto-format break at hyphens?
I write my email in vim, which dynamically inserts newlines after 72 characters.
formatoptions=awtcql
This works nicely, breaking at spaces. However, is there a way to make it break at hyphens as ...
4
votes
1
answer
1k
views
Autoindent second line of plain text bullet list item
When using plain text I write bullet lists like this (second and further lines indented with two spaces):
* blah blah blah
blah blah
* yadda yadda yadda
Problem is, when I start out a new bullet ...
0
votes
1
answer
2k
views
How to break long line of xml files only on display not in the actual code [closed]
I have an xml file with some text which is so long, that it does not fit into the normal line of my editor.
Is there an xml-specific way to insert a newline just for formatting, i.e. ignored by a ...
0
votes
2
answers
778
views
Use visual mode to convert text to unicode bold formats?
How can I make it so when in visual mode, pressing b will toggle highlighted text to its bold unicode counterpart?
This is what I mean by its Unicode counterpart:
http://qaz.wtf/u/convert.cgi?text=...
1
vote
1
answer
139
views
How to set formatoption so that a blank line isn't needed between two paragraphs?
I primarily use Vim for text processing, so in order to lighten that process, I've set some parameters in my .vimrc:
set fo=ant
set tw=80
set ts=3
set nojoinspaces
The nojoinspaces parameter is set ...
3
votes
3
answers
217
views
How can I toggle between single and multi-line expressions of arrays?
This is probably easier to explain with an example. I prefer expressing things like
const array = { a: 1, b: 2, c: 3 }
on a single line at first but eventually I might want to switch to
const array ...
3
votes
1
answer
1k
views
Function argument editing
I've been using paredit.vim for editing Clojure files. It's quite successful in managing all those parentheses in a sane way. I'm looking for a similar way for editing function calls in other ...
1
vote
1
answer
810
views
How to make formatoptions+=a useful?
I was interested in the set formatoptions+=a option, but even if the idea of reformatting comment in my code or even markdown text is seducing, I cannot really use the feature because I cannot write ...
11
votes
5
answers
7k
views
set formatoptions in vimrc is being ignored
Vim automatically continues a comment when I press Enter in Insert mode, which I find helpful.
However, I do not want the comment continued after pressing 'o' from normal mode to insert a new line ...
2
votes
0
answers
129
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
1
answer
5k
views
Key binding for enter key in insert mode
I want to be able to run a script to indent the line of code I have just written each time I press enter key in insert mode.
More concretely,currently I use following key binding:
map <C-K> :...
10
votes
4
answers
1k
views
Line number specific text-width setting
I use gvim for writing emails and use tw=72 to break long lines. Now I also edit basic mail headers in the same document, e.g. I am adding recipients to my mail. Now with tw=72 it also breaks every ...
17
votes
2
answers
5k
views
Why Vim sets max text width to 79 instead of 80?
I'm a little puzzled about some default values in Vim.
In particular, for gq{motion}, is said that
[...]
If the 'textwidth' option is 0, the formatted line
length is the screen width (with a maximum ...
1
vote
0
answers
189
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 ...
2
votes
0
answers
132
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
2
answers
1k
views
Transforming a long table into multiple columns
Suppose I have the following table:
E 12.02
T 9.10
A 8.12
O 7.68
I 7.31
N 6.95
S 6.28
R 6.02
H 5.92
D 4.32
L 3.98
U 2.88
C 2.71
M 2.61
F 2.30
Y 2.11
W 2.09
G 2.03
...
1
vote
1
answer
48
views
"Change" as much whitespace as necessary
I'm editing a table in extended-markdown, and I'm wondering how to easily edit cells without moving the dividing lines.
Tables are formatted like this:
| HEADING1 | HEADING2 | etc...
| ...
5
votes
2
answers
1k
views
How to set the relative indent after breaking Python lines?
When I insert a line break inside a line of Python 3 code, the remaining part of the line is indented by two additional tab widths (2 time 4 spaces) in the next line.
# Before
example_function(...
3
votes
5
answers
1k
views
How to conveniently add ornate headers to source code?
Currently I’m adding source sections manually, e.g.:
/*******************************************************************************
* entry point
*******************...
5
votes
1
answer
210
views
gqip for VHDL comments does not work
After I set syntax=vhdl and set fo=tcq, running gqip on the following paragraph does not work as expected:
-- Lorem ipsum dolor sit amet,
-- tempor incididunt ut labore et dolore magna aliqua. Ut ...
13
votes
3
answers
1k
views
How to automatically lower case the second letter of a word?
When I have to type a lot of text I often tend to keep my finger pressed on shift when I write the first letter of a sentence which often give:
[...]end of sentence. NEw sentence[...]
Here the E of ...
1
vote
3
answers
427
views
Conversion from XML to KML
I have an XML file with this format (there could be some leading spaces):
<Latitude>23.1138</Latitude>
<Longitude>8.2898</Longitude>
...
<Latitude>19....
0
votes
2
answers
1k
views
How to remove line breaks in xml tags?
I often have to write XML where text-width has been manually set by another editor:
<context>
<p>Here is a paragraph about some stuff that happened
and someone did a nice ...
5
votes
1
answer
576
views
Make autoformating insert a line break instead of two spaces after full stop
I noticed that vi's auto format adds two spaces after a full stop. I wonder how this can be changed, i.e., insert just one space after a full stop, or even a line break.
The application is in using a ...
4
votes
1
answer
426
views
Vim Pandoc & Headers
When using vim-pandoc, I'm having some funny behavior with headers:
For instance,
if I position the cursor on a word and press v-a-w and then <localleader> - i, I get italics.
if I position ...
2
votes
2
answers
562
views
Pandoc and formatting
I'm using the vim-pandoc and vim-pandoc-syntax bundles in neovim. I'm converting the markdown to a docx file and I'm seeing that I need to do a double space in order to get a carriage return in the ...
3
votes
1
answer
291
views
How to search and format a text range?
I want to format a block of text and I am using a range to select the leading comment of a function. It's all lines starting with // ....
I'm using the range
:?^[^\/][^\/]?+1,/^[^\/][^\/]/-1
to ...
3
votes
1
answer
77
views
Switching back and forth between two text layout conventions of input to LaTeX
While using git and other versioning systems, it is very useful that text lines occupy no more than (say) 80 characters. It is also more comfortable to edit text with vi if lines are note excessively ...
2
votes
1
answer
48
views
Opening a new line without returning the carriage
Say I want to begin letters like this:
Dear world,
hello.
What's the simplest way to define a mapping that opens a new line preserving the cursor's horizontal position?
5
votes
2
answers
1k
views
How can I make vim's flowing aware of email replies?
Problem summary
I use vim to edit emails that I send with mutt. I also use format=flowed, which "reflows" text. That is, lines are limited to a fixed number of characters, and a "soft wrap" is ...
6
votes
2
answers
635
views
Is it possible to create a folding inside a single line?
The chapter 28 of User Manual says the following about folding:
Folding is used to show a range of lines in the buffer as a single line on the screen.
And all the examples of folding that I've ...
2
votes
1
answer
115
views
A script and keybindings to look for VIM commands in a file, and then execute them on that file
This is a followup question to Auto sorting of lists of include files, which explains the motivation.
EDIT
I am looking for a script and/or keybindings to look for VIM commands in a file, and then ...
2
votes
1
answer
81
views
Difference between autoformat and autoindent
What is difference between autoformat and autoindent? What are most popular solutions in text formating in vim of both of these methods?
2
votes
0
answers
181
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 ...
2
votes
1
answer
111
views
Conflict: concealment and paragraph formatting
When formatting paragraphs with concealed elements, the formatting program does not take into account that some characters are invisible, and renders some lines shorter than the rest, when using the ...