Skip to main content
2 of 4
added 143 characters in body

Set option just for one command

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. And 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?