Reman
Reman

Reputation: 8109

How to extend a selection in vimscript

p.e. I have a block of text selected (using Ctrl-V) and want to extend it in a vimscript to a new location p.e. 30 lines below

Does anyone know how to do this?

Upvotes: 1

Views: 1190

Answers (2)

Prince Goulash
Prince Goulash

Reputation: 15715

You can use the markers '< and '> to move to the beginning and end respectively of the most recent visual selection. So a simple function such as

EDITED to use gv and a jump variable.

function! ExtendVisual(jump)
    execute "normal! gv" . a:jump . "j"
endfunction

vnoremap <silent> <leader>e :call ExtendVisual(30)<CR>

will let you extend the current visual:q region by 30 lines using \e.

Upvotes: 3

ZyX
ZyX

Reputation: 53634

It is better expressed with <expr> mappings:

vnoremap <expr> \e g:jump."j"

With a function call:

function Jump()
    " Do something (modifying text, switching buffers and 
    " something other is forbidden, see :h map-<expr>)
    return jump."j"
endfunction
vnoremap <expr> \e Jump()

Upvotes: 3

Related Questions