Questions tagged [indentation]

For questions about prefixing lines with whitespace to aid in readability.

Filter by
Sorted by
Tagged with
3
votes
2answers
345 views

How to change the displayed indentation amount?

You and your collaborators have different preferences for how to indent your files. Obviously they have a barbaric suggestion, whether that's tabs, spaces or something else, doesn't matter, it's ...
3
votes
1answer
471 views

Auto Indent (the = key) of C switch block

For the following switch block: If I select the switch block and apply the auto format command, the = key, I get the following: The block is formatted correctly in the first image, but it gets ...
3
votes
3answers
163 views

How can I indent selected lines in Visual mode by space granularity instead of TABs?

How can I indent lines selected in Visual mode using space granularity instead of than TABs (i.e. < or >)? Sometimes when coding Python, I need to indent lines to a level that is not a TAB ...
3
votes
2answers
346 views

Is there a way to indent and outdent lines without moving the cursor?

I often escape insert mode only to change the current line's indent by pressing >> or << and then immediately go back to writing. I wanted to make this easier, so I included these lines on ...
3
votes
1answer
420 views

How do I control how vim indents ruby blocks?

When I start a ruby block in the middle of a line, the next line is indented deeper than I'd like. It's indented from the start of the block, not the start of the line. Example: some_variable_name =...
3
votes
2answers
786 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? ...
3
votes
1answer
319 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 ...
3
votes
2answers
2k views

How to disable bad indentation when pasting text?

I am using vim and simply want to disable auto indent when I paste text into my terminal vim session. I have tried numerous solutions including various incantations of below to ~/.vimrc: set nopaste &...
3
votes
1answer
72 views

How do you get two `match`es at the same time to work? [duplicate]

I have two match lines in my vimrc. they work when they are used by themselves but when i try to uncomment both i don't get any matching behavior: " highlight spaces used for indenting match Visual /^...
3
votes
1answer
549 views

Why `v:lnum` doesn't return 1 for the first line?

I really want to know why doesn't Vim's v:lnum return 1 for very first line. I tried googling and searching in Vim's docs, but I can't find an answer. I understand that v:lnum returns line number, ...
3
votes
1answer
458 views

How to skip over indentation whitespace with horizontal motion?

I have a file that uses 4-space indentation. By default, when I move horizontally, Vim moves over those spaces one by one. How can I configure Vim so that it moves 4 spaces horizontally when moving ...
3
votes
1answer
277 views

autoindent different from manuall indenting

We have a custom filetype at work which I use with a plugin i've written. There we have a construct like this: \item some text. it is indented on level more than the \item tag \item the next item ...
3
votes
1answer
936 views

How to make auto-indentation work correctly after macros ending with semicolons

I'm using cindent with C++ sources, and when I put some macro, which already ends with a semicolon, like Qt's Q_OBJECT, cindent doesn't understand it and makes an extra indentation on the next line. ...
3
votes
1answer
123 views

How can I make fmt return leading spaces instead of tabs?

When I use vim to write regular text (not source code), I often highlight a long line, or a paragraph, and do: !fmt to re-format the lines into proper length lines. I think they up up being 75 ...
3
votes
4answers
688 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. ...
3
votes
1answer
166 views

Does each indention option override the previous one?

From :h indent.txt: ...each one overrides the previous if it is enabled... Now if I set 'cin' after 'ai', Does 'cin' disable the effect of 'ai'?. If no, so what is the purpose of "override" ...
3
votes
2answers
460 views

Create a new line with indentation matching the cursor position

I am looking for a way to create a newline with an indentation equal to the current column position of my cursor. Here is an example. Say I'm editing some line of code looking like this, with my ...
3
votes
1answer
512 views

Wrong indentation for fortran forall

I'm using Neovim to edit Fortran 90 files and if I type the one-liner: forall(i=1:10) b(i) = i Neovim will always assume that it has a forall block and indent the following lines (til the end of the ...
3
votes
2answers
657 views

Lag from filetype plugin indent on

I'm getting lag in vim when navigating relatively small text files if filetype plugin indent on is uncommented in my vimrc file. My full vimrc file is pasted below. Any help on how I can get it ...
3
votes
1answer
47 views

LaTeX: turn off text wrap and auto indent in maths environments

I use vim with vim-latex for editing latex files. I always have hard wrapping enabled using set tw=80. I also have the default vim-latex auto indent settings enabled. I wonder if there is a way to ...
3
votes
0answers
164 views

Why does Vim smartindent on one computer and not another?

