Skip to main content
added 265 characters in body
Source Link

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

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?

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

added 1 character in body
Source Link
statox
  • 50.5k
  • 19
  • 153
  • 231

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

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?

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?

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?

added 143 characters in body
Source Link

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?

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>

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?

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?

Source Link
Loading