0

I use vim in terminal. Sometimes I want to paste text from outside into it, but avoid autoindent, abbreviations and such. Vim has paste mode for it, but when I enable paste mode most shortcuts stop working. This include all alt shortcuts <a-a>, <a-q>, etc., most control shortcuts like <c-x>, <c-s>, <c-bs>, but not all, at least <c-o>, <c-l> and <c-q> work. Also functional keys work.

The problem happens both in vim (8.0) and neovim (0.1.7), I use gnome-terminal.

Why can it be and is there a way to fix it?

1

Paste mode (:help 'paste') is meant to be entered temporarily, just for the paste. The only shortcuts you should press is the (e.g. middle mouse button or terminal paste one) for pasting the contents (and that one itself will not arrive in Vim at all). After pasting, you move out of paste mode, either via the configured 'pastetoggle' key, or by typing :set nopaste<CR>.

  • For practical use you're probably right. For editor customization task I am at, this is yet another ugly quirk. Why it allows some shortcuts but not others? Help says it disables mappings in insert and command line mode, but it isn't true, I have several mappings that still work. Your answer neither explains it nor provides workaround. – Uprooted Oct 4 '18 at 19:31
  • Mappings are those seen in :imap and :cmap, the rest are built-in commands, or stuff external to Vim. If you see anything else being mapped in paste mode, that would be a bug. The pastetoggle key is the one special exception, as explained in the help. – Ingo Karkat Oct 4 '18 at 19:36
  • I was wrong about pastetoggle, but I have e.g. c-k and c-l mapped (:inoremap) to duplicate and kill line respectively, they still work. While c-s (save file) becomes ^S. – Uprooted Oct 4 '18 at 19:42
  • That should not happen. I just tried with :inoremap <C-k> XXX and :inoremap <C-l> YYY, and these do not trigger after :set paste. Instead, I get the built-in digraph query, and literal ^L inserted. – Ingo Karkat Oct 5 '18 at 6:41
  • Retested, it works as you say. I could swear it was not so yesterday. Sorry for bother. – Uprooted Oct 5 '18 at 19:56

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.