PDA

View Full Version : Editing C++ using vim in Ubuntu



audit
November 10th, 2010, 06:38 PM
I have been writing C++ programs in vim for about a month. And I now getting use to vim, but one small problem I do not know how to solve.

I set my tabs to 4 which I prefer to 8. When I start a block of code after a
"{" vim auto indents to 8--How do I change this to auto indent in 4?

Also if anyone has any vim C++ tips worth noting--Please do.

Simian Man
November 10th, 2010, 06:41 PM
Put this in a file called "~/.exrc":


set ts=4
setsw=4


I'd also recommend using "set expandtab" which will insert spaces when you hit the tab key instead of actual tab characters. Anyone else reading your code will thank you :).

Also "set cindent" would be a nice one to have. This sets up auto-indentation for C-like languages.

shawnhcorey
November 10th, 2010, 07:05 PM
To get help of the options, type:

:help options^M
where ^M means press the RETURN key.

Some options related to tabs are:

autoindent
cindent
expandtab
shifhtwidth
shiftround
smartindent
softtabstop
tabstop


Other command you may be interested in are:
:help ^D
:help ^T
:help >>
:help <<
where ^X means control-X

These command shift the start of the line in or out one tab stop, depending whether you are in insert mode or command mode.