Super User is a question and answer site for computer enthusiasts and power users. Join them; it only takes a minute:

Sign up
Here's how it works:
  1. Anybody can ask a question
  2. Anybody can answer
  3. The best answers are voted up and rise to the top

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"

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

def foo
  print "boo"

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

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

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

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: – 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: 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

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

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .