Questions tagged [indentation]

Prefixing lines with whitespace to aid in readability.

Filter by
Sorted by
Tagged with
5
votes
2answers
98 views

Can I make the indent commands take an additional count that doesn't affect the motion?

Let's say I'd like to indent the current line 4 times. (Not 4 spaces, 4 indent commands). As far as I can tell, the shortest way to do this is >>... (Indent once, repeat three times) This ...
1
vote
2answers
141 views

How do I keep folds when formatting (reindenting) the whole file?

I do quite often use this mapping: autocmd FileType cpp nnoremap <buffer> == :%!clang-format -style=file<cr>2g;zz It reindents the whole file and returns the cursor to the last edit ...
6
votes
0answers
972 views

What is the best practice in vim8 for wrapping with indentation aka breakindent

To have proper paragraph wrapping with indentation in vim (after vim7.4) we could use this: " Wrap the text with identation isntead of the old way set breakindent set showbreak=\ \\_ Since vim8 ...
1
vote
2answers
266 views

How can I highlight misuse of tabs and spaces according to current configuration?

I'm looking for a way that will highlight lines (or part of lines) that don't adhere to current tabs settings. Say for instance, I have the following configuration in my .vimrc tabstop=8 ...
6
votes
1answer
5k views

incorrect auto-indent in bash code

I have bash script which Vim detects as a sh according to :set filetype?. In addition, Vim-script for auto-indention support for shell-scripts(/usr/share/vim/vim74/indent/sh.vim) is also present. ...
4
votes
1answer
198 views

indent command does not indent matched lines

I have file where I would like to indent all the lines between curly braces: html { margin: 0; padding: 0; border: 0; font-size: 100%; font: inherit; vertical-align: baseline; } body { line-height: 1....
1
vote
0answers
296 views

Fix indentation after a multiline HTML tag

I have the following in .vimrc: set tabstop=2 softtabstop=-1 shiftwidth=0 expandtab filetype plugin indent on When I type the following in an HTML file: <html id="somethingverylong" > <...
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> :...
2
votes
1answer
400 views

Best Practices for working with an indent-sensitive language?

pug, and python are both indent-sensitive languages. I believe that if you have your editor correctly configured this can serve as an advantage, but if it is not correctly configured it's quite a bit ...
3
votes
2answers
389 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 ...
1
vote
1answer
56 views

How to prevent indent, unindent (>>, <<) from re-aligning text?

Is it possible to make indenting/unindenting not re-align text, eg: /* * Some Text */ Indents to: /* * Some Text */ I would prefer/expect: /* * Some Text */ I saw ...
6
votes
1answer
1k views

How can I indent JavaScript that's within <script> tags in an HTML file?

If I am viewing a HTML file that someone else wrote, it often has <script> tags containing javascript, e.g. <!DOCTYPE html> <html> <head> </head> <body&...
1
vote
2answers
465 views

repeat indent-to-previous-position in vim?

I very often want to do the following or similar: indent all lines from previous position to current position inclusive repeat, repeat, repeat (to further indent the same lines) I feel I should be ...
2
votes
1answer
430 views

Trouble with vimrc

So I've been using Vim at school with a vimrc that seemed to be well set up, and learn few extra commands like set nu or syntax on. Right now I'm trying I'm using Vi on my computer, and was struck by ...
1
vote
0answers
164 views

Why does cindent align statements to closing } in switch case?

