On Sun, Dec 12, 2010 at 11:35 PM, C K Kashyap <[email protected]> wrote:
>
> I have a set of lines like this -
>
> char str1 = "hello";
> char str2 = "printer";
>
> and I'd like to generate -
>
> char str1 = "hello";
> char str1_arr[5];
> char str2 = "printer";
> char str2_arr[7];
>
> Ordinarily, I'd just go ahead and record a macro and playback ... but
> the problem is with the numbers 5 and 7 above - those depend on the
> length of the string.
> Is there a way, I can do a viusal highlight of the string in quotes
> and get its length?
function! VSubLen()
let a = "'<"
let b = "'>"
let fn = line(a) == line(b)
\ ? "col"
\ : "line"
return eval(fn."(b)"."-".fn."(a) + 1")
endfunc
vnoremap <Leader>l s<C-R>=VSubLen()<CR>
nnoremap <Leader>vl i<C-R>=VSubLen()<CR>
--
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