All Questions
Tagged with vim indentation
371
questions
2413
votes
34
answers
982k
views
Indent multiple lines quickly in vi
It should be trivial, and it might even be in the help, but I can't figure out how to navigate it. How do I indent multiple lines quickly in vi?
1506
votes
27
answers
631k
views
Turning off auto indent when pasting text into vim
I am making the effort to learn Vim.
When I paste code into my document from the clipboard, I get extra spaces at the start of each new line:
line
line
line
I know you can turn off auto ...
1434
votes
12
answers
1.1m
views
Tab key == 4 spaces and auto-indent after curly braces in Vim
How do I make vi-Vim never use tabs (converting spaces to tabs, bad!), makes the tab key == 4 spaces, and automatically indent code after curly brace blocks like Emacs does?
Also, how do I save these ...
712
votes
16
answers
369k
views
How do I fix the indentation of an entire file in Vi?
In Vim, what is the command to correct the indentation of all the lines?
Often times I'll copy and paste code into a remote terminal and have the whole thing messed up. I want to fix this in one ...
447
votes
12
answers
238k
views
Changing Vim indentation behavior by file type
Could someone explain to me in simple terms the easiest way to change the indentation behavior of Vim based on the file type? For instance, if I open a Python file it should indent with 2 spaces, but ...
153
votes
12
answers
125k
views
How do I tidy up an HTML file's indentation in VI?
How do I fix the indentation of his huge html files which was all messed up?
I tried the usual "gg=G command, which is what I use to fix the indentation of code files. However, it didn't seem to ...
117
votes
6
answers
67k
views
How can I wrap text to some length in Vim?
Let's speak of relative measures. My Vim looks like:
aaaaaaaaaaaaa
bbbbbbbbbbbbb
ccccccccccccc
etc
I would like it to be smaller:
aaaaa
aaaaa
bbbbb
bbbbb
ccccc
ccccc
etc
How can I get it? And ...
115
votes
3
answers
101k
views
How to use only tab (not space) in vim
I prefer to use tab than white space(may be a little different from most of others)
But I found, when I hit Enter at the end of line, it will add some white spaces, but not tab. So, I have to delete ...
78
votes
5
answers
11k
views
Vim automatically removes indentation on Python comments [duplicate]
I'm using Vim and editing Python scripts.
Autoindent works pretty well in general, but when I start a new line and type '#' to type a comment, Vim unindents that line for me.
For example, if have
...
70
votes
5
answers
15k
views
How do I indent a single line multiple times in vi or vim?
I've found several answers on how to indent multiple lines in vim, I want to know how to take a single line and indent it more than once. In effect, I want a shorter version of the following command:
...
64
votes
4
answers
12k
views
Comments (#) go to start of line in the insert mode in Vim
Whenever I want to add a comment to an indented line in vim, I hit Shift-o (open a new row above the current, switch to insert mode) and start typing a Python comment (using #). That hash is then ...
62
votes
8
answers
65k
views
Showing trailing spaces in vim
I've set the following options in .vimrc
set listchars=tab:▸\ ,trail:·
set list
And expected to see dots in those places where spaces are used for tabulation in the code (I use spaces, not tabs).
...
62
votes
8
answers
144k
views
Setting up Vim for Python
I really like the Emacs editor for Python because of its smart tabbing for instance if I have something like this
def foo():
if bar:
blah
[b]eep
and I press tab on the cursor (...
58
votes
9
answers
60k
views
Remove all arbitary spaces before a line in Vim
I'v written a plugin where it comes to parsing a XML tag. The content inside the tag is indented and when i copy the parsed string into the file it's gettting like:
Example line
This is ...
54
votes
7
answers
65k
views
Is it possible to display indentation guides in Vim?
I'm a longtime Vim user (3 or 4 years) who has recently started dealing with some deeply nested code. This code is indented with spaces, not tabs. I would like some clean and non-distracting ...
53
votes
9
answers
49k
views
Correct indentation of HTML and PHP using Vim
I've been using Vim for a while, and I can't get proper HTML indentation working in PHP files.
For example, what I want is for each child to be indented one tab more than it's parent, as shown below.
...
53
votes
3
answers
11k
views
Vim: Smart indent when entering insert mode on blank line?
When I open a new line (via 'o') my cursor jumps to a correctly indented position on the next line. On the other hand, entering insert mode while my cursor is on a blank line doesn't move my cursor to ...
47
votes
6
answers
47k
views
Vim Auto Indent with newline
How do I get vim to place the cursor within the braces starting on a new line, ie with | denoting the cursor position :
class {
|
}
right now with my settings it only does this
class {
|}
I got ...
38
votes
4
answers
10k
views
Indenting in VIM with all the files in Folder
I have a folder containing hundreds of TTL (TeraTermLanguage) files.
Now I wanted indent all these files.
I have created teraterm.vim for indentation and I open a file using VIM and do "gg=G" and ...
36
votes
5
answers
8k
views
How to avoid namespace content indentation in vim?
How to set vim to not indent namespace content in C++?
namespace < identifier >
{
< statement_list > // Unwanted indentation
}
Surprisingly, 'cinoptions' doesn't provide a way to ...
34
votes
3
answers
9k
views
How to paste source code to vim without error format?
When I copy a python code, and paste to vim. the indents are all error.
but I paste into emacs or gedit, it is right.
that is difficult to describle, let's see the screenshot.
Notice:the blue and ...
28
votes
6
answers
36k
views
Disable all auto indentation in vim
In TeX vim usually screws up my indentation. Mainly when I'm in a displayed equation which I think should look like this:
\[
x=\frac{y}{z}
\]
where the whitespace infront of the x is one tab.
...
27
votes
5
answers
17k
views
Indenting a bunch of lines in Vim
Is there a way to indent a selection of lines in Vim, like we have in text editors where we select a bunch of lines and press tab (or shift tab) to indent/unindent the selected lines?
I am talking ...
26
votes
2
answers
10k
views
Why does vim not obey my expandtab in python files?
After I installed Vundle, my vim no longer obeys the expandtab settings I had. My tabs were set to 2 spaces, but now in python files it no longer does that. The problem is being called by this line:
...
25
votes
5
answers
4k
views
How can I achieve project specific indentation in vim?
I'm working on several projects, each of which uses different indentation style (for various filetypes). For example 1 tab per indentation level, 2 or 4 spaces etc. How can I automate switching ...
24
votes
3
answers
29k
views
Getting Vim to recognize XML
I would like Vim to help me indent my XML files like my C code. However, when I use
gg=G
It just sets everything to the left. Do I need to designate a syntax? Is XML recognized as a language?
23
votes
3
answers
7k
views
How to disable vim's indentation of switch case?
I'm currently fighting with Vim, I can't seem to make the indentation options do what I want.
Here are my settings, I put them at the bottom of .vimrc to make sure they take precedence. As you can ...
22
votes
5
answers
16k
views
Can VIM autoindent SQL?
"SQL Statement indentation good practice" appears to be the accepted format for writing SQL blocks.
Is there a Vim indent/syntax file that would adhere to this standard, or at least be close?
...
22
votes
2
answers
2k
views
Make vim indent C preprocessor directives the same as other statements
General info
(Note: Please read this all the way through, because I spent a bit of time organizing it, making sure I addressed each individual problem I'm having and why one proposed solution doesn't ...
21
votes
2
answers
3k
views
stopping vim from removing indentation on empty lines
When the cursor is placed at the end of a line containing nothing but withspace characters, vim will, when i press enter, remove that whitespace. I find this irritating, as it breaks my script for ...
20
votes
3
answers
25k
views
How to indent multiple lines on Vim?
I want to be able to highlight lines I want to indent/reverse-indent and indent with tab and shift-tab respectively.
" for command mode reverse tab
nmap <S-Tab> <<
" for insert mode ...
18
votes
1
answer
3k
views
Avoiding label indenting in C++
I guess this was asked before, but I could not find any similar question.
When writing part of the scope operator in C++, Vim guesses that it's going to be a label (on the first :) and then indents ...
17
votes
5
answers
13k
views
How to indent a selection in gVim (Win32)
I'd like to indent a block of text.
I am able to do this in the Linux build of gVim.
I do this in the state of gVim where I'm not in the insert or visual mode. The bar at the bottom is blank on the ...
17
votes
1
answer
11k
views
How do you enable file specific tab indent settings in VIM?
I believe there is a method to write a comment in a file that vim will use to override default tabbing and indent values.
Can someone point me to information about this feature and how to use it?
16
votes
4
answers
13k
views
Indenting two spaces a selection (visual mode) in vim?
Say I have this code:
var users = [
{ name: 'TJ', email: '[email protected]' },
{ name: 'Loki', email: '[email protected]' },
{ name: 'Jane', email: '[email protected]' }
];
I want to ...
16
votes
8
answers
15k
views
Javascript indentation in VIM
I'm trying to get VIM to indent Javascript with the '=' and related commands. When I try to auto indent the following, for example:
new function($) {
$.fn.setCursorPosition = function(pos) {
...
16
votes
3
answers
2k
views
Can Vim display two spaces for indentation, while keeping four spaces in the file?
I want to work on someone else's project, and he uses 4 spaces for indentation. I use 2, and my screen is not big enough to edit using 4 spaces comfortably.
Can I configure Vim to display 2 spaces ...
16
votes
2
answers
6k
views
Is there any good Haskell indentation script for Vim?
Unfortunately, the one Haskell indent script I found (by motemen) breaks when it comes to Haddock comments:
-- |Docline 1, lorem ipsum<CR>
-- Docline 2
^^^^ - an autoindent here, wtf
Would ...
15
votes
4
answers
4k
views
Automatic new line and indentation in vim when inside braces?
For example, if I'm coding jQuery in vim, and I have this in insert mode ("|" is the current cursor position):
$('#something').click(function(){|})
...and I hit enter, I would like to get this:
$('#...
15
votes
1
answer
787
views
How can I make vim indent dplyr code with the pipe (%>%) operator correctly?
For example, vim will not indent correctly the following code:
flights <- flights %>%
group_by(year, month, day) %>%
select(arr_delay, dep_delay) %>%
summarise(
arr = ...
14
votes
2
answers
2k
views
Vim: Indent current (blank) line and insert
Say I have the current text in the buffer, where _ marks the cursor
int main(int argc, char **argv) {
printf("Hello, world!\n");
_
}
I have indentexpr on (though a solution with cindent or ...
14
votes
1
answer
7k
views
What is the "un-tab" sequence in (g)Vim?
This is an annoyance I've had for a long time.
(Nitpicky section: I prefer 4 space characters to tab characters. It's a lot easier to type "tab" instead of explaining that. When I say "tab", I mean ...
14
votes
6
answers
6k
views
How to prevent Vim indenting wrapped text in parentheses
This has bugged me for a long time, and try as I might I can't find a way round it.
When I'm editing text (specifically latex, but that doesn't matter) files, I want it to auto-wrap at 80 columns. It ...
14
votes
4
answers
1k
views
Does Vim have indentation guides, Notepad++-style?
In Notepad++, there is a dotted line that runs down from the function keyword through the end of the method. It looks like this:
Does Vim support something similar?
14
votes
2
answers
6k
views
Can I fix Groovy indenting in Vim?
I am trying to use Vim for some Groovy code at work. It doesn't seem to handle autoindents well when semicolons are not used. I've found a few questions related to Ruby and JavaScript with the same ...
14
votes
1
answer
4k
views
Set tab as 2 spaces in vimrc, but still set to 4 spaces when editing python files
I've set tab to equal 2 spaces in my vimrc. This works when I edit java files, but for some reason when I edit python files, tab is set to 4 spaces instead.
My vimrc:
filetype plugin indent on
...
14
votes
4
answers
2k
views
Vim cursor position after expanding html tag
I most IDEs and modern text editors (Sublime Text 3) the cursor is correctly indented after inserting a newline in between an html tag (aka 'expanding" the tag):
Before:
<div>|</div>
...
13
votes
2
answers
19k
views
How to edit HTML in Vim?
I'm new to Vim and I'm trying to get used to it. I just created a .vimrc file and got Vim to display line numbers and do incremental searching. I also enabled syntax highlighting. Now I want to enable ...
13
votes
1
answer
2k
views
Setting specific column tab stops in Vim
I am reasonably familiar with Vim's option for tabstop, softtabstop, shiftwidth, expandtabs, etc.
However, I'm wondering if there is a way in Vim to set specific column tab stops.
I need tab stops ...
13
votes
3
answers
1k
views
Vim editor indent problem when the first character of the line is a sharp # character
This haven been bugging me since the first day using Vim for 3 years. Whenever I try to indent a line via Shift + > when the FIRST CHARACTER of the line starts with a "#", it doesn't work ...