I was looking for a way to set virtualedit=block
before executing visual block select with additional binding g<C-v>
and after that turning it off.
There are few things in my workflow that require that behavior. I didn't find anything after some research. So currently I have this in my vimrc.
nnoremap g<C-v> :setl virtualedit=block<CR><C-v>
nnoremap <C-v> :setl virtualedit=<CR><C-v>
Another example is to disable incsearch
for custom command
nnoremap <silent> K :setl nois<CR>:grep! "\b<C-R><C-W>\b"<CR>:setl is<CR>
So my question is, is there right or just better than the one I came up with way to set option just for one command and switch it back after command is done?
Update Here is example of function that can help with second case
function! Example()
let &l:virtualedit="block"
exe "normal \<C-v>"
let &l:virtualedit=""
endfunction
But this way does not work for cases like in first example