user826955
user826955

Reputation: 3206

Always indent in vim

So far I've always used xemacs for source code editing (C++), but for several reasons i'd like to switch to or at least try out vim. One of the very basic things is indentation, where I'm super happy with xemacs behaviour. However I have yet to find a solution for having this behaviour in vim.

What I'm talking about is basically the ability to press Tab in any position of a line, and the line will always be indented to the correct level. This means:

1) pressing Tab multiple times will not indent multiple times, instead the text will be (re-)aligned to the indentation level suitable for the current code

2) pressing Tab e.g. in the middle of a word will not insert spaces or a tab in between this word, but rather indent the whole line

Is it possible to achieve this with vim?

Currently I have:

filetype indent plugin on
set cident
set autoindent
set shiftwidth=3
set softtabstop=3
set expandtab

Upvotes: 0

Views: 217

Answers (1)

romainl
romainl

Reputation: 196546

In normal mode, pressing == should fix the indentation of the current line.

You can fix the indentation of several lines by:

  • selecting them and pressing =,
  • using a motion, =},
  • using a text-object, =ip.

In insert mode, you can fix the indentation of the current line with <C-o>== but the insertion point moves as well. You are not supposed to do that kind of thing in insert mode anyway.

Upvotes: 2

Related Questions