Stack Exchange Network

Stack Exchange network consists of 174 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.

2
votes
1answer
50 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
33 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", "...
0
votes
1answer
24 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 ...
0
votes
1answer
57 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
34 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
42 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
37 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
26 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
80 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 ...
0
votes
0answers
75 views

E20: mark not set error occurs sometimes

I am editing latex1 prose in vim. For paragraph reformatting, I am using the par text formatter. I have set up the following autocommand for latex-files, to map A-q for reformatting the whole ...
1
vote
2answers
59 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
62 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
56 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
18 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&...
1
vote
1answer
453 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 ...
0
votes
1answer
58 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-...
0
votes
0answers
53 views

Compabitibility between vim and emacs style modelines

I'm a long-time vim user. Today I learned something new: modeline(s). For the many years, 15+, that I've used vim, I've handled this through autocommands for specific file types. Today, while ...
1
vote
1answer
43 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
24 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
32 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
0answers
41 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 ...
0
votes
0answers
49 views

formatlistpat — unexpected regex behaviour

Here is a corrected version. The formatlistpat now works. The regex behaves as expected. I leave this question open, because during my tests I came across a warning saying I had too many brackets (I ...
1
vote
0answers
34 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: ...
0
votes
2answers
114 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
83 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
37 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-...
0
votes
0answers
17 views

Alter formatting behavior of comments in texfiles

While editing .tex files, I like to maintain a textwidth of 80 characters. And so I frequently do things like gqq to format a line after editing. But sometimes I've commented out something at the end ...
1
vote
1answer
71 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
123 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, ...
0
votes
0answers
28 views

Formatting inside of enclosures in insert mode

I have been searching for a plugin or setting that does the following for a while. When in insert mode, write function: function doSomething()_ where _ is the cursor I want to be able to use vim ...
1
vote
1answer
42 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
51 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
148 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
245 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
143 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
67 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
57 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 ...
0
votes
2answers
555 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
121 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
109 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
403 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, ...
0
votes
0answers
45 views

How to show single spaces and tabs as different characters? [duplicate]

So we use some ridiculous linter which won't allow me to commit when I have spaces instead of tabs. It would tell me it saw 12 spaces instead of 3 tabs and so on. I've looked at threads like this and ...
2
votes
2answers
234 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
716 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
95 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
269 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
66 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
117 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
37 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 (...