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.comments powered by Disqus