How to execute selected text as Vim commands

I've defined a few mappings based on lh-vim-lib that do not involve any register. This is indeed an overkill solution, but a neat one for mappings -- as it will never modify the default register.


You can select the lines, yank the selection and execute it with

:@"

I like to make this mapping which will require you to make a visual selection first and doesn't overwrite your unnamed register:

vmap <space> "xy:@x<CR>

If you like to write Vim commands with line continuations:

vmap <space> :w! /tmp/x.vim<CR>:so /tmp/x.vim<CR>

Tags:

Vim