0

Found the following snippet https://github.com/ConradIrwin/vim-bracketed-paste and thought it would be neat if I could modify it so it would,

  1. Detect when pasting,
  2. Update statusline with "pasting data"
  3. set paste
  4. "paste data"
  5. leave pastemode (by pastetoggle binded on [201~)
  6. Update statusline to whatever it was before pasting

This is what I've "kinda tried", but cant understand how I would get anything to "execute" on "[201~". Even though I used VIM for some while I still find this incredible difficult (I still don't fully understand the whole code snippet) and tips / pointers / solutions would be welcome.

let &t_ti .= "\<Esc>[?2004h"
let &t_te = "\e[?2004l" . &t_te

function! PasteStart(ret)
  set statusline=pasting
  set pastetoggle=<f29>
  set paste
  return a:ret
endfunction

function! PasteEnd()
  set statusline=Done
  return ""
endfunction

execute "set <f28>=\<Esc>[200~"
execute "set <f29>=\<Esc>[201~"

map  <expr> <f28> PasteStart("i")
imap <expr> <f28> PasteStart("")
vmap <expr> <f28> PasteStart("c")

map  <expr> <f29> PasteEnd()
imap <expr> <f29> PasteEnd()
vmap <expr> <f29> PasteEnd()

cmap <f28> <nop>
cmap <f29> <nop>

Thanks

  • 1
    Why would you want that indication? Unless you're pasting megabytes of text, the paste itself should be fairly quick, almost unnoticeable. Also, following the link to the [original SO answer](https://stackoverflow.com/a/7053522/813602), it's been updated to say that in Vim 8.0, bracketed paste handling is built-in, and that workaround not required any longer. So, I wouldn't bother perfecting an obsolete solution. – Ingo Karkat Oct 18 '18 at 14:21
  • 1
    The way you've extended the code looks fine. You may be just missing an explicit `:redrawstatus` to make the update visible. Vim doesn't always update the screen if further commands are pending. – Ingo Karkat Oct 18 '18 at 14:23
  • Well actually I have a habit of copying *a lot* of text and then pasting it into vim. And lately I've been trying to find out why my pasting is so slow, I think there may be some config-issue I have. And while I was on it, I tried the snippet above and became curios about why I couldn't update the statusline *while* pasting. But yeah, thanks for the pointers! – Patrik Martinsson Nov 01 '18 at 13:17

0 Answers0