Brandon Mintern wrote:
> Note: I am only using the default indent feature currently (I believe
> it's smartindent).
Whoops. The default is actually autoindent. That is what I am using.
This is a discussion on Vim autoindent Tabs and Spaces - Editors ; Okay, I know there have been a million questions regarding tabs vs. spaces. I have done a ton of searches to find the answer to my question, and I haven't managed to find one. I want to properly mix tabs ...
Okay, I know there have been a million questions regarding tabs vs.
spaces. I have done a ton of searches to find the answer to my
question, and I haven't managed to find one. I want to properly mix
tabs and spaces in my indentation, but vim does not seem to allow me to
do this, at least not with my current settings. I am sure there is some
obscure option to change, but I can't figure out what.
I do not want to discuss proper indentation (tabs vs. spaces), but I
will review my scheme to put my question in the proper frame. I use
tabs to indicate indentation level, and I used spaces to properly align
multi-line statements. With this in mind, anyone should be able to view
my source code with any tabstop setting and get proper code alignment.
This most applies to C code, but has also cropped up in some Python and
Perl usage. In my example below, I have used ^I to indicate tabs and .
to indicate spaces. It might not look right if you are not viewing this
with a fixed width font.
int main (int argc, char** argv) {
^Iint i = 1;
^Iif (i) {
^I^IsomeReallyLongFunction(with, a, lot, of, wordy, arguments, and,
^I^I......................."perhaps maybe a quoted string",
^I^I......................."and one more quoted string");
^I}
^Ireturn 0;
}
My current .vimrc is:
set noexpandtab
set tabstop=4
set shiftwidth=4
The problem is that when vim auto-indents the 3rd line of my function
call, it converts every 4 spaces into a tab character. It looks fine as
I'm editing it, but if I later check out the file using a different tab
width (i.e. with cat or less on default settings), the 3rd line of the
call is not lined up with the 2nd.
I simply want vim to exactly copy my indentation of the previous line,
without converting anything. What can I change to do this? Even if I
have to write something crazy in my .vimrc, I'm cool with that, because
it will save me a lot of hassle in the long run.
Note: I am only using the default indent feature currently (I believe
it's smartindent). I do not mind typing a simple Tab when I want to
indent, or typing multiple spaces to align multi-line function calls. I
simply want vim to exactly copy my previous indentation when continuing
to the next line.
Thanks in advance,
Brandon
Brandon Mintern wrote:
> Note: I am only using the default indent feature currently (I believe
> it's smartindent).
Whoops. The default is actually autoindent. That is what I am using.
Brandon Mintern wrote:
> I simply want vim to exactly copy my indentation of the previous line,
> without converting anything. What can I change to do this? Even if I
> have to write something crazy in my .vimrc, I'm cool with that, because
> it will save me a lot of hassle in the long run.
I found it. It's as simple as
set copyindent
I knew it had to be something simple, and that's why I was getting
frustrated searching for it.
Thanks anyways to anyone who read my original post.
According to the vim documentation, this is not an option in vi, so if
someone else is reading this later, you will need another solution.