Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

doesn't work with latest tmux #32

Closed
sandrodz opened this issue May 3, 2017 · 25 comments
Closed

doesn't work with latest tmux #32

sandrodz opened this issue May 3, 2017 · 25 comments

Comments

@sandrodz
Copy link

sandrodz commented May 3, 2017

Plugin works fine outside tmux, but within tmux same old indentation hell breaks loose.

Any ideas how to fix this?

@fabienduhamel
Copy link

Same issue here.

@ConradIrwin
Copy link
Owner

We've added and removed tmux specific code a couple of times now — I don't use tmux, and it sounds like it has very complicated handling of terminal escapes (unsurprisingly!). I'd be very happy for anyone to pick this up and figure out exactly what the problem is, but please see also #28 #18 #14 #21 #23 and #25.

@fabienduhamel
Copy link

Thanks for the reply. None of these links gives me a working solution. I'm currently trying to fix it by myself.

@fabienduhamel
Copy link

I'm bored of tmux general issues for a couple of days, I deleted it.

@ConradIrwin
Copy link
Owner

ConradIrwin commented Jun 2, 2017 via email

@amosbird
Copy link

amosbird commented Jun 6, 2017

Just hitted by this. Hope someone can share a solution.

@amosbird
Copy link

amosbird commented Jun 6, 2017

Just remove all the tmux wraping stuff and it's done. Thanks @nicm !

@sandrodz
Copy link
Author

sandrodz commented Jun 6, 2017

@amosbird how did you fix it?

@nicm
Copy link

nicm commented Jun 6, 2017

If you remove the DCS wrapping it should work in any tmux since tmux/tmux@f4fdddc

@ryanpcmcquen
Copy link

ryanpcmcquen commented Jun 6, 2017

@nicm, you should PR that.

@von
Copy link

von commented Jun 11, 2017

@nicm I think you are talking about a solution that works with 'tmux paste-buffer -p' as opposed to pasting from the system paste buffer with Command-V?

@nicm
Copy link

nicm commented Jun 11, 2017 via email

@von
Copy link

von commented Jun 11, 2017

Thanks for clarifying. Like others on this thread, something recently broke indentation pasting from the system pastebuffer into vim running in tmux for me and removing the wrapping (i.e. making WrapForTmux() a no-op) doesn't help.

@nicm
Copy link

nicm commented Jun 11, 2017

Show me what you have in your script now.

von-forks pushed a commit to von-forks/vim-bracketed-paste that referenced this issue Jun 12, 2017
@von
Copy link

von commented Jun 12, 2017

Here you go: https://github.com/von-forks/vim-bracketed-paste/blob/master/plugin/bracketed-paste.vim

As far as I can tell, XTermPasteBegin() is never invoked when I paste as I don't see the message from the echom I added for debugging.

@nicm
Copy link

nicm commented Jun 12, 2017 via email

@von
Copy link

von commented Jun 13, 2017

I am running tmux 2.5 installed via homebrew.

And I've noticed my problem comes and goes depending on how I start vim. If I start vim with a file on the command line or loading a session, pasting and indentation is broken. If I start vim without any commandline arguments and then open a file, pasting works without indentation as desired. So I've got some startup weirdness going on and will go debug on my own for a bit. Thanks for your help.

@von
Copy link

von commented Jun 14, 2017

If I change from setting t_ti and t_te to setting t_SI and t_EI, i.e., I revert fd01b5d, everything works perfectly. Using t_ti and t_te work for me, but seemingly only after running a curses based program from within vim (vifm, which is how I normally open a file).

For clarity, this fixes things for me:

-let &t_ti .= "<Esc>[?2004h"
-let &t_te .= "<Esc>[?2004l"
+let &t_SI .= "<Esc>[?2004h"
+let &t_EI .= "<Esc>[?2004l"

According to :help t_ti and t_te are about entering and leaving "termcap" mode and t_SI and t_EI are entering and leaving "insert" mode. I don't understand why bracketed-paste changed - the comment on the above commit doesn't make sense to me - and I'm hoping this gives someone who understand that change a clue as to why it's not working well for me.

Since it might be relevant, I'm running vim 8.0 (patches 1-636), in tmux 2.5, in iTerm 3.0.15. (And this is all with the tmux wrapping removed per #33.)

@von
Copy link

von commented Jun 14, 2017

OK, reading fd01b5d more carefully, I understand it is about making pasting work from normal and visual mode and sure enough, I confirmed that using t_SI and t_EI instead of t_ti and t_te breaks pasting from normal and visual mode. I tried setting all four, and that doesn't seem to help.

von-forks pushed a commit to von-forks/vim-bracketed-paste that referenced this issue Jun 15, 2017
von-forks pushed a commit to von-forks/vim-bracketed-paste that referenced this issue Jun 15, 2017
von-forks pushed a commit to von-forks/vim-bracketed-paste that referenced this issue Jun 15, 2017
@ssiegel
Copy link
Contributor

ssiegel commented Jul 2, 2017

Vim seems to include support for bracketed paste as of 8.0.0210. Maybe there is some interference that is masked by signalling bracketed paste support on every change to insert mode? Unfortunately I am not able to investigate that right now.

@v
Copy link

v commented Sep 1, 2017

@nicm's original suggestion worked for me. I simply removed the calls to WrapForTmux

This diff works for me on Mac OSX with tmux 2.5 and vim 7.4

diff --git a/plugin/bracketed-paste.vim b/plugin/bracketed-paste.vim
index 196ec9b..17c688f 100644
--- a/plugin/bracketed-paste.vim
+++ b/plugin/bracketed-paste.vim
@@ -24,8 +24,8 @@ function! WrapForTmux(s)
   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")
+let &t_ti .= "\<Esc>[?2004h"
+let &t_te .= "\<Esc>[?2004l"
 
 function! XTermPasteBegin(ret)
   set pastetoggle=<f29>

FWIW, I think my diff has the same behavior as the diff in #33

@ConradIrwin
Copy link
Owner

Ok. I've gone with @v's solution.

Looking forward to new reports of "doesn't work in tmux" :D.

@chrisjohnson
Copy link

chrisjohnson commented Sep 23, 2017

I can confirm that this doesn't work in tmux, and since vim 8 ships support natively (which works outside tmux), the only real point of a plugin here is to wrap for tmux or to support <8.

Maybe worth updating the README to specify that this is for 7.x since it doesn't serve any purpose in 8.x currently

FWIW I am able to use bracketed paste mode in zsh inside tmux (2.5), it's only vim (with and without this plugin) that doesn't work in tmux

@chrisjohnson
Copy link

chrisjohnson commented Sep 23, 2017

Also fwiw this bit of config that I similarly lifted from that SO article actually does make bracketed paste mode work inside of tmux... not sure what that means because I don't even see any tmux-specific code here. But somehow, in vim 8, with this config, I can use bracketed paste mode both inside and outside tmux.

let s:screen  = &term =~ 'screen'
let s:xterm   = &term =~ 'xterm'

" make use of Xterm "bracketed paste mode"
" http://www.xfree86.org/current/ctlseqs.html#Bracketed%20Paste%20Mode
" http://stackoverflow.com/questions/5585129
if s:screen || s:xterm
  function! s:BeginXTermPaste(ret)
    set paste
    return a:ret
  endfunction

  " enable bracketed paste mode on entering Vim
  let &t_ti .= "\e[?2004h"

  " disable bracketed paste mode on leaving Vim
  let &t_te = "\e[?2004l" . &t_te

  set pastetoggle=<Esc>[201~
  inoremap <expr> <Esc>[200~ <SID>BeginXTermPaste("")
  nnoremap <expr> <Esc>[200~ <SID>BeginXTermPaste("i")
  vnoremap <expr> <Esc>[200~ <SID>BeginXTermPaste("c")
  cnoremap <Esc>[200~ <nop>
  cnoremap <Esc>[201~ <nop>
endif

If you are not keen on supporting tmux in your plugin and just want to serve 7.x users I'm fine taking my config and wrapping it up into a different plugin

Edit: https://github.com/chrisjohnson/vim8-bracketed-paste-mode-tmux

@ryanpcmcquen
Copy link

I've rolled my own plugin also: https://github.com/ryanpcmcquen/fix-vim-pasting

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

10 participants