Haunted House

Origo is a funnyface (0,0)

Vim-tip #1

Posted by Gasten on August 22, 2007

Whenever I find a new cool way of doing things in vim, I’ll post them here. First, I would like to show you how you can get pasted text ‘dented in the way you want.

Say that you got a piece of code on a website or somewhere else which you need to paste into a new text-document (Or as I did in this example, I had to get the content of this chuck-file). You do as you always do: you mark the text you wish to copy, switch to Vim, insert mode, middle-click and !!!! Chockhorror! Total fsckup!

// step generator, zero crossing detector, dac
Step s => ZeroX z => dac;
1.0 => float v;

// infnite time-loop
while( true )
    // set the step value
        v => s.next;
            // change step value
                -v => v;
                    // advance time
                        100::ms => now;

What now? Dedent manually? Yes, almost... But try this: put your courser on the 'dent-level you desire, and type dw. Look! The first alpha-numeric character in the line will appear under your courser! Cool, huh?

Just something small, but nonetheless nifty!


One Response to “Vim-tip #1”

  1. Gasten said

    Hmm… After some investigation, it seems like this weird behaviour of vim is due to my auto-indent-setting (don’t know it’s exact name right now). The auto-indent thingie is inserting a equal number of tab-keys on the beginning of the new line when you press enter as the previous line have. This means that once code is starting to indent, vim will check the previous line’s indentation and insert that into this new line. Then the pasted chunk will past it’s inserted indentation, and the indentation will keep incrementing.

    This means that if you want to paste something, you will have to turn auto-indentation off. But there is probably some really nice setting that’ll turn off auto-indent when pasting.

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out /  Change )

Google+ photo

You are commenting using your Google+ account. Log Out /  Change )

Twitter picture

You are commenting using your Twitter account. Log Out /  Change )

Facebook photo

You are commenting using your Facebook account. Log Out /  Change )


Connecting to %s

%d bloggers like this: