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
1
vote
1answer
37 views

How can I align the comment at the end of sentences when the comment predictor is already shown?

I want to align commens on multiple lines neatly, and found the following question and answer (I used the tabular package), but then I found out that it needs the comment specifier NOT to be shown on ...
1
vote
0answers
63 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 ...
4
votes
0answers
183 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 ...
1
vote
0answers
51 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: ...
11
votes
2answers
1k views

Remove new line from result of system() [duplicate]

I would like to store the result of a system() call in a variable without the trailing ^@ character. At the moment I do something like var = system('command | xargs -i echo -n "{}"') but it feels ...
4
votes
1answer
246 views

Using `gq` to correctly wrap function arguments

Consider editing the code foo = long_function_name(var_one, var_two, var_three, var_four) where the textwidth 'column' occurs just after var_two. I would like to be able to press gqq on the line ...
2
votes
2answers
162 views

How to format quotes, so that Vim breaks long lines into multiple quotes on multiple lines?

For example, suppose I have this line of JavaScript: console.log( "This is a really long line that I want to format, and it is inside of a quote" ) I'd like to select the quote line in VISUAL-...
1
vote
1answer
144 views

formatoptions for hybrid (short markup + long paragraphs) content

I am trying to write my PhD thesis in vim using LaTeX So the documents will have two distinct types of content - markups that are relatively short, and paragraph text that is rather long. \begin{...
0
votes
1answer
1k views

How to format csv with regex

I have a csv that looks like this: 1,wer123,name,address1,age,2,cde789,name,address1,address2,age,3,529owq,name,address1,age and so on. I want this csv to be formatted as 1, wer123, name, ...
3
votes
1answer
85 views

How do I move by paragraphs, but end up *in* the paragraph?

So I often use repeated invocations of gqip to re-wrap paragraphs of text or comments. Unfortunately, the quickest way I've memorized for moving between paragraphs, }, lands me between them: Qui⁁ut ...
2
votes
1answer
84 views

strftime format support two letter day option

We use a date format that appends the day at the end of the date like so: 20180109tu@1730. Is there any way to get the two letter day format?
1
vote
0answers
539 views

vim + jq :: how to format possibly incorrect text in unsaved file [duplicate]

This is very similar to how-to-run-bash-command-over-current-file-and-replace-buffer-with-result But I need to know how I can access current buffer when the file does not exist? i.e. I open vim goto ...
2
votes
1answer
498 views

Getting vim with yapf to work with anaconda environments

I'm trying to figure out how to get yapf to use my current conda environment when resolving imports. Basically, I just see a ton of the following errors: physics.py|6 col 1 error| [import-error] ...
2
votes
1answer
450 views

Indentation like astyle - continuation lines

I currently use astyle -A8 -t8 -p -j <filename> to format the code in my C project. Is there a way to configure my .vimrc to follow the continuation line format that the above demands? For ...
1
vote
0answers
49 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
1answer
140 views

Split a block to multiple lines with respecting indenting

Context is Ruby. Lets say I have a long line which has a block which I want to have simply in multiple lines: let:(variable) { do.some.stuff(expressed_as_a_long_line { x }) } I'd like split this ...
1
vote
1answer
133 views

Vim equalprg: why does it fail silently on a bash script?

After the command :set equalprg=echo.sh, the equals command simply deletes the specified region. Here is echo.sh: #!/bin/bash echo "$1" Where is the input? I can assign equalprg to something like ...
2
votes
2answers
4k views

vim to interpret escape characters (“\n”, “\t”) as does echo

I need an option in vim to display a text file, say text-file, during the session as would echo -e `cat text-file` | vim - vim is given text-file text-file includes text with escape sequences, such ...
3
votes
1answer
398 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
2answers
210 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
3answers
638 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
2answers
477 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
1answer
3k 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 ...
2
votes
1answer
120 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
1answer
741 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
1answer
83 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
1answer
172 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
0answers
42 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
0answers
186 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
1answer
4k 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 ...
13
votes
3answers
4k 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
1answer
215 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
1answer
461 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
1answer
332 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
1answer
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
1answer
1k 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
2answers
699 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
1answer
117 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
3answers
140 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
1answer
822 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
1answer
572 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 ...
10
votes
5answers
4k 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
0answers
111 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
1answer
2k 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
4answers
774 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 ...
14
votes
2answers
3k 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
0answers
171 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
0answers
118 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
2answers
985 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
1answer
41 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... | ...