I prefer this indentation style for switch cases with local variables: switch (expr) { case CONST_BLAH1: { int decl; // scope local to this case stmt; break; case CONST_BLAH2: ...
2
votes
0answers
117 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 ...
3
votes
2answers
732 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
0answers
61 views

Structural navigation by indentation level [duplicate]

Suppose I have a pretty-printed JSON file that I'm trying to navigate and my cursor is at the X position. Is there a motion to move to the nearest line above/below the current one with an indentation ...
9
votes
3answers
1k views

Vim switch statement cindent options

I want my C code indented as follows: switch (x) { case 1: break; case 2: { break; } } Instead of this: switch (x) { case 1: break; case 2: { ...
5
votes
2answers
722 views

Vim conceal indentation. Replace indentation spaces with utf-8 chars

I use four spaces for indent. I would like to replace the indentation with some UTF-8 chars. What I have: 1. def foo(bar): for jaffa in bar: print jaffa 2. var foo = function(bar){ ...
1
vote
0answers
120 views

What controls (de)indenting when inserting a brace character?

Working on a C file, Vim correctly indents as I type. In Objective-C, however, it gets indentation right, but deindentation wrong for instance methods, unless I exit insert mode and use the = operator....
16
votes
3answers
1k views

How do you indent > < without leaving visual mode and losing your current selection?

I often have to manually indent, but when I enter a visual mode, select my lines to indent, and press < or >, I leave visual mode whether I want to or not. I would rather have it so I stay in ...
4
votes
3answers
329 views

How can you indent your current file without losing your cursor position?

I was reading that the way to indent in vim is a gg=G sequence. This however loses my cursor position. How can I indent my file without losing my cursor position?
7
votes
2answers
5k 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 ...
1
vote
1answer
43 views

Indenting now add suspicious chars to my files when pasting

Following answer I got there to allow >> to indent, I edited my .vimrc to this: :set shiftwidth=2 :set autoindent :set smartindent But now when I copy/paste (via putty), it indents incrementally, by ...
3
votes
4answers
2k views

Delete indenting spaces one at a time

I want to be able to delete indenting spaces one at a time. If I set shiftwidth to 4, it deletes 4 spaces at a time if vim counts them as indentation. Setting shiftwidth to 1 fixes the problem, but ...
2
votes
1answer
107 views

automatic text wrapping messed up with parenthesis

I like to wrap my text to 80 characters all the time, even when I am editing Markdown. I have a problem when I open parentheses: it doesn't wrap right anymore. Since it is hard for me to explain it, ...
40
votes
4answers
50k 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
302 views

Vim indent rules apply to existing files but not to new ones

vim-erlang-runtime is set up for indenting Erlang files that works for already existing files and does not work for any newly created ones. To elaborate, when starting a function body whenever I ...
4
votes
1answer
383 views

How to check whether the cursor is at the boundary of a syntax item for indentexpr?

I'm writing my own indentexpr to indent my code, the indentexpr is run in a sandbox, so one important point is that I cannot change the text content. I have set up the syntax highlighting for quoted ...
1
vote
2answers
422 views

Vim indentation of a bash script seems broken after a pipe

Vim builtin indentation seems to get confused with the following script. I cannot get Vim to indent properly the while-loop after the pipe. #!/bin/bash while true do # while loop is indented ...
4
votes
3answers
499 views

How do I comment out lines without changing indentation?

I use Vim to write my Python source and use the debugging library pdb. Let's say I have this code with break points commented out: import pdb #pdb.set_trace() def func1(): #pdb.set_trace() ...
4
votes
1answer
153 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 ...
0
votes
1answer
264 views

Issue with paste command remap in vim

I want to auto indent code on pasting and found this: :nnoremap p p=`] --(not working) but it was not working for me as the code still came out unindented. So I used: :nnoremap &...
2
votes
0answers
329 views

How do I fix indentation after multiline c++ initialization list?

When I have a long constructor that forces me to put initialization list items on separate lines, my indentations look like this after gg=G. Really_Long_Class_Name::Really_Long_Class_Name(int _arg1, ...
4
votes
1answer
175 views

augroup end indentation

When I'm editing my vimrc, if I gg=G vim autoindents nicely except where augroup is involved I end up with augroup movingBackup au! au BufWritePost * call WriteBackupFile(expand("%:t"), ...
1
vote
1answer
941 views

No shiftround when hitting Tab

I'm having trouble making indentation work as I expect in Vim. Short version: What I want is to disable Tab mark. Long version: What I want is to ALWAYS insert four spaces when indenting (i.e. when ...
6
votes
2answers
802 views

Toggling Tabs and Spaces

I work on different projects that have preferences for tabs and others for spaces. Is there a way to toggle using tabs or spaces for indentation? I tried a function I saw online function TabToggle() ...
2
votes
1answer
487 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 ...
8
votes
1answer
546 views

What controls indentation of lines following an open square bracket when using cindent?

I am trying to build my own indent file for JavaScript. The default indent file for JavaScript turns cindent on, with minimal modifications, and I am using that as a base. On Vim 7.3 for OSX El ...
5
votes
1answer
3k views

Incorrect auto-indent in python code

I have a following python code, which contains both 4 space and 2 space indents. class Foo(object): def __init__(self, flag = False): if flag: print("hello") ...
5
votes
2answers
911 views

Indent a markdown list item?

I am frequently editing markdown files, and when dealing with multi-line items in hierarchical lists, it would be great to have a rapid way to indent or un-indent a list item. For example, how can I ...
2
votes
1answer
71 views

Difference between autoformat and autoindent

What is difference between autoformat and autoindent? What are most popular solutions in text formating in vim of both of these methods?
7
votes
1answer
764 views

How to override the '=' command?

I cannot convince vim to apply the coding-style I'd like to (cindent and friends). However, integrating clang-format.py (which uses the .clang-format of my project) actually makes me totally happy. ...
2
votes
0answers
362 views

Make vim version 7 edit xml files

I'm using old Debian linux an vim version 7.1.314. I would like to edit eclipse .cproject file that build using XML syntax. Currently vim shows not colored information. I found vim plugin that I hope ...
5
votes
1answer
158 views

How to wrap plain text honoring existing text indent?

With at least these settings: expandtab textwidth=79 sw=4 ts=4 fo=tcq If I have a long line of text that starts with a * (like a C/javadoc comment) it will honor the current indent level when I gqq, ...
1
vote
1answer
610 views

Fix spacing with vim

I would like to fix only spacing in badly formatted C/C++ source code. The Vim command = fixes only indentation. Utility indent is not suitable, because it reformats totally all source code, but want ...
3
votes
0answers
159 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 ...
1
vote
0answers
33 views

How can I insert a new line with the indentation of the line above? [duplicate]

When I type o, it will insert a new line, and it is exactly new line without any indentation. The cursor will go to the beginning. How can I insert a new line with the indentation of the line ...
5
votes
2answers
907 views

HTML is not being indented

I have just created a file .html. When I run set filetype? I get filetype=html. Then I select this code: <div> <span> </span> </div> and press = but the code is not indented.....

1
3 4
5
6 7