Thread: VIM editing ... more about those tabs!

  1. #1
    Registered User hamsteroid's Avatar
    Join Date
    Mar 2007
    Location
    Waterford, Ireland
    Posts
    62

    VIM editing ... more about those tabs!

    Hey Folks,

    I'm digging into VIM and I quite like it by now... but I has an issue with the auto indenting - I want it turned off. All my files end in .c (just in case vim is using cindent rules).

    I'm using Mandriva 2006.1 and VIM v6.3.86. I looked at the VIM faq and some of the suggestions I tried was :set noai - which didn't work when I tested it (ie, went back to insert mode and hit return and it put a tab in for the next line. Grr).

    Another suggestion was to edit the .vimrc (although this is not in my $HOME dir - there is the .viminfo file though - no good though).... anyway - a solution suggested was:
    placing these in wimrc: "filetype plugin indent off" and "filetype indent off".

    Has anyone had any success in turning off autoindenting? It can be annoying as helpful!
    Thanks!
    Last edited by hamsteroid; 04-05-2007 at 02:57 PM. Reason: had != has

  2. #2
    Registered User
    Join Date
    Sep 2001
    Posts
    752
    :set nocindent
    ?
    Callou collei we'll code the way
    Of prime numbers and pings!

  3. #3
    Registered User hamsteroid's Avatar
    Join Date
    Mar 2007
    Location
    Waterford, Ireland
    Posts
    62
    Quote Originally Posted by QuestionC View Post
    :set nocindent
    ?
    Hi QuestioC, I didn't try :set nocindent - think I didn't include the no part - yep, that's why I mentioned they were .c files. I'll try it tomorrow when I get back to the linux box. Thanks.

  4. #4
    Lean Mean Coding Machine KONI's Avatar
    Join Date
    Mar 2007
    Location
    Luxembourg, Europe
    Posts
    444
    What you need is:

    set expandtab
    set shiftwidth=4
    set softtabstop=4
    set tabstop=4

  5. #5
    Registered User hamsteroid's Avatar
    Join Date
    Mar 2007
    Location
    Waterford, Ireland
    Posts
    62
    Thanks Koni - I am at work - on the home straight - nearly there! Will try this when I have free will again

  6. #6
    Lean Mean Coding Machine KONI's Avatar
    Join Date
    Mar 2007
    Location
    Luxembourg, Europe
    Posts
    444
    Hm, I admit I only partially read your initial post, thinking you wanted to use spaces instead of tabs (what my 4 lines do actually). To remove auto indent, use the command that QuestionC suggested.

  7. #7
    Registered User hamsteroid's Avatar
    Join Date
    Mar 2007
    Location
    Waterford, Ireland
    Posts
    62
    Ta - ok will do.

  8. #8
    Registered User hamsteroid's Avatar
    Join Date
    Mar 2007
    Location
    Waterford, Ireland
    Posts
    62
    Just to say that "set nocindent" did the trick! Actually on mate's pc I came across another weird vim property... when you entered text in insert mode and then... come out of insert mode for anything say, and then tried deleting it using backspace... the cursor would not wipe out previously entered text!

    eg.
    1. entering text in insert mode... fine... ok
    2. come out of insert mode. eg. hit esc.
    3. go back into insert mode.
    4. try deleting the text you just entered in step 1 using backspace (assuming your cursor is at the end of the same line)...

    I find you can't.. Only way around it to come out of insert mode and place the cursor on the text to delete and hit x key (or whatever). Deleting via backspacei in insert mode doesn't work - ie, the text acts like it's write protected. - text you just entered a few moments ago in insert mode!
    This was noticed under Suse 10.2.

  9. #9
    Lurking whiteflags's Avatar
    Join Date
    Apr 2006
    Location
    United States
    Posts
    9,613
    In vim you will find that aside from using the hjkl keys to move the cursor, most keys that would normally edit text, like backspace, do not. In vim they force you to go into normal mode before you can delete, move, or copy things, etc. -- this is supposed to help you from changing the text inadvertantly.

    And if I remember right:
    d# - deletes # characters starting on the left
    d#w - deletes the nearest # words, conserving whitespace
    d#e - deletes # words and separating whitespace
    dd - delete this line.

    So deleting things really isn't that hard.

    What is it... um, run :help vimtutor -- it takes about a half an hour to go through but it teaches you the basics of what you should know before seriously using vim.

  10. #10
    Registered User hamsteroid's Avatar
    Join Date
    Mar 2007
    Location
    Waterford, Ireland
    Posts
    62
    Quote Originally Posted by citizen View Post
    And if I remember right:
    d# - deletes # characters starting on the left
    d#w - deletes the nearest # words, conserving whitespace
    d#e - deletes # words and separating whitespace
    dd - delete this line.

    So deleting things really isn't that hard.
    Yeah, that's true, I usually delete using highlight mode (usually for cutting) or simply dd and yank it... but it is handy to delete with backspace while still in insert mode. Only noticed the difference with vim 7.x under Suse. Just set-up I guess.

  11. #11
    Registered User
    Join Date
    Sep 2001
    Posts
    752
    Quote Originally Posted by hamsteroid View Post
    Just to say that "set nocindent" did the trick! Actually on mate's pc I came across another weird vim property... when you entered text in insert mode and then... come out of insert mode for anything say, and then tried deleting it using backspace... the cursor would not wipe out previously entered text!
    When I started using vim in college, that's how it behaved. I figure that text you have typed since going into insert mode isn't yet committed to the buffer, and insert-backspace is implemented in a very simple way which only deletes this 'pre-buffer' content. I always figured this has to do with the fact that I'm running it over a terminal. Just my guess.

    It was frustrating at the time for me too, but only until I got into the swing of things. There's a lot of standard word processing practices that you have to unlearn in Vim like moving the cursor while in insert mode.
    Callou collei we'll code the way
    Of prime numbers and pings!

Popular pages Recent additions subscribe to a feed

Similar Threads

  1. VIM: The (un)official thread
    By MK27 in forum Programming Book and Product Reviews
    Replies: 32
    Last Post: 04-20-2011, 06:43 PM
  2. vim question - linux
    By Stonehambey in forum Tech Board
    Replies: 9
    Last Post: 10-18-2008, 04:05 AM
  3. Tabs or Spaces
    By DavidP in forum A Brief History of Cprogramming.com
    Replies: 46
    Last Post: 04-08-2007, 11:45 AM
  4. Vim tabs
    By PutoAmo in forum Linux Programming
    Replies: 2
    Last Post: 10-30-2002, 04:35 PM
  5. Tab Controls - API
    By -KEN- in forum Windows Programming
    Replies: 7
    Last Post: 06-02-2002, 09:44 AM