2

Indentation of C++ (and also C, Objective-C and even Java) is typically handled by enabling the 'cindent' option, which uses Vim's built-in C-indenting implementation, which recognizes elements of these languages (such as curly braces, semi-colons, etc.) and uses them as cues to decide whether to indent or unindent a specific line. This indentation engine ...


2

I'd say the easiest way to insert text at the correct indentation is to use the o or O Normal-mode commands. From :help o: When 'autoindent' is on, the indent for a new line is obtained from the previous line. When 'smartindent' or 'cindent' is on, the indent for a line is automatically adjusted for C programs. Of course, these two commands will insert ...


1

When you enable filetype plug-ins, Vim will load filetype-specific configuration whenever it opens a file of a specific type. Many such plug-ins are shipped with Vim itself and you can find them under directories such as indent/ and ftplugin/ in your Vim runtime (you can find the location with :echo $VIMRUNTIME inside Vim.) So it's quite possible that you're ...


1

I am referring to both the behavior when pressing Enter in insert mode, and also the behavior when pressing = in Visual mode. The "equal" command depends on :h 'equalprg' option value. If it's set then Vim invokes an external formatter program, and all those indents will be set according to that program's configuration. In fact, you may end up ...


Only top voted, non community-wiki answers of a minimum length are eligible