PDA

View Full Version : VIM editing ... more about those tabs!



hamsteroid
04-05-2007, 02:56 PM
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!

QuestionC
04-05-2007, 03:32 PM
:set nocindent
?

hamsteroid
04-05-2007, 04:42 PM
: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.

KONI
04-06-2007, 01:18 AM
What you need is:



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

hamsteroid
04-06-2007, 03:02 AM
Thanks Koni - I am at work - on the home straight - nearly there! :) Will try this when I have free will again ;)

KONI
04-06-2007, 03:16 AM
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.

hamsteroid
04-06-2007, 03:20 AM
Ta - ok will do.

hamsteroid
04-09-2007, 05:52 PM
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.

whiteflags
04-09-2007, 06:49 PM
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.

hamsteroid
04-09-2007, 06:55 PM
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.

QuestionC
04-10-2007, 12:50 PM
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.