Questions tagged [indentation]

Prefixing lines with whitespace to aid in readability.

Filter by
Sorted by
Tagged with
4
votes
3answers
306 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?
1
vote
1answer
41 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 ...
2
votes
1answer
99 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, ...
0
votes
2answers
341 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
1answer
361 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 ...
4
votes
3answers
406 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() ...
0
votes
1answer
218 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
280 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, ...
2
votes
1answer
396 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
465 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 ...
4
votes
1answer
154 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
615 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 ...
5
votes
2answers
568 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() ...
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") ...
1
vote
1answer
102 views

How do I choose which indent format to use for same file type?

I have multiple indent rules for same file type. I'd like to try them separately. How do I see which one is active? :set filetype is correct. I did manage to change the rules by disabling all other ...
5
votes
2answers
624 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
65 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
546 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
301 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 ...
4
votes
1answer
754 views

Indenting c/c++ using lisp indentation style

I want to write c++ code in vim using lisp indentation style (closing curly braces on the same line as last statement) but I can't figure out how to configure indentation to use that style. Is there ...
5
votes
1answer
108 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
518 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
153 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
32 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 ...
2
votes
1answer
54 views

Can't seem to get syntax information when in insert mode

This is for an indent function that should maintain the indentation should the cursor happen to be in a string region. It maintains the indentation when I hit == in normal mode but changes when I open ...
2
votes
4answers
1k views

Why is autoindent not applied to my markdown files?

When editing markdown (*.md) formatted files, and making bullet points, upon pressing return I want the new bullet point to be automatically created in the same level under the previous one. ...
3
votes
1answer
714 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. ...
5
votes
1answer
536 views

vimrc tab behavior when noexpandtab and softtabstop is less than tabstop

Questions In the following example: Why in the first line, a \t is inserted but only 4-col blank is displayed? Shouldn't it be 8 according to tabstop? Why the two <TAB> hits in the first line ...
5
votes
1answer
681 views

Vim auto indentation

I am using Vim with Pathogen, vim-jsx, and vim-javascript. I have trouble getting the correct indentation. When I am breaking one line that is too long into several pieces (without adding new blocks),...
5
votes
0answers
306 views

Is it possible to get the rule (cinoption) that govern the indentation for a specific line in vim

I have the following code: namespace { template<typename T> struct One // This is the odd line { // impl details } template<typename T> struct Two { // impl details } }...
14
votes
1answer
465 views

How to move the cursor to the correct indentation level without quiting insert mode?

For example I have this JavaScript code. The | character represents the cursor position and it is on an empty line. function a() { console.log("a"); function b() { console.log("b"); ...
10
votes
1answer
147 views

How to temporarily make gq consider hyphen (-) a normal word, to not indent the following lines in the same paragraph

I have tried this in a JavaScript file after disabling smartindent and autoindent options, with textwidth = 80, but it is still the same. It also happens automatically because of the textwidth option ...
11
votes
1answer
1k views

Unexplained gq indentation issue

I insert this text in Vim: t tttt ttttttttt tt tttt tt ttt tttttt-tttt-ttttttt tttttttttttttttttttttttttttttttttttttttttttttttttttttt ttttt ttt ttt tttttt ttttttt tttt ttttttt: ttttttt tt ttttttt, ...
4
votes
2answers
234 views

Remove unecessary indents while keeping the relative indentation

I am looking for a transformation that would change this text: text indented text double indented text indented again to: ...
5
votes
1answer
231 views

When moving text to new line, changes indentation for both lines

I am seeing this in Vim 7.3. I have autoindent on. Sometimes, when I move some code to the next line, the indentation of the line it was originally on changes, and then the newly created line is set ...
1
vote
1answer
160 views

How to use 'filetype indent on', without it indenting while entering text in insert mode

I'm using filetype indent on in my vimrc, generally this works very well, when pressing return it sets the indentation properly (in most cases). However it has a very strange/annoying behavior, of re-...
1
vote
1answer
362 views

Autocomplete popup menu with autoindent and hard wrap in insert mode

I have set autoindent and set tw=90 and set fo=t. Additionally I have working autocompletion that means when I type one character a popup menu come in. Because of popup menu in some situations, where ...
3
votes
0answers
112 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. ...
2
votes
0answers
82 views

Automatically determine whether to use spaces or tabs [duplicate]

I like to use tabs for indentation (hey, don't bully me!). But 33% of other programmers prefer spaces. The norm with Python is to use spaces for indetation. Even so, I configured Vim to use tabs with ...
4
votes
2answers
959 views

Can I get vim to fold comments when using foldmethod=indent

When editing Python files at work I have to include 20+ lines of boilerplate legalese at the start of the file. "start of the file" is not that strict: I'm allowed to include the Python docstring, and ...
3
votes
1answer
359 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 ...
1
vote
0answers
25 views

Parentheses off the page stop being recognized

I am using a recorded macro to manually wrap an extremely long string in a python script, like this: blah = ('blahblah ... blah blah') to blah = ('blahblah...' 'blahblah...' ... ...
1
vote
0answers
53 views

filetype plugin not loaded on files opened with edit command

I've turned on filetype indent and plugins on with the following in my vimrc file: filetype indent plugin on Everything is fine when I open a file from terminal, but if I open another buffer ...
4
votes
1answer
58 views

Adding new characters cause splitting line into many lines

I'm analyzing a lot of logs using VIM version 7.3 (2010 Aug 15, compiled Sep 24 2013 13:45:11). Recently I obtained logs that look like this: 3521:2015-09-28T09:18:36.922557+00:00 192 [info] » ...
3
votes
1answer
337 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, ...
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
723 views

jinja2 indentation with gg=G

I develop django templates, and I need to indent them with gg=G, but jinja2 tags seem to be immune to it. Here is an example of poorly indented, hard to read if-else tags: {% extends "base.html" %} {%...
2
votes
1answer
153 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: ...
3
votes
1answer
298 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
0answers
211 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'...