All Questions

Tagged with
Filter by
Sorted by
Tagged with
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?
Allain Lalonde's user avatar
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 ...
Rimian's user avatar
  • 37.5k
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 ...
mmcdole's user avatar
  • 92.2k
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 ...
mmcdole's user avatar
  • 92.2k
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 ...
EBGreen's user avatar
  • 37.2k
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 ...
mmcdole's user avatar
  • 92.2k
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 ...
Léo Léopold Hertz 준영's user avatar
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 ...
Freewind's user avatar
  • 196k
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 ...
andylei's user avatar
  • 1,390
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: ...
Cory Klein's user avatar
  • 53.6k
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 ...
Jonatan Littke's user avatar
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). ...
lyuba's user avatar
  • 6,330
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 (...
Doboy's user avatar
  • 10.8k
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 ...
Fatih Arslan's user avatar
  • 16.8k
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 ...
mjn12's user avatar
  • 1,873
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. ...
Sasha's user avatar
  • 2,257
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 ...
Dane O'Connor's user avatar
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 ...
Zen's user avatar
  • 847
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 ...
hari's user avatar
  • 1,429
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 ...
freitass's user avatar
  • 6,622
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 ...
Tanky Woo's user avatar
  • 5,016
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. ...
romeovs's user avatar
  • 5,895
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 ...
umar's user avatar
  • 4,339
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: ...
u_ser722345's user avatar
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 ...
VoY's user avatar
  • 5,599
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?
IslandCow's user avatar
  • 3,482
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 ...
andy's user avatar
  • 18.2k
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? ...
Mike's user avatar
  • 5,768
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 ...
Dr Kitty's user avatar
  • 442
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 ...
hartfelt's user avatar
  • 373
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 ...
deadghost's user avatar
  • 5,107
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 ...
sidyll's user avatar
  • 58.5k
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 ...
Fredrick's user avatar
  • 1,270
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?
cmcginty's user avatar
  • 115k
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 ...
wyc's user avatar
  • 54.4k
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) { ...
Brian M. Hunt's user avatar
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 ...
Andres Riofrio's user avatar
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 ...
Jakub Lédl's user avatar
  • 1,805
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: $('#...
Mike Crittenden's user avatar
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 = ...
enricoferrero's user avatar
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 ...
strager's user avatar
  • 89.4k
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 ...
OwenP's user avatar
  • 25.2k
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 ...
Draemon's user avatar
  • 34.4k
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?
Apotheosis's user avatar
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 ...
DuckPuppy's user avatar
  • 1,366
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 ...
doctopus's user avatar
  • 5,557
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> ...
Daniel Lang's user avatar
  • 6,819
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 ...
mrm8's user avatar
  • 155
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 ...
DuncanKinnear's user avatar
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 ...
David's user avatar
  • 131

1
2 3 4 5
8