Reputation: 1390
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?
Upvotes: 4
Views: 128
Reputation: 31429
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.
Upvotes: 5