I have the following in my .vimrc on both machines: filetype plugin indent on syntax on And yet, for some reason I only see the expected behavior on my Mac, and not on the other computer (which is a ...
3
votes
0answers
133 views

Formatting blocks of "commented out" text

I would like to be able to edit and format blocks of comments (in different markup and programming languages) as if the commenting characters (generally in the beginning of the lines) are ignored. ...
3
votes
0answers
242 views

Is there a way to add handlebars to html.vim?

I'm working with handlebars right now and I'd like to get tags like: {{#component 'whatever'}} {{/component}} and {{#if}} {{else}} {{/if}} to increase the indent count. Unfortunately, it doesn'...
2
votes
1answer
4k views

How to unindent code blocks?

For indenting there's no problem. I enter the visual-block mode, select the block, enter insert mode, press ctrl-t (or just press tab), exit the visual-block mode, and the whole block is indented. ...
2
votes
1answer
249 views

expandtab not replacing tabs after space separated characters

Running vim with the following settings: expandtab tabstop=4 softtabstop=4 shiftwidth=4 And no other user plugins. In insert mode... If I enter: a<Tab>b<Tab>c all tabs are replaced ...
2
votes
3answers
261 views

How to change indentation in "case" with curly braces? [duplicate]

The default is this: switch(x) { case a: { y(); } } But I need this: switch(x) { case a: { y(); } } With :set cindent and :set cino={-s this is ...
2
votes
1answer
531 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, ...
2
votes
2answers
263 views

Is there a way to hide leading whitespace?

Some of the files I am editing have a huge amount of whitespace leading before each line, for example: module Something module Inside class FinallyClass def ...
2
votes
1answer
573 views

Function to refactor indents and tabs

I'm writing a vim function to set hard tabs and refactor indents in a whole file. This is the function: function RefInd() :set tabstop=4 softtabstop=0 noexpandtab shiftwidth=4 gg=G ...
2
votes
3answers
476 views

Pasting text on Vim inside tmux breaks indentation

Ubuntu: 18.04 bionic tmux: version 2.6 VIM: Vi IMproved 8.0 (2016 Sep 12, compiled Jun 06 2019 ) Included patches: 1-1453 Modified by pkg-vim-maintainers@lists.alioth.debian.org Compiled by pkg-vim-...
2
votes
2answers
890 views

Auto indent turns off itself automatically on php files

I don't get it, my vimrc has set ai, but when editing project files (php), :set ai? always returns noautoindent inside .vimrc :set ai? returns true. my rc: " vim-plug (https://github.com/junegunn/...
2
votes
1answer
533 views

Trigger reindentation after snippet has expanded to word in 'indentkeys'

The ftplugin vimtex provides the file indent/tex.vim with following line setlocal indentkeys+=[,(,{,),},],\&,=item,=else,=fi 'indentkeys' 'indk' string (default "0{,0},:,0#,!^F,o,O,e") ...
2
votes
1answer
232 views

Indenting schema, is there a sort of thing you can load/configure into "=" in vim?

I don't know what vim cannot do, so far, I feel it is so powerful! I need indent in Normal Mode for c++ code. I found vim is using "=" to that, just visual/mouse select the code and hit "=" key, or ...
2
votes
1answer
191 views

`normal` does not seem to allow automatic indentation

Why does this not work as expected? function! MyO() normal! o endfunction nnoremap TT :call MyO()<cr>i If this is the situation: | an indented text ^ (normal mode) typing o gives: ...
2
votes
1answer
133 views

Understanding indenting rules for C++ files

Why is the following C++ source file indented like this, #include <vector> int main() { std::vector<std::vector<int>> v{ {1,2}, {1,1}, {1,2} };...
2
votes
1answer
179 views

Override indentation settings with autocmd

When editing Typescript neovim automatically sets indentexpr=GetTypescriptIndent(). I don't like the way it aligns to an open brace instead of inserting a (soft) tab or two, but it doesn't seem to be ...
2
votes
3answers
3k 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?
2
votes
3answers
130 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 ...
2
votes
1answer
3k 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> :...
2
votes
1answer
2k views

vim indentation setup - Ruby [closed]

I have a problem with indentation using vim. Lets say I have a file: class My end // <-- cursor is here When I press O vim will create new line in between class and end and it will be indented. ...
2
votes
1answer
22 views

text object for current indentation level? [duplicate]

Say I have an indented block like so int main(int argc, char **argv){ printf ("odd numbers between 1 and 10:\n"); // level 1 for (int i = 1; i <= 10 ; i ++) { // ...
2
votes
1answer
38 views

bad comment behavior in cmake files

When I'm editing a cmake file in (neo)vim I'm getting bad behavior block inserting comment characters. Given this section of text install_license_file( PACKAGE tomcrypt TARGET ...
2
votes
1answer
66 views

What option controls how much space is added after a new line?

When I set tw vim will auto wrap lines at tw. When breaking that line vim usually places some spaces to keep the indentation of the previous line. Example foo bar<suppose that a wrap happens ...
2
votes
1answer
74 views

What is necessary to properly indent shell scripts with gg=G?

I was editing a small configure script and noticed that vim's indentation of the file was not working properly. A sample of the original source follows: while getopts 'dgSsx' opt; do case $opt ...
2
votes
1answer
2k views

How to set custom shortcut in vim?

I want to make use of Shift+Tab to left-shift (unindent) a block of text, instead of Ctrl+d. How to do it?
2
votes
2answers
59 views

Fix indentation in a file while keeping cursor on the same line

I'd like to use vim's builtin indent fix feature on an entire file. I have looked up answers, but all I found were suggestions to type gg=G, the only problem being that it brings your cursor to the ...
2
votes
1answer
207 views

How to disable intelligent indent for text/markdown files?

Since ever in my configuration of vim text and markdown-files are indented on following lines to align with open parenthesis. Text Text Text (e.g. Hello World) More Text This happens ...
2
votes
1answer
300 views

NeoVim indents each property:value in CSS

I have a style element in an HTML file. When I type, NeoVim continuously indents each successive line: In my Vim, it works correctly: My vimrc. I would be grateful for any suggestion. Thanks!
2
votes
1answer
291 views

vim suddenly stops indenting and uses tabs instead of spaces

every now and then my neovim just stops the correct indenting and i have to restart the session. Besides the indenting, some plugins seem to stop working as well as some built in function like the o ...

1 2
3
4 5
7