Stack Exchange Network

Stack Exchange network consists of 175 Q&A communities including Stack Overflow, the largest, most trusted online community for developers to learn, share their knowledge, and build their careers.

Visit Stack Exchange

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.

1
vote
3answers
50 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 ...
1
vote
1answer
28 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 ...
1
vote
1answer
40 views

How can I format a function declaration to force curly brace at the end of the line?

I have big portions of code where functions are formatted with the opening curly brace on the next line, like this : function foo() { } I'm trying to figure out how to search / replace in order to ...
2
votes
0answers
17 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 ...
3
votes
1answer
67 views

Insert comma on new line in array

I like to format my arrays like this: myArray = [ "lorem" , "ipsum" , "dolor" , "sit" , "amet" ]; If I open a new line below the "amet" line, I ...
0
votes
2answers
35 views

How to convert a sequence of words to a list?

I have the following strings (whitespace and line wise separated) in a file mks asksö askndl ebre nakkl sadj and would like to have it formatted as follows ["mks", "asksö", "askndl"], ["ebre", "...
1
vote
1answer
46 views

xml ftplugin overrides textwidth

I would like to hard wrap XML files during editing. In every other filetype my set textwidth=80 works fine. But in XML something overrides the insertion of line breaks. I tried adding t to ...
4
votes
1answer
316 views

what are the usage of equalprg and formatprg

If I want to format a few lines, should I choose equalprg (using = operator) or formatprg (using gq operator)? Both of them are for some kind of formatting. But what are the differences.
0
votes
1answer
45 views

Automatically reindent lines filtered through formatprg

I have following xml file: <?xml version="1.0" encoding="UTF-8"?> <graph id="G" edgedefault="undirected"> <edge id="e6" source="n5" target="n4"> <data key="d1">1.1</...
1
vote
1answer
55 views

How to make vim display ZWNJ characters correctly?

When I insert a ZWNJ character into text, vim displays <200c> instead of it. Is it possible to make vim to behave normally with this character, like GUI editors? Or is it possible to hide (and ...
1
vote
1answer
38 views

how reformat kegg reconstruct pathway in vim?

I need to reformat the kegg reconstruct pathway output, I have something like this in file1: 00550 Peptidoglycan biosynthesis (2) K01000 K02563 00511 Other glycan degradation (8) K01190 K01191 ...
1
vote
0answers
28 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 ...
2
votes
1answer
106 views

How to autoformat a multi-line string

I want to format a multiline string according to a textwidth of 32. group: - normal: scalar - multiline: "Lorem ipsum dolor sit amet, consetetur sadipscing elitr, sed diam nonumy eirmod tempor ...
1
vote
2answers
62 views

separating folds with constant amount of newlines

Is there a succinct way to separate folds, open or closed, by the same number of newlines throughout the buffer? I'm using fold by indent. The goal is two visible blank lines between each fold (...
1
vote
1answer
92 views

Highlight whitespace using matchadd

I'm trying to use matchadd to highlight different occurrences of whitespace. However, sometimes it doesn't work for some reason. Here is the code: highlight GroupA guibg=lightgreen highlight ...
0
votes
2answers
59 views

Search and replace a pattern with new line except for a pattern

I am having a very long line file, I have to break the line into number of small lines. Example: < this>is a testing< /this>< next>testing< /next>< tested>successfully&...
0
votes
1answer
21 views

Automatic format: how to insert needed amount of spaces for vertical aligning? [duplicate]

Given code: <option id='Nicole' data-language='en-AU'>Australian English - female - Nicole</option> <option id='Russell' data-language='en-AU'>Australian English - female - Russell&...
3
votes
2answers
2k views

How to format JSON file in Vim

Given a file with a large JSON object all on one line like {"versions":[{"count":2,"version":""},{"count":1,"version":"1.1.1"},{"count":14,"version":"2.9"},{... How can I format this to be human ...
1
vote
1answer
84 views

How can I automatically preform operations when a vim *window* is resized?

I'm setting up NeoFormat/ALEfix-style code reformatting, and I'd really like to have it automatically and fluidly reformat the code as the window is resized. This is possible for whole-viewport vim-...
1
vote
1answer
54 views

Dynamically toggle formatoptions based on input

Question: Is there a way to control the indentation + comment leader input, when adding a new line? Details: I am trying to set formatoptions-=cro when inserting a new line (in specific syntax region)...
1
vote
1answer
27 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
35 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 ...
2
votes
0answers
68 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
39 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
2answers
213 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 ...
3
votes
1answer
104 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 ...
1
vote
1answer
64 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
77 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
361 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, ...
1
vote
1answer
46 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 ...
3
votes
1answer
59 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
229 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
301 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
161 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
42 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
70 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
70 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 ...
1
vote
2answers
830 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
133 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
121 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
433 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
272 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)...
4
votes
1answer
1k 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
1answer
101 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 ...
1
vote
1answer
344 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
68 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
129 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
38 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 (...
3
votes
0answers
123 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 ...
3
votes
1answer
2k 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 ...