vimclipboard

How can I change default clipboard register in Vim?


To paste text from the clipboard in Vim, currently I need to type "+p. How can I change or create an alias for register +, for example, to a? So that Vim would paste text from the clipboard when I type "ap. I tried to map register, but no results.


Solution

  • There's no way to map registers in Vim. Mappings are key mappings.

    Not an exact solution for your problem but one of the following two ways may be close enough:

    1. Set clipboard to unnamedplus. You can alias the unnamed register to the + clipboard register by adding

      :set clipboard^=unnamedplus
      

      to your vimrc. Whenever you paste from the unnamed register, e.g. by p, you will paste from the clipboard instead. See :help clipboard-unnamedplus

    2. Map keys for easy clipboard access. Although you cannot map registers, you can map a key to make clipboard access more convenient. With the following mappings

      :nnoremap <Leader>p "+p
      :xnoremap <Leader>p "+p
      

      you can quickly paste from the clipboard using your <Leader> key and p.