Mark Needham

Thoughts on Software Development

Archive for the ‘vim’ tag

Vim: Copying to and retrieving from the clipboard

with 6 comments

My memory when it comes to remembering how to get text to and from Vim via the clipboard is pretty bad so I thought I’d try summarising what I know and see if that works out any better.

We can access the system clipboard via the ‘+’ buffer so the commands revolve around that.

Copying to the clipboard

To copy the whole file to the clipboard we can use this command:

:%y+

Or if we want to get the data between lines 4 and 10 then we could do:

:4,10y+

If we want just the current line the following will work:

:.y+

If we want to copy lines via visual mode, we would use ‘v’ to go into that and select which lines we want to copy followed by:

"+y

Retrieving from the clipboard

Retrieving data from the clipboard is a case of accessing the ‘+’ buffer.

Therefore to paste whatever’s in the clipboard into a file we’d do this:

"+p

If we wanted to paste it just before the current position of the cursor then we’d do this instead:

"+P

Written by Mark Needham

February 14th, 2011 at 2:13 pm

Vim: Learnings so far

with 8 comments

I’ve been using Vim instead of RubyMine for the last month or so and it’s been interesting observing the way that I browse code as I add plugins to make my life easier.

Between files

I generally don’t know exactly where in the folder structure different files live since I’m used to being able to search by just the name i.e. RubyMine’s Ctrl-N

Yahuda Katz wrote a blog post earlier in the year where he listed some of the plugins he’s been using – one of which is called Command-T and allows exactly this functionality.

I also quite like the ability to quickly access files that I’ve recently opened i.e. files which are in the Vim buffer or RubyMine’s Ctrl-E. The FuzzyFinder plugin provides that functionality.

I’ve also tagged all my Ruby gems and the source code of the project using Exuberant CTags which then allows easy browsing to methods/classes.

Inside files

I’ve noticed that the way I browse inside files has changed since I started using Vim.

I used to just scroll around files using the mouse but now I find myself moving around a file by line numbers instead.

A lot of the commands for file editing in Vim are based on moving/changing/deleting to a particular symbol so you become almost a human parser when reading a line of text.

I found/am finding the following quite useful for learning Vim shortcuts:

When coding in Java/C# I rely quite heavily on auto complete to tell me what methods I have available to me on a certain object.

Although I don’t use it that frequently the SuperTab plugin works reasonably well when you do need help.

Mike pointed out Vimlander-2-The-Quickening which has some of the plugins I mentioned and several others ready to use.

Written by Mark Needham

December 27th, 2010 at 7:15 pm