Questions tagged [indentation]

Prefixing lines with whitespace to aid in readability.

Filter by
Sorted by
Tagged with
16
votes
4answers
18k views

How can I change the indent size?

I just discovered I could indent and un-indent easily in Vi with : << and >> By default it adds a tab character. Now I'm wondering, could this be to a number of spaces via a configuration in my ...
1
vote
1answer
67 views

equalprg with lisp (clojure) and custom indent settings

How do I make equalprg match my custom indent settings? They are like: let b:did_indent = 1 set expandtab set shiftwidth=2 set softtabstop=2 set autoindent And they format the code to this (...
0
votes
1answer
19 views

How to have the cursor at the right indentation when editing PHP/HTML

When I'm working with HTML in a PHP file and I press enter while in INSERT mode, my cursor goes to the start of the next line instead of going at the right positive therefore I have to press tab to ...
2
votes
1answer
39 views

Format / Indent c++ as you type inside expressions

In visual studio, that code : for(int x=0;x<10;x++) {} becomes that code : for (int x = 0; x < 10; x++) { } as soon as you hit enter. I was wondering, is it possible, and if so, how can I ...
1
vote
1answer
82 views

How to stop “tab” key indenting whole line

In one version of VIM that I run, when I hit the "tab" key in insert mode, it indents the whole line, regardless of the cursors position in the line. Here is what I believe to be the only modified ...
1
vote
1answer
64 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)...
34
votes
4answers
7k views

How can I change the default indentation based on filetype?

I'd like to have different indentations based on the type of file I am working on. For example, working on a .c file I'd like my indentation be 4 spaces. In .html files I'd like to (have to) work with ...
2
votes
4answers
238 views

Paste in normal mode ignores autoindent

When I paste something within normal mode, vim ignores autoindent. I copy and paste with y and p. As mentioned autoindent is on. It works fine when I manually indent or type something before pasting. ...
1
vote
0answers
21 views

Where can I find good indentation file for lex filetype?

I checked and found only a syntax file for lex filetypes in /usr/share/nvim/runtime/syntax, but found no indent file in /usr/share/nvim/runtime/indent I want my lex files to be properly indented; one ...
3
votes
2answers
620 views

How to disable auto-indent when pasting in BusyBox's Vi?

I have a Vi running as BusyBox executable (VMware ESXi): $ vi --version BusyBox v1.20.2 (2014-08-27 12:48:18 PDT) multi-call binary. Is there a way to disable auto-indent when pasting the code? ...
2
votes
1answer
46 views

Why does vim still auto-indent LaTeX after I set noai noci nosi?

I want to disable autoindent and smartindent for LaTeX so I did :set noai noci nosi When I open a brand new mwe.tex, filetype=plaintex and there is no auto indent magic. When I then enter some code,...
5
votes
1answer
227 views

Indentation in Latex within a list after an equation

Here is a minimal .tex file: \begin{document} \begin{itemize} \item Here is an equation: \begin{align*} x = y \end{align*} \item Here is another item ...
5
votes
2answers
2k views

How can I fix the auto indentation in LaTeX?

Vim has some fancy pants indentation stuff. When it works right it's a pleasure to have, but sometimes it just drives me nuts. One that I've never been able to solve has to do with LaTeX syntax. Lets ...
1
vote
2answers
55 views

How to move a cursor to the last line with auto indent?

Assume autoindent is set, and you have the buffer below. Note the cursor is represented as I. for i in range(1, 6): print(i)I When you hit Enter key, you get this. for i in range(1, 6): ...
2
votes
3answers
69 views

How to indent or unindent lines in a block of text?

I use two spaces in my indentation of codes. What are the possible ways to indent or unindent a block of code?
1
vote
0answers
18 views

How to get the right indentation and new line when adding a new line between brackets? [duplicate]

