Tag Archives: vim

vim dependency

I have just been trying out eclipse and I realised I’ve become so used to vim I’m really a clutz with a regular text editor now. When it comes to programming I’ve become dependant on vim. My recent addiction started when I got a laptop with lame arrow keys and figured vim would make more sense. I installed vim and viemu for Visual Studio and never looked back. These days I’m just using vim since I’m working on linux but I’m really heavily dependant on it. It’s odd because as I type this in a regular editor this is fine, but when I see curly braces I feel lost without vim.

Luckily there is a plugin for eclipse called vrapper. It has most of the things I need. There are a couple of bits missing, but it’s enough to keep me from feeling all at sea.

I think I’ll take a look at the source code now it’s on github. I don’t know whether I can contribute to the project, but it’ll certainly be interesting to see a vim emulator as it’s still in the process of being built.

Oh and just in case I forget, the way to install new software is on the Help menu in eclipse.

Tagged ,

vim tricks for perl

I’ve been making use of some helpful vim snippets posted on blogs.perl.org for a little while now and I thought they deserved a quick mention.  Until I started writing this blog post I hadn’t realised they were actually be the same author.  Marcel Grünauer has been writing some of the most interesting blog posts on the new(ish) perl blog site from my point of view.  The series on vim tricks is here.The first script that adds use statements makes use of expand('<cword>') which out of the box doesn’t pick up the whole package name, stopping at the :: instead.  The script makes a note that this can be ‘fixed’ by changing the iskeyword setting.  One of the commenters luckily makes a patch to make that change while also localising the effect, so that it’s only done for that call, rather than requiring you to fundamentally change your vims behaviour.

I only read that comment when I was constructing this blog post though and so I had a play at vim scripting myself.  Instead of using expand I used matchstr and gave it a hand coded regex to find from the cursor to the end of the package name.

    let p = matchstr(line, '[A-Za-z_0-9:]\+', col('.') - 1)
    let s:package = input('Package? ', p)

Having read the alternative fix for that I think the expand('<cword>') is still the better way to do it, but it at least allowed me to finally do a tiny bit of vim scripting.  As it happens I also noticed a minor bug in the use statement script that causes issues when you try to add a use statement for a package named something that is a subset of an existing use statement.  i.e. you have use A::B::C; and you try to add a use statement for A::B.

This can be fixed simply by adding a little to the end of the regex that checks the use statement doesn’t already exist,

   if (search('^use\s\+'.s:package.'[^A-Za-z_0-9:]', 'bnw') == 0)

I also modified my version of the script to use <Leader> instead of , as the command character, so you type \us instead of ,us to execute the command.  That makes it more inline with his second script.

I’ve stuck my vim config onto github, as much as a backup as to share it.  It’s not really very sophisticated.  https://github.com/colinnewell/colins-perl-vim-config/blob/master/vimrc

Now I’ve started to get more into using this vim scripting I really ought to go back and take a look at some of Ovids past blogs to see what useful things I can find there.  He has tended to blog interesting editor snippets.

Have a look at Marcel’s blog I realised he also blogged another really interesting thing, the dip script.  In some ways I’m impressed he’s managed to demonstrate it so succinctly here, but I also can’t help but think he ought to be shouting about it more because the potential of that is freaking awesome.

Tagged ,

vim tricks (from stackoverflow)

There are a couple of tricks in vim that I keep needing to look up in my Stack Overflow favourites.  The first is to save a file that needs root access when you haven’t loaded vim as root.

:w !sudo tee %

http://stackoverflow.com/questions/726894/what-are-the-dark-corners-of-vim-your-mom-never-told-you-about/726920#726920

The second is using vim as a hex editor,

:%!xxd -g 1

and to reverse it,

:%!xxd -r

http://stackoverflow.com/questions/726894/what-are-the-dark-corners-of-vim-your-mom-never-told-you-about/727634#727634

Tagged
Follow

Get every new post delivered to your Inbox.

Join 58 other followers