Versions Compared

Key

  • This line was added.
  • This line was removed.
  • Formatting was changed.

This page has moved to http://developer.lsst.io/en/latest/tools/vim.html.

 

The following configuration file should be placed in ~/.vim/ftplugin/c.vim   .

Code Block
setlocal shiftwidth=4
setlocal softtabstop=4
setlocal expandtab
setlocal textwidth=78
setlocal cino=:0,l1,g0,(0,u0,W2s
setlocal comments^=s2:/**,mb:*,ex:*/
syntax match cTodo /\todo/

You may also need to add filetype plugin indent on   to ~/.vimrc   .

Explanation:

setlocal shiftwidth=4

Sets the autoindent spacing to 4 spaces. setlocal to limit this to the current (C++) buffer.

setlocal softtabstop=4

Sets the spacing for tab characters to 4 spaces.

setlocal expandtab

Always use spaces; never use tab characters.

setlocal textwidth=78

Limit the length of a line to 78 characters. Standard 4-6 actually specifies up to 110.

setlocal cino=:0,l1,g0,(0,u0,W2s

Set the C indent configuration.

    • :0: Align case labels with the enclosing switch.
    • l1: Indent statements relative to the case label, not anything following.
    • g0: Align C++ scope (private/public) labels with the enclosing class.
    • (0: Align lines after "(foo" next to the unclosed parenthesis.
    • u0: Same as above for the next level of parentheses deeper.
    • W2s: Indent lines following a line-terminating unclosed parenthesis by two shiftwidths (8 spaces)

setlocal comments^=s2:/**,mb:*,ex:*/

Allow comments to start with two asterisks for Doxygen.

syntax match cTodo /\todo/

...