:set paste
キーの組み合わせ(leader + pなど)をバインドして、同じキーの組み合わせでオンとオフを切り替える方法を探しています。
私はこれらを2つの異なるキーコンボにバインドできること:set paste
、そしてバインドできることを知っていますが、トグルを作成しようとしています。:set paste!
There is a specific command to toggle paste mode :
set pastetoggle=<F10>
to set it to F10 key for example.
Edit : To use it with leader key, you would use
set pastetoggle=<leader>p
You can use pastetoggle
for paste toggle.
set pastetoggle=<F3>
Well pastetoggle
didn't work for me.
What worked is this (in my .vimrc):
" Invert paste when \p is pressed
:nnoremap <leader>p :set invpaste<CR>
The accepted answer to this question caused a rather insidious bug to happen in environments that have "space" as their <leader>
Let's say I wanted to copy the following text:
Hello there people!
With the accepted configuration of set pastetoggle=<leader>p
I would see the following:
Hello thereeople!
What was happening was it was swallowing up the <space>p
because my leader happens to be the spacebar.
This is not a very uncommon leader key of "space" so I thought I would mention it for those out there trying to figure this bizarre behavior out!
The suggestion by https://stackoverflow.com/users/8783819/indrajeet-kumar to do the following works like a charm:
:nnoremap <leader>p :set invpaste<CR>
I am not yet accepted enough by stack overflow to comment so please forgive me for giving this as an answer. If someone could paste this as a comment to the top post I would be very grateful!