Tuesday, August 30, 2011

Actual cursor position.

I'm looking for a way to get the current cursor position in the line
(that is, the column) in *characters*.
col is no use, because it returns the position in bytes. I can't use
virtcol either because it returns the position on the screen: a tab
counts as 8 characters (or whatever tabstop is set to), the line can be
wrapped, etc.

This could be a reasonably compatible solution:

function! Column()
let l:ot=&tabstop
let l:ow=&wrap
set tabstop=1
set nowrap

let l:ret = virtcol(".")

let &tabstop=l:ot
let &wrap=l:ow

return l:ret
endfunction

But it looks sloppy and bogus. There's got to be a better way.

Any suggestions or tips?

Thanks!

--
You received this message from the "vim_use" maillist.
Do not top-post! Type your reply below the text you are replying to.
For more information, visit http://www.vim.org/maillist.php

No comments:

Post a Comment