Vim autoindent Tabs and Spaces - Editors

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 ...

+ Reply to Thread
Results 1 to 3 of 3

Vim autoindent Tabs and Spaces

  1. Default Vim autoindent Tabs and Spaces

    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

  2. Default Re: Vim autoindent Tabs and Spaces

    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.

  3. Default Re: Vim autoindent Tabs and Spaces - SOLVED

    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.

+ Reply to Thread

Similar Threads

  1. A better way to convert spaces to tabs while joining 2 lines
    By Application Development in forum awk
    Replies: 6
    Last Post: 12-07-2007, 02:37 PM
  2. Awk script to separate spaces and tabs
    By Application Development in forum awk
    Replies: 10
    Last Post: 03-04-2007, 09:56 PM
  3. vim: replace tabs by spaces
    By Application Development in forum Editors
    Replies: 2
    Last Post: 08-01-2006, 07:31 PM
  4. how to deal with spaces and tabs
    By Application Development in forum awk
    Replies: 1
    Last Post: 02-16-2006, 07:59 AM
  5. How to use split on spaces AND tabs?
    By Application Development in forum Perl
    Replies: 2
    Last Post: 07-03-2004, 04:24 PM