The following code snippets explain my problem well.
What I want:
template<class T>
ostream& operator<<(ostream& out, const vector<T>& v)
{
...
}
int
main()
{
...
}
What I get (notice the over-indentation before the function name):
template<class T>
ostream& operator<<(ostream& out, const vector<T>& v)
{
...
}
int
main()
{
...
}
I have set filetype plugin indent on
in my ~/.vimrc
.
I have looked at this post but the answer in that looks like learning a new programming language. I am a vim fan, but not a vim expert. Isn't there a simpler solution?
vim" in 'runtimepath'. This disables auto-indenting for files you will open. It will keep working in already opened files. Reset 'autoindent', 'cindent', 'smartindent' and/or 'indentexpr' to disable indenting in an opened file.
To tab or add the indentation at multiple lines, try “shift+dot” i.e., “.” Shortcut once. You will see it will add an indentation of one character at each selected line from the start. If you want to add indentation without stopping, then you have to try the “.” Key from the keyword after using “shift+.”.
How to Turn On Auto Indent in Vim. To automatically indent when editing a file in Vim, enable the auto indenting feature using the :set autoindent flag in command mode: Press Enter, and this will auto-indent the file you are currently editing.
I like having auto on, but smart does funny things based on keywords. To indent the current line, or a visual block: ctrl-t, ctrl-d - indent current line forward, backwards (insert mode) visual > or < - indent block by sw (repeat with . ) then try hitting the F5 key while in insert mode (or just :set paste ).
What you are seeing is the effect of cino-t
(cinoptions setting t). You need to make sure conniptions contains t0
to make the parameter flush with the left margin
From :h cino-t
cino-t
tN Indent a function return type declaration N characters from the
margin. (default 'shiftwidth').
cino= cino=t0 cino=t7
int int int
func() func() func()
To do this you need to make sure that it is set for the cpp filetype. (cindent
is turned on by the default cpp indent file)
I think just adding set cinoptions+=t0
to your vimrc should be sufficient.
Just as I guessed, this had a pretty simple solution! After motivating myself to read the :help 'cinoptions-values'
, the following configuration was all that's needed to solve this particular problem.
:set cino+=t0
From the help text:
tN Indent a function return type declaration N characters from the
margin. (default 'shiftwidth').
cino= cino=t0 cino=t7
int int int
func() func() func()
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With