Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Visually select to the middle of line

Tags:

vim

I have this mapping that allows me to move to the middle of the line:

nnoremap <silent> M :execute 'normal! ' . (virtcol('$')/2) . '\|'<CR>

Can it be extended to work in visual mode?

like image 702
petobens Avatar asked Sep 12 '25 22:09

petobens


1 Answers

This seems to work.

vnoremap <silent> M :<c-u>execute 'normal! gv' . (virtcol('$')/2) . '\|'<CR>

Since typing an ex command exits visual mode you need to first reselect the visual mode before executing the | command.

<c-u> clears the command line which was prepopulated with '<,'>
gv reselects the old virtual selection.

vnoremap was used so that its a visual mode mapping.

like image 69
FDinoff Avatar answered Sep 15 '25 08:09

FDinoff