Take the 2-minute tour ×
Super User is a question and answer site for computer enthusiasts and power users. It's 100% free, no registration required.

I've been using vim and gVim for over a year. I use it mainly for editing of HTML, PHP, Python and Javascript.

Every time I've tried to set some automatic type of indentation I've got into troubles. Now I just use autoindent. I use it both at home in Windows 7 and at work in Linux.

Things I'm missing is:

  • Right indentation after ending a line
  • correct indentation when I use =.

I've tried to install many of the gvim plugins and I still get no practical results. I set syntax and smartindent or cindent, also filetypeplugin (I can post my .vimrc if needed).

The PHP is less of a worry to me, my main issue is indenting HTML and Javascript (e.g. jQuery).

share|improve this question
1  
I don't know what "right indentation after ending a line" or "correct indentation when I use =" means. It would help to see examples of what you do, what you expect, and what you see instead. –  garyjohn Aug 27 '11 at 16:31
    
What settings are you using to enable indentation for PHP/HTML/JavaScript files? ":filetype indent on" in your ~/.vimrc is probably the optimal method, and it works fine for me. –  Heptite Aug 28 '11 at 0:39
    
my indentKeys was set to empty string. I've removed lines where it was set that way. –  shevski Oct 8 '11 at 18:38

1 Answer 1

Without any particular plugin and these settings in my .vimrc

set tabstop=2
set softtabstop=0
set noexpandtab
set shiftwidth=2
set shiftround
set autoindent
set copyindent

I get what I think is "correct indentation when I use =" (| is the cursor).

var myObj = {
foo : "bar"|
};

becomes this when I type =:

var myObj = {
  foo : "bar"|
};

With the same example, I get correct indentation when hitting <CR>.

var myObj = {
  foo : "bar"|
};

becomes this:

var myObj = {
  foo : "bar"
  |
};

I think set copyindent is what you need.

share|improve this answer

Your Answer

 
discard

By posting your answer, you agree to the privacy policy and terms of service.

Not the answer you're looking for? Browse other questions tagged or ask your own question.