Customize Your Vim Setup; Thank Me Later

Create a Leader Command for Vim Paste Mode

Andy Huynh

1 minute read

Ever copy something to your clipboard to NOT have it appear as you would expect in Vim? Pasting from another application to Vim yields wonky results because Vim doesn’t know how to handle the clipboard’s content.

Vim has a paste mode you can toggle on or off using :set paste and :set nopaste.


Vim has a one liner you can add to vimrc to transform into a Vim paste toggle: set pastetoggle=<F2>.

However, leader commands are omnipresent in my workflow. Codegangsta at Kajabi wrote a succinct Vim script for this very purpose.


function! TogglePaste()
        if(&paste == 0)
                set paste
                echo "Paste Mode Enabled"
                set nopaste
                echo "Paste Mode Disabled"

map <leader>p :call TogglePaste()<cr>

My leader button of choice is \; thus \p to toggle your paste on and off.

  •   Category
  • Vim
comments powered by Disqus