18

:set pasteキーの組み合わせ(leader + pなど)をバインドして、同じキーの組み合わせでオンとオフを切り替える方法を探しています。

私はこれらを2つの異なるキーコンボにバインドできること:set paste、そしてバインドできることを知っていますが、トグルを作成しようとしています。:set paste!

4

4 に答える 4

31

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
于 2012-12-20T07:45:15.807 に答える
6

You can use pastetoggle for paste toggle.

set pastetoggle=<F3>
于 2012-12-20T07:44:16.410 に答える
3

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> 
于 2017-10-16T10:51:18.047 に答える
2

Beware of Accepted Answer!!!!

The accepted answer to this question caused a rather insidious bug to happen in environments that have "space" as their <leader>


Problem

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!


A Better Solution

The suggestion by https://stackoverflow.com/users/8783819/indrajeet-kumar to do the following works like a charm:

:nnoremap <leader>p :set invpaste<CR>


Disclaimer

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!

于 2018-04-05T21:09:23.953 に答える