about me about me
photography photography
software projects software projects
contact me contact me

This isn’t my affidavit of being a copy and paste programmer. vim has recently become my code editor of choice, having used Eclipse for years, and Netbeans for most of this year. Poor network performance at work means both of those IDEs slow me down.

One annoyance with vim is pasting text from another application. Lets take a nicely indented method:

    protected function translate(array $calls)
    {
        $features = array();
        foreach ($calls as $call) {
            list($feature) = $this->translator->translate(array($call));
            $feature['destination'] = $call['classification'];
        }
        return $features;
    }

If I want to move this from one class to another, and I copy and paste it with smartindent enabled:

    protected function translate(array $calls)
        {
                    $features = array();
                            foreach ($calls as $call) {
                                            list($feature) = $this->translator->translate(array($call));
                                                        $feature['destination'] = $call['classification'];
                                                                }
                                                                        return $features;
                                                                            }

Ack! That smart indenting ain’t so smart. We can work around this by enabling paste mode. To do this, use the following vim command:

:set pastetoggle=<F2>

Now when you enter insert mode, hit F2 and you’ll toggle the paste option, whereby indentation won’t go all screwy. You can set this permanently by adding this to your ~/.vimrc (minus the colon at the start).


comments

No comments for this post.

this post's tags