Using Python in vim with visual selection. (tummy.com, ltd. Journal Entry)
tummy.com: we do linux

Thursday March 01, 2007 at 04:06
Subject: Using Python in vim with visual selection.
Keywords: Python, vim
Posted by: Sean Reifschneider

After my presentation on using Python in vim, I was asked about the ability to have Python operate on a visual selection. I spent some time tracking down how to do this, as I didn't know off the top of my head.

In the python+vim code, there are two ways to get access to a visual selection. One is to use the "vim.current.range" object. For example, use "v" in vim and select a range, then do ":python foo()" to call a function with that range available to the "foo" function.

vim.current.range will give you a list-like object of the lines in the visual selection.

For access to the starting and ending position of the selection, you can use "vim.current.buffer.mark('<')", which will give you the line and column of the start of the visual selection. Similarly, the ">" mark will give you the end position.
(Post Reply)