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?
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.
execute "normal! '<V'>" . jump . "j". If jump is an argument supplied to the function, then you need to use a:jump when you use it.'> marker is not moved during the selection: : in visual mode produces :'<,'> and thus for 3-line selection it is called three times.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()