So I am curious about one thing: when I am between two brackets ({) in vim (or nvim), and I press Enter I go from this (where the pipe sign is the cursor): getUsers(){|} to this: getUsers(){ |} ...
1
vote
1answer
31 views

How to stop auto indent for some file with particular suffix

In my .vimrc file, I add few lines to it so that some file could have nice auto indent, such as .f90 and .c file, but it also cause autoindent for .plt file. Is there some way like if statement that ...
1
vote
2answers
52 views

Plugin to show enclosing indentation levels

I'm looking for functionality which may or may not exist. Basically, I'd like to have a location list split at the top of each writable buffer which shows the last line of each enclosing indentation ...
0
votes
0answers
23 views

vim disable behavior special tags (eg script)

When editing html, vim applies different rules when inside certain tags (like script/pre/style). I want to have the normal html rules when inside a script tag (using handlebars, and I don't write any ...
7
votes
2answers
2k views

Vim doesn't use the correct indentation in Python files

I have encountered something that I have never seen before in Vim. While I was tentatively modifying some of the source code for software I've been planning to work on, I noticed vim was displaying ...
0
votes
1answer
21 views

'filetype plugin indent on' breaks indention [closed]

Using vim 8.*, I am using these plugins: html5.vim polymer-ide.vim supertab vim-javascript In my vimrc.local file if I enable filetype plugin indent on it breaks my javaScript indention but makes the ...
2
votes
1answer
146 views

How to make a newline without autoindent

Is there a command to make a newline without the autoindent? In other words, I want o and O to normally autoindent, but is there another command that will not autoindent for just the duration of that ...
1
vote
0answers
30 views

How to indent HTML5 with omitted closing tags properly?

I try writing some HTML5 with omitted closing tags in NVIM v0.3.4, and get this: <ol> <li>3 <li>4 <li>8 <li>9 </ol> This ...
1
vote
1answer
23 views

Match indentation upon newline without replacing spaces with tabs or vice versa

When I create a new line or hit o I have Vim configured to match the previous indentation. However, since I use hard tabs in most places, vim will replace any spaces that are greater than or equal to ...
2
votes
2answers
771 views

Can vimwiki be made to treat list indentation the way vim-notes does?

I've looked through the vimwiki documentation and a few questions here on SO, but don't see how I can manage this. In vim-notes, hitting TAB within a list indents the entire list item. In vimwiki, ...
0
votes
3answers
127 views

Substitute tabs for equivalent number of spaces

N.B I use the word blank here due to lack of a better word. By blank I mean the remaining part of a tab that is visualized after the starting part. Please feel free to edit this question. I know ...
0
votes
1answer
40 views

Indentation script does not work for all occurrence

I have following c.vim file: imap {<CR> {<CR>}<Esc>O imap [ []<Left> imap # #include<><Left> command F %s/\v(\w) ?(\+|-|\*|\/|\>\=|\<\=|!\=|\=|\=\=) ?(\w|-)/...
0
votes
1answer
20 views

Indent text to beginning of line

Sometimes I'll have some text with an arbitrary indentation. Sample text. If I want to bring this text back to the beginning of the line, I'll visually select the line and then ...
1
vote
1answer
46 views

Multi-line array variable in bash with filetype sh does not indent correctly

I have the following bash array after automatic indentation, both on pressing carriage return when was editing in :h Insert mode and doing =ip on the block in :h Normal-mode DOTFILES=( ".bashrc" "....
0
votes
1answer
4k views

Automatic whitespace in python

I'm a novice in Vim and configuring it for writing python scripts comfortably. Is the a way to automatically put four spaces after I jump onto the first line of while True: loop ?
0
votes
1answer
29 views

How can I reindent/prettyify blocks of HTML code?

I've got a lot of HTML files, some of them with garbage indentation. How can I select a block, and then prettify/reindent the HTML within, adding in newlines where appropriate? I can install any ...
0
votes
0answers
25 views

How do I get Vim (with TComment) to do proper block comments in OCaml?

(I have TComment installed, and I'm on NeoVim 0.4.0.) Given this code, for example: let mem key st = let is_matching_key = function | Positional _ -> false | Flag f -> f.name == key ...
1
vote
1answer
263 views

Set Indentation when Declaring Constructors for C++ Classes with Inheritance

I've been using vim for two years but there are many things I don't know very well. Today, I was coding in c++ and found that I wanted to type the snippet like this: Horse(COLOR color, HANDS height, ...
0
votes
0answers
42 views

In PHP files, how can I auto close HTML tag pairs and indent the new line?

I have been a Vim user for several years now and I haven't been able to find a solution to this issue. There have been a lot of questions on the internet that try to address it, but none of the ...
4
votes
1answer
75 views

How to visually select based on indentation?

If someone is editing the following javascript file: let foo = true if (foo) { let bar = 42 // moooooore code... } You can use vi{ anywhere on the line with let bar to select let bar = 42 and ...
0
votes
1answer
42 views

inoremap inserts unwanted tabs

I recently made myself custom insert mode keybindings to type faster in LaTeX. However, When I use them, Vim adds tabs that weren't part of the original keybinding. Example: Here is my inoremap: ...
4
votes
1answer
117 views

Motion to jump back one level of indentation, not including blank lines

I've been authoring a lot of F# in Vim lately. Like Python it is pretty strictly indentation-based. However, unlike Python mode for Vim, it does not appear that the standard F# Vim plugin supports any ...
1
vote
2answers
162 views

What is valid use case for `smartindent`?

I might not have discovered everything about it, but the smartindent option has given me much more trouble than usefulness. For example, it indents a line beginning with for or if, and won't shift a ...
1
vote
1answer
34 views

Indenting a c file adds spaces before function's type?

Open a c file and then type: int main and then hit: gg=G It becomes int main Is this an intended behavior? Is there a way to change this? I prefer it to be retained as is because most ...
9
votes
1answer
322 views

Disabling partial HTML indentation in Vim

Caveat: I'm not a web developer. That being said, there are rare occasions where I have to edit HTML. When I do, I've noticed a behavior in Vim that I don't like, and hope that I can change via ...
27
votes
8answers
1k views

How do I move vertically until reaching a non-whitespace character?

In a very long file with (accurately-) indented code, it may be helpful to move directly to a line of text above or below the cursor which delimits the indenting. (One way of doing this could be via ...
0
votes
1answer
38 views

LaTeX indent for \iff error in vim

With the minimal vimrc (with vimtex plugin): set nocp filetype plugin indent on syntax on set st=2 set acd set wildmenu set wildmode=longest,list,full let $USRPLUGD=$HOME.'\vimfiles\myvim\plugged' ...
1
vote
1answer
154 views

How to show 2 spaces as tabs in listchar?

I like to see my indentation level with listchars=tab:\|\ But one project uses two spaces instead. Is there any way to show indentation level lines then? This question seems to the opposite of Show ...
1
vote
1answer
96 views

Keep relative cursor position after indenting with >>

Can I setup >> to keep the relative cursor position? For example, assuming the line is def fun(<cursor>): can I make >> result in def fun(<cursor>): ? Obviously, with ...
0
votes
1answer
67 views

Copy and paste with breakindent set

I'm using breakindent to make long lines wraparound to the same indentation level as the start of the line. Unfortunately, with this setting on system copy and paste (in this case, out of the macOS ...
2
votes
6answers
295 views

Indent on New Line between HTML/XML Tags

I'm currently using imap <silent> <C-c> </<C-X><C-O><C-X><Esc>F<i as per this post and this page to close <></> tags of any kind with <C-c&...
2
votes
1answer
664 views

How do I make the yaml indent not indent lists?

OK so I would like to change the way that my yaml gets indented. Right now my vim indents a yaml list like this: list: - this - is - a list dict: this: is a dict I would like it to indent ...
0
votes
1answer
49 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
235 views

Incorrect auto-indent bash

Result of auto-indent in vim (filetype indent on) main() { case $1 in --ssh) echo "sshing into ${aws_ips[$1]}" ssh -i VPN_NODE_1.pem ${aws_ips[$1]} ;; --scp) ...
1
vote
0answers
31 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 ...