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.

Does Vim have a command equivalent to Emacs' Ctrl-I?

Emacs has an extremely useful shortcut "C-I" which fixes indentation of the current line (or selected lines.)

For example, suppose you write this tiny code on Emacs:

    def foo
  print "boo"
end

and you are selecting the whole 3 lines. You press "C-I" then the code becomes

def foo
  print "boo"
end

I can use this in quiet mode i.e. ignoring. Emacs as well. Does anyone know how to do this on Vim?

share|improve this question

4 Answers 4

maybe there are other ways but try:

=
share|improve this answer
    
Thanks for your quick responding, but "=" just puts the same length of indentation (or none?) in all the line. I'm looking for the way to put adequate length of indentations as in the example. –  Culip Sep 23 '10 at 22:54
    
= is the standard way for C-like languages, but it looks like you are using a more python-like language, which usually requires some extra setup, such as here: henry.precheur.org/vim/python –  Karl Bielefeldt Sep 24 '10 at 2:11
    
I believe equals should do the trick but you have to have the proper indentation method setup. Check out :help index.txt It gives a quick overview of the various indent settings. You still may need to also check out :help ft-python-indent. I don't think you should need any extras plugins to get decent python indenting, however I could be wrong :) –  Neg_EV Sep 24 '10 at 14:45

The answers to this question: http://stackoverflow.com/questions/235839/how-do-i-indent-multiple-lines-quickly-in-vi offers several ways to indent.

You may be looking for ={ to indent your current code block.

share|improve this answer
    
Thanks. The last section about "filetype plugin indent on" was really helpful. ;-) –  Culip Sep 25 '10 at 8:06

Thanks for all of your help. I really appreciate it. But actually I found a solution:

In vimrc, you will see the code below in near L37-39:

"if has("autocmd")
"  filetype plugin indent on
"endif

and so delete " at the beginning of each line to enable this setting. Now the auto indent and indentation fixing work!

As Casual Coder says, when you want to fix indentation in the current line, press = (in Emacs C-h.) Also you can combine this with selecting commands like gg=G (in Emacs, C-x h C-i) for the whole code, and C-v (Visual Block Mode) would be handy.

(The sample code I wrote in the question is written in Ruby. My Vim which I downloaded from the Ubuntu repository comes with Ruby's indent configuration file (/usr/share/vim/vim72/indent/ruby.vim) and so you don't have to get "vim-ruby".)

share|improve this answer

In insert mode Ctrl+F reindents the current line. The keybinding may be changed by setting cinkeys

share|improve this answer
1  
[in INSERT mdoe] Wow, I didn't know that! Thank you very much! –  Culip Nov 12 '10 at 16:43

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.