fix-vim-pasting icon indicating copy to clipboard operation
fix-vim-pasting copied to clipboard

autoindent, smartindent, cindent all make pasting work as if nopaste was turned on

Open t-ye opened this issue 6 years ago • 7 comments

For this plugin to work, it appears that all types of automatic indenting must be off, i.e.,

 set noautoindent
 set nosmartindent
 set nocindent

must be in your .vimrc. (Not sure if any type of automatic indenting affects the other.)1 Checked both in and out of tmux.

I realize this was addressed in #2, but I'm hoping it's possible to add an "automatic indentation toggle" to the plugin. I like some automatic indenting, and it doesn't really save any time if I have to call set noautoindent and set autoindent every time I paste.


1. I did a bit of experimentation with set paste and noted that set paste followed by set autoindent (or either of the other two automatic indenting settings) still broke pasting, with or without this plugin, even though I was still in paste insert mode. So it seems that set paste may just do the above disabling of automatic indenting (among other things) and we can break it be re-enabling them.

t-ye avatar May 28 '18 21:05 t-ye

I don't have any of those in my ~/.vimrc and this plugin works.

ryanpcmcquen avatar May 28 '18 23:05 ryanpcmcquen

@t-ye, this plugin programatically enables/disables set paste, so you shouldn't have that in your .vimrc.

ryanpcmcquen avatar May 07 '19 18:05 ryanpcmcquen

@ryanpcmcquen As of now I can confirm that the code still can't work on my tmux. Not even set noautoindent etc that OP suggests helps. Works perfectly out of tmux though.

Tmux 2.9a VIM 8.1

hafizhmakmur avatar Mar 02 '20 19:03 hafizhmakmur

@hafizhmakmur, so is it a tmux bug?

ryanpcmcquen avatar Mar 02 '20 20:03 ryanpcmcquen

I'm seeing the same behavior as reported by @t-ye in the original description with GNU Screen:

Screen version 4.00.03 (FAU) 23-Oct-06

No problem with the same vimrc file outside of screen (using Putty). Setting the 3 no indent settings has NO impact for me (i.e. consistently bracketed paste mode is not doing a no paste).

clach04 avatar Oct 14 '22 21:10 clach04

I was never able to reproduce this issue, but would accept a PR that fixes it.

ryanpcmcquen avatar Oct 14 '22 22:10 ryanpcmcquen

My comment https://github.com/ConradIrwin/vim-bracketed-paste/pull/31#issuecomment-1279514361 here shows something that works for me, its similar but different:

  • t_SI / t_EI versus t_ti /t_te - https://vimdoc.sourceforge.net/htmldoc/term.html#t_SI

It's not the same but works for me with:

  • Putty

  • Vim 7.x and 8.x

  • GNU Screen 4.00.03 and 4.05.00

      " bracketed paste, works with and without GNU Screen https://github.com/ConradIrwin/vim-bracketed-paste/pull/31#issuecomment-1279514361 modified tmux_start
      " Docs on bracketed paste mode:
      " http://www.xfree86.org/current/ctlseqs.html
      " Docs on mapping fast escape codes in vim
      " http://vim.wikia.com/wiki/Mapping_fast_keycodes_in_terminal_Vim
    
      if !exists("g:bracketed_paste_tmux_wrap")
        let g:bracketed_paste_tmux_wrap = 1
      endif
    
      function! WrapForTmux(s)
        if !g:bracketed_paste_tmux_wrap || (!exists('$TMUX') && !exists('$STY'))
          return a:s
        endif
    
        let tmux_start = "\<Esc>P"
        let tmux_end = "\<Esc>\\"
    
        return tmux_start . substitute(a:s, "\<Esc>", "\<Esc>\<Esc>", 'g') . tmux_end
      endfunction
    
      let &t_ti .= WrapForTmux("\<Esc>[?2004h")
      let &t_te .= WrapForTmux("\<Esc>[?2004l")
    
      function! XTermPasteBegin(ret)
        set pastetoggle=<f29>
        set paste
        return a:ret
      endfunction
    
      execute "set <f28>=\<Esc>[200~"
      execute "set <f29>=\<Esc>[201~"
      map <expr> <f28> XTermPasteBegin("i")
      imap <expr> <f28> XTermPasteBegin("")
      vmap <expr> <f28> XTermPasteBegin("c")
      cmap <f28> <nop>
      cmap <f29> <nop>
    

I'm not sure this is worth me posting a PR as its sufficiently different from this implementation (which is super nice and small) and I've not tested with tmux, I've only tested raw Putty and Putty+GNU-Screen - I also don't 100% understand the escape sequences

Thanks for making this available!

clach04 avatar Oct 14 '22 22:10 clach04