From the Archives 4

From March 15, 2005:

One of these days I’m going to create a separate site for all my computer related writing. In the mean time, I found a couple new cool things about vim, my text editor of choice.

[Ha!  I just did that.]

First, because it has all sorts of cool autoindent features and comment continuation stuff, pasting can be a pain. It usually ends up totally messing up the formatting. There is a solution. It’s the ‘paste’ setting. Who would have thunk it? Before pasting, :set paste. After pasting, :set nopaste. Piece of cake and it works like a charm.

Next, I don’t like how vim does indenting. Eight spaces is way too much. Also, when editing code that has an existing standard, it would be nice to maintain that standard. How? The relevant settings are ’shiftwidth’, ‘tabstop’, ’softtabstop’, and ‘expandtab’. I’m not sure 100% how these all work together but here’s a stab at getting things to work:
expandtab: either on or off. When it’s on, it doesn’t insert tab characters. Just spaces.
shiftwidth: The width in characters that the auto-indent should be.
tabstop: The width in characters that the tab character displays as.
softtabstop: By default set to 0, aka off. When on, it is the number of spaces that are inserted with the tab key. Say you set it to 6, with tabstop set to 4. Then pressing tab would result in a tab character and two spaces being inserted. I think I can do evertyhing I want to without using this.

So, I think the way I want things is tabs to be 3 characters. So, set tabstop=3'and set shiftwidth=3 should do it.

What about files where it is all spaces, with a 2 character indent? :set tabstop=2 and :set shiftwidth=2 and :set expandtab does the trick quite nicely.

One Response to “From the Archives 4”

  1. Daniel Ellison Says:

    Thanks so much for that “:set paste” thing. All these years of cursing vim for its aberrant pasting behaviour were unnecessary, it seems.

Leave a Reply