Re: xterm PRIMARY and CLIPBOARD selection [was: Re: Copy from Firefox and paste into Terminal with Vim]

2024-02-07 Thread debian-user
Stefan Monnier  wrote:
> > I have not said it is more “standard for terminals”, I have that it
> > is more “standard” fullstop. It is more standard by the virtue of
> > having worked for decades, C-Ins S-Ins S-Del existed way before the
> > C-C C-V C-X tryptich, and still working today in most contexts.  
> 
> Indeed, IIUC these key bindings were part of the CUA standard:
> https://en.wikipedia.org/wiki/IBM_Common_User_Access

Indeed and CTRL-C & friends first appeared as Apple-C on the Lisa, it
seems and were appropriated by Microsoft after a while:

https://www.howtogeek.com/804030/the-origins-of-ctrlc-ctrlv-ctrlx-and-ctrlz-explained/



Re: xterm PRIMARY and CLIPBOARD selection [was: Re: Copy from Firefox and paste into Terminal with Vim]

2024-02-07 Thread Max Nikulin

On 07/02/2024 19:20, Nicolas George wrote:

Max Nikulin (12024-02-07):

It may be a convention for applications other than terminals, however I am
unsure what "standard" means for terminals.


I have not said it is more “standard for terminals”, I have that it is
more “standard” fullstop. It is more standard by the virtue of having
worked for decades, C-Ins S-Ins S-Del existed way before the C-C C-V C-X
tryptich, and still working today in most contexts.


Terminal application should leave standard hotkeys for applications 
running in terminals. It is the reason why modern terminals use 
[Ctrl+Shift+c] and [Ctrl+Shift+v] instead of conventional [Ctrl+c] and 
[Ctrl+v]. That is why I am against idea of adding [Ctrl+Insert] to xterm 
bindings.


In Emacs C- is bound to `kill-ring-save'.


Works for me. The author of XTerm is quite reactive if you can explain
the issue clearly, I am not surprised it was fixed.


My impression, it was a decision to support only single storage for 
handling selection. I like that it was changed.




Re: xterm PRIMARY and CLIPBOARD selection [was: Re: Copy from Firefox and paste into Terminal with Vim]

2024-02-07 Thread Stefan Monnier
> I have not said it is more “standard for terminals”, I have that it is
> more “standard” fullstop. It is more standard by the virtue of having
> worked for decades, C-Ins S-Ins S-Del existed way before the C-C C-V C-X
> tryptich, and still working today in most contexts.

Indeed, IIUC these key bindings were part of the CUA standard:
https://en.wikipedia.org/wiki/IBM_Common_User_Access


Stefan



Re: Copy from Firefox and paste into Terminal with Vim

2024-02-07 Thread Max Nikulin

On 07/02/2024 19:19, Greg Wooledge wrote:

On Tue, Feb 06, 2024 at 11:02:09PM -0800, David Christensen wrote:

* Pressing " then + then p seems to paste from the default Vim buffer --
what I seem to recall being referred to as the "yank buffer" (?).

* Pressing " then * then p seems to paste from the default Vim buffer.


These are the same results that I had.  You're most likely running a
vim package built without the full suite of GUI options, just like I am.


Only vim.gtk3 and vim.motif support PRIMARY selection and CLIPBOARD 
registers (you do not need to run gvim). There is no support in 
vim.tiny, vim.basic (package "vim"), vim.nox. They are built from the 
same source package with different configure options. It seems neovim 
(different project) require an external tool for clipboard.





Re: xterm PRIMARY and CLIPBOARD selection [was: Re: Copy from Firefox and paste into Terminal with Vim]

2024-02-07 Thread Nicolas George
Max Nikulin (12024-02-07):
> It may be a convention for applications other than terminals, however I am
> unsure what "standard" means for terminals.

I have not said it is more “standard for terminals”, I have that it is
more “standard” fullstop. It is more standard by the virtue of having
worked for decades, C-Ins S-Ins S-Del existed way before the C-C C-V C-X
tryptich, and still working today in most contexts.

> Thanks, it seems, it works in bookworm. Several years ago xterm did not
> support ownership of independent CLIPBOARD and PRIMARY simultaneously. It
> was a workaround for the following scenario:
> 
> - select some text
> - copy it to CLIPBOARD
> - select another fragment of text (PRIMARY)
> - switch to another application
> - paste from PRIMARY
> - paste from CLIPBOARD

Works for me. The author of XTerm is quite reactive if you can explain
the issue clearly, I am not surprised it was fixed.

Regards,

-- 
  Nicolas George



Re: Copy from Firefox and paste into Terminal with Vim

2024-02-07 Thread Greg Wooledge
On Tue, Feb 06, 2024 at 11:02:09PM -0800, David Christensen wrote:
> * Pressing " then + then p seems to paste from the default Vim buffer --
> what I seem to recall being referred to as the "yank buffer" (?).
> 
> * Pressing " then * then p seems to paste from the default Vim buffer.

These are the same results that I had.  You're most likely running a
vim package built without the full suite of GUI options, just like I am.

(Do you get a terminal bell after "+ or is your terminal bell disabled?)

> The behavior is the same with .vimrc disabled.
> 
> So, my Debian, X, Xfce, Terminal, and/or Vim are not working as documented
> (?).

Try:

vim --version | sed -n -e 1,2p -e /GUI/p -e /clip/p



Re: Copy from Firefox and paste into Terminal with Vim

2024-02-07 Thread David Christensen

On 2/6/24 06:25, Max Nikulin wrote:

On 06/02/2024 13:28, David Christensen wrote:

On 2/5/24 19:03, Max Nikulin wrote:

    xclip -o -selection PRIMARY
    xclip -o -selection CLIPBOARD


That is useful.


I expected that you would try both commands when vim is unable to paste. 
It would allow to discriminate whether it is Firefox or Vim issue.



I tried using those commands, but was getting confusing results.  If and 
when my Debian, X, Xfce, Terminal, and/or Vim misbehave again, I will 
see if those commands produce any clues.




If I start Firefox, browse to https://www.toyota.com/dealers, select the
the first dealer contents, start Vim, press and release the 
double-quote key, press and release the asterisk key, and press and 
release the p key, Vim inserts a blank line.


What is the effect of ["], [+], [p] keystrokes?



https://lists.debian.org/debian-user/2024/02/msg00277.html


or C-R* in insert mode. 


I do not understand your notation:

 C-R*


[Ctrl+R], [*] or [Ctrl+R], [+]

     :help i_CTRL-R



In command mode:

* Pressing Ctrl+R causes the bottom line to say:

Already at newest change

* Pressing Ctrl+R then + causes the cursor to move down one line.

* Pressing Ctrl+R then * causes the bottom line to say:

search hit BOTTOM, continuing at TOP


In insert mode:

* Pressing Ctrl+R causes the following two characters to be inserted 
into columns 53 and 54 of the bottom line:


^R

* Pressing Ctrl+R then + causes the two characters to be removed from 
the bottom line


* Pressing Ctrl+R then * causes the two characters to be removed from 
the bottom line




... Ctrl+Shift+V


I was trying to recommend against it, despite currently bracketed paste 
is enabled by default in BASH.



https://lists.debian.org/debian-user/2024/02/msg00276.html



https://security.stackexchange.com/questions/39118/how-can-i-protect-myself-from-this-kind-of-clipboard-abuse



Yuck.


I wonder if the https://www.toyota.com/dealers content I was attempting 
to paste into Vim contained exploits (?).  I have rebooted several 
times; perhaps the effects were not persistent (?).  Toyota's web site 
is different today; perhaps Toyota removed the exploits (?).



I wonder if the following will display exploits (?):

$ xclip -o -selection PRIMARY

$ xclip -o -selection CLIPBOARD


I wonder if my Vim has blocked "+p and "*p as a means to protect against 
clipboard attacks?




As to vim docs

     :help gui-selection
     :help quoteplus



https://lists.debian.org/debian-user/2024/02/msg00277.html



and for completeness

     :help registers



It seems that I have been conflating the terms and concepts "buffer" and 
"register".




Perhaps

     :help user-manual

contains description as well



Vim has more features than I know or use.


David



Re: Copy from Firefox and paste into Terminal with Vim

2024-02-06 Thread David Christensen

On 2/6/24 05:48, John Hasler wrote:

My .vimrc contains

syntax on
set mouse-=a

And pasting works.



Thank you for the reply.  :-)


If and when Firefox, Debian, X, Xfce, Terminal, and/or Vim misbehave 
again, I will try your suggestions.




VIM - Vi IMproved 9.0 (2022 Jun 28, compiled Nov 20 2023 16:05:25)
Included patches: 1-2116



2024-02-06 23:39:21 dpchrist@laalaa ~
$ cat /etc/debian_version ; uname -a ; vim --version | head -n 2
11.8
Linux laalaa 5.10.0-27-amd64 #1 SMP Debian 5.10.205-2 (2023-12-31) 
x86_64 GNU/Linux

VIM - Vi IMproved 8.2 (2019 Dec 12, compiled Oct 01 2021 01:51:08)
Included patches: 1-2434


David



Re: Copy from Firefox and paste into Terminal with Vim

2024-02-06 Thread David Christensen

On 2/6/24 03:33, Ralph Aichinger wrote:

On Mon, 2024-02-05 at 15:14 -0800, David Christensen wrote:

I am unable to determine if the problem is Firefox, Vim, or something
else.

Comments or suggestions?


As others have written, vim has changed copy+paste defaults some time
ago. Some even call this changing defaults "they broke copy+paste" ;).
One easy thing you might want to check is if this also happens in
neovim. Neovim did not make this copy+paste change, and it might
behave subtly different. It's quick to install and check.

/ralph



Thank you for the reply.  :-)


I prefer to use Vim, as it seems to be available and/or installed on all 
of the various hosts I use (including those I do not administer).



David



Re: Copy from Firefox and paste into Terminal with Vim

2024-02-06 Thread David Christensen

On 2/6/24 00:12, Klaus Singvogel wrote:

David Christensen wrote:

On 2/5/24 21:45, to...@tuxteam.de wrote:

Try ":set mouse=" and see whether it helps. Perhaps it's that.


That's the way. That's the fix for the root cause.



Thank you for the reply.  :-)


Currently, Firefox, Vim, select, copy, and/or paste seem to be behaving. 
 If and when the gremlins wake up, I'll try your suggestion.



David



Re: Copy from Firefox and paste into Terminal with Vim

2024-02-06 Thread David Christensen

On 2/6/24 04:28, Greg Wooledge wrote:

On Mon, Feb 05, 2024 at 10:28:53PM -0800, David Christensen wrote:

Continuing from above in Vim in Insert mode, if I then simultaneously press
the Ctrl, Shift, and v keys, and then release all keys, Vim inserts the
contents of the clipboard; as confirmed by:

 xclip -o -selection CLIPBOARD


How's that possible?



Thank you for the reply.  :-)


Apparently, something in the 920M bytes of my boot file system and/or in 
the 8009M bytes of my root file system make it possible.




Are you running a GUI version of vim (gvim?)



No.



instead of running vim in a terminal?



I am running Vim in Terminal.



Or are you using an exotic terminal?



I do not believe so.



If you're using a terminal that isn't xterm, please specify which.



I used the Xfce Panel Preferences dialog to create a Launcher item with 
one Terminal Emulator item:


Name:   Terminal Emulator
Comment:Use the command line
Command:exo-open --launch TerminalEmulator
Working Directory:
Icon:   org.xfce.terminalemulator
Options:
checked Use startup notification
unchecked   Run in terminal


I click on the panel icon to start Terminal.



In xterm and urxvt, Ctrl-Shift-v is identical to Ctrl-v ("literal
next"), so there's no way vim can distinguish the two.  And yes, I
tested it just to be sure.  In both xterm and urxvt, vim, insert > mode, 
Ctrl-Shift-v acts exactly like Ctrl-v.



I am seeing similar behavior:

https://lists.debian.org/debian-user/2024/02/msg00276.html



This applies in general to *any* issue that involves exotic key
combinations, because different terminals handle them differently.



Okay.


David



Re: Copy from Firefox and paste into Terminal with Vim

2024-02-06 Thread David Christensen

On 2/6/24 03:15, Dan Ritter wrote:

David Christensen wrote:

On 2/5/24 16:48, Dan Ritter wrote:

David Christensen wrote:

Please provide a URL that describes the Vim "+ and "* buffers, how to
interact with them within Vim, how to interact with them from other apps,
etc..


https://www.oreilly.com/library/view/learning-the-vi/9780596529833/ch04s03.html



Thank you for the reply.  :-)


Interesting.  Perhaps I should try to add buffers to my Vim skill set.



The "+ and "* buffers will get filled with primary and clipboard
selections when they occur, or you can fill them yourself so
that other applications can read from them.



In a window running Terminal running Vim in command mode:

* Pressing " then + then p seems to paste from the default Vim buffer -- 
what I seem to recall being referred to as the "yank buffer" (?).


* Pressing " then * then p seems to paste from the default Vim buffer.



:set clipboard=unnamed, unnamedplus


Vim says:

E518: Unknown option: unnamedplus


If I run the command:

:set clipboard=unnamed,unnamedplus


Vim does not complain, and "+p and "*p behave as above.


Perhaps my .vimrc is interfering (?).  Here it is again FYI:

2024-02-06 22:50:35 dpchrist@laalaa ~
$ grep -v '"' .vimrc | grep .
map q 
set autoindent
set backspace=indent,eol,start
set nocompatible
set nomodeline
set number
set numberwidth=8
set paste
set shiftwidth=4
set wildmode=longest,list


Disabling .vimrc and testing "+p, "*p, and :set 
clipboard=unnamed,unnamedplus again, the behavior is the same.




makes the basic vim clipboard -- the one without a name, the one
that you use if you just dd or y a line -- be the same as the
X11 primary selection buffer.



Not on my Debian, X, Xfce, Terminal, and/or Vim.



https://vimdoc.sourceforge.net/htmldoc/gui.html#clipboard



In a window running Terminal running Vim in command mode with .vimrc 
enabled:


* "*dd deletes the line containing the insertion point.  The line is not 
copied to the keyboard.


* "*p pastes the line previously deleted after the line containing the 
insertion point.



The behavior is the same with .vimrc disabled.


So, my Debian, X, Xfce, Terminal, and/or Vim are not working as 
documented (?).



David



Re: Copy from Firefox and paste into Terminal with Vim

2024-02-06 Thread David Christensen

On 2/5/24 16:29, DdB wrote:

Am 06.02.2024 um 00:14 schrieb David Christensen:

Comments or suggestions?

This may be unrelated, but ...
I can copy/paste using the mouse, or - if i use the keyboard - i need to
copy paste using CTRL-Shift-C and CTRL-Shift-V (when in the terminal
emulator like gnome-terminal or terminator)



Thank you for the reply.  :-)


Firefox and Vim seem to be playing nice today -- I can select text in 
Firefox and paste via middle-click into a window running Terminal 
running Vim.  I tried several times, but was unable to get them to 
malfunction.



Similarly, Ctrl+Shift+C and Ctrl+Shift+V within a window running 
Terminal running Vim in either command mode or insert mode -- I can 
select and copy text to the (X primary?) clipboard and I can paste text 
from the (X primary?) clipboard; respectively.



So, it appears the gremlins must be asleep.  When the wake up, I'll try 
again.



Back in the day, I worked on a Windows hardware/ software validation 
project.  Some of the team members had a tool that could record a 
Windows desktop GUI session, save it to a script, and replay a script on 
demand.  Creating useful scripts was tedious and difficult, but the 
benefits were huge.  Is there a FOSS equivalent for Debian, X, Xfce, etc.?



David



Re: Copy from Firefox and paste into Terminal with Vim

2024-02-06 Thread Max Nikulin

On 07/02/2024 00:35, Ralph Aichinger wrote:

On Tue, 2024-02-06 at 21:31 +0700, Max Nikulin wrote:

is active in terminal, it is possible to hold [Shift] to get mouse
events handled by terminal instead of Vim or another application
running in terminal.


I think pressing shift does not work here in e.g. gnome-terminal,
because there paste is Shift-Ctrl-V and interpreted by gnome-terminal.
Have not tried it though, vim taking care of the mouse is just nuts
in my opinion ;)


[Ctrl+Shift+V] is not a mouse event. Consider vim with enabled mouse on 
a remote host when X11 forwarding is disabled in ssh. Local selection is 
not available through + and * registers. It is handy to use Shift to be 
able to select some text (unless it is multiline text in a vertically 
split window) or to paste in insert mode by Shift+middle mouse button.





xterm PRIMARY and CLIPBOARD selection [was: Re: Copy from Firefox and paste into Terminal with Vim]

2024-02-06 Thread Max Nikulin

On 07/02/2024 00:38, Nicolas George wrote:

Max Nikulin (12024-02-07):

 Shift Ctrl C:


CtrlInsert is the standard counterpart to ShiftInsert.


It may be a convention for applications other than terminals, however I 
am unsure what "standard" means for terminals. Konsole has "reverted" 
bindings: [Shift+Insert] for CLIPBOARD and [Ctrl+Shift+Insert] for 
PRIMARY. Unsure if it was so before appearance of Wayland (it did not 
support PRIMARY at first). I have seen a (likely) KDE bug that paste 
from PRIMARY by middle click is a security issue, so it should not be 
supported.


Certainly, it is up to you if you wish to have [Ctrl+Insert] binding. I 
am unaware of any conflicts with applications running in terminals.



exec-formatted("sh -c 'xsel --output --primary | \
 exec xsel --input --clipboard'", PRIMARY)\n\


copy-selection(CLIPBOARD)

… is simpler.


Thanks, it seems, it works in bookworm. Several years ago xterm did not 
support ownership of independent CLIPBOARD and PRIMARY simultaneously. 
It was a workaround for the following scenario:


- select some text
- copy it to CLIPBOARD
- select another fragment of text (PRIMARY)
- switch to another application
- paste from PRIMARY
- paste from CLIPBOARD

I have the following note

! Allow both primary selection and clipboard copy-paste
! Ctrl+Shift+V, Ctrl+Shift+Insert, Ctrl+Shift+C similar to gnome-terminal
! Should work out of the box:
! Shift  Insert:insert-selection(SELECT, CUT_BUFFER0)
! Notice that copy-selection(CLIPBOARD) binds PRIMARY and SELECTION, see
! https://bugs.debian.org/cgi-bin/bugreport.cgi?bug=588785#108
! There is no point to use CUT_BUFFER1 as in xterm(1) "Custom Key Bindings"
! insert-selection(CLIPBOARD, CUT_BUFFER1)

Likely the related changes
https://invisible-island.net/xterm/xterm.log.html#xterm_336
Patch #336 - 2018/09/19

ensure that only one of PRIMARY and CLIPBOARD is owned by xterm
at a given time (Debian #901249).

https://invisible-island.net/xterm/xterm.log.html#xterm_338
Patch #338 - 2018/12/09

revert the change which prevented concurrent ownership
of different selection targets, and instead modify selection storage
so that different concurrent requests for different selection
targets will be stored/retrieved independently (Debian #901249).

For me it is not easy to follow discussions of xterm bugs and to read 
man page selections related to selection.




Re: Copy from Firefox and paste into Terminal with Vim

2024-02-06 Thread Ralph Aichinger
On Tue, 2024-02-06 at 21:31 +0700, Max Nikulin wrote:
> is active in terminal, it is possible to hold [Shift] to get mouse 
> events handled by terminal instead of Vim or another application
> running in terminal.

I think pressing shift does not work here in e.g. gnome-terminal,
because there paste is Shift-Ctrl-V and interpreted by gnome-terminal.
Have not tried it though, vim taking care of the mouse is just nuts
in my opinion ;)

/ralph



Re: Copy from Firefox and paste into Terminal with Vim

2024-02-06 Thread Nicolas George
Max Nikulin (12024-02-07):
> Shift Ctrl C:

CtrlInsert is the standard counterpart to ShiftInsert.

>   exec-formatted("sh -c 'xsel --output --primary |
> \
> exec xsel --input --clipboard'", PRIMARY)\n\

copy-selection(CLIPBOARD)

… is simpler.

Regards,

-- 
  Nicolas George



Re: Copy from Firefox and paste into Terminal with Vim

2024-02-06 Thread Max Nikulin

On 06/02/2024 21:57, Greg Wooledge wrote:

Anything that came from a desktop environment is pretty exotic to me.
I'm pretty old-school.  If xterm can't do it, then I'll call it exotic.


Rewrap on window resize is a convenient feature of libvte.

Ctrl+Shift+V for xterm:

xterm*vt100.translations: #override \n\
Shift~Ctrl  Insert:insert-selection(PRIMARY, CUT_BUFFER0) \n\
Shift Ctrl  Insert:insert-selection(CLIPBOARD) \n\
Shift Ctrl C: exec-formatted("sh -c 'xsel --output 
--primary | \

exec xsel --input --clipboard'", PRIMARY)\n\
Shift Ctrl V: insert-selection(CLIPBOARD)


As to + and * registers. What kind of vim do you use? At least vim-gtk3
provides console vim binary built with x11 support. Perhaps it is
+xterm_clipboard option.

unicorn:~$ vim --version | sed -n -e 1,2p -e /GUI/p -e /clip/p
VIM - Vi IMproved 9.0 (2022 Jun 28, compiled May 04 2023 10:24:44)
Included patches: 1-1378, 1499
Huge version without GUI.  Features included (+) or not (-):
-clipboard +keymap+printer   +vertsplit
+eval  -mouse_jsbterm -sun_workshop  -xterm_clipboard


If you do not like vim-gtk3, perhaps vim-motif has support of * and + 
registers.




Re: Copy from Firefox and paste into Terminal with Vim

2024-02-06 Thread Greg Wooledge
On Tue, Feb 06, 2024 at 03:36:23PM +, debian-u...@howorth.org.uk wrote:
> I know I don't like xterm so I never use it. I mainly use lxterminal
> and sometimes gnome-terminal but they both must be 'exotic' since they
> behave as David said.

The following NEW packages will be installed:
  libvte-2.91-0 libvte-2.91-common lxterminal

Hmm, OK, that's not bad.

First thing I try: Ctrl-v Ctrl-v (at a bash prompt).  This gives ^V as
expected.

Second thing I try: Ctrl-v Shift-Ctrl-v.  This gives a long-ish paste
of what appears to be base64-encoded content, but beginning with ^[[200~
(start of bracketed paste).  There's probably another escape sequence
at the end (end of bracketed paste?) but with no Ctrl-V acting upon it,
it's not visible.

So I guess this Shift-Ctrl-v is something that's handled directly by
the terminal emulator, and does *not* result in a byte sequence that's
interpreted by the application.  That answers one of my questions, at
least.

There is ... almost no documentation, however.  "man lxterminal" gives
a stub man page written by the Debian maintainer.  The /usr/share/doc
directory is barren as well:

unicorn:/usr/share/doc/lxterminal$ ls
changelog.Debian.gz  changelog.gz  copyright

So I guess people learn about lxterminal features like Shift-Ctrl-v by
word of mouth...?

The terminal has a menu bar with a Help option.  The Help menu has exactly
one choice: About.  About gives a popup window with a link to
.  Going there and clicking the WIKI button
leads me to  which is a 404 page.

*sigh*



Re: Copy from Firefox and paste into Terminal with Vim

2024-02-06 Thread debian-user
Greg Wooledge  wrote:
> On Mon, Feb 05, 2024 at 10:28:53PM -0800, David Christensen wrote:
> > Continuing from above in Vim in Insert mode, if I then
> > simultaneously press the Ctrl, Shift, and v keys, and then release
> > all keys, Vim inserts the contents of the clipboard; as confirmed
> > by:
> > 
> > xclip -o -selection CLIPBOARD  
> 
> How's that possible?  Are you running a GUI version of vim (gvim?)
> instead of running vim in a terminal?  Or are you using an exotic
> terminal?

Wow, thanks! I learned something new.

> In xterm and urxvt, Ctrl-Shift-v is identical to Ctrl-v ("literal
> next"), so there's no way vim can distinguish the two.  And yes, I
> tested it just to be sure.  In both xterm and urxvt, vim, insert
> mode, Ctrl-Shift-v acts exactly like Ctrl-v.

So it does. How bizarre! Makes vim in an xterm unusable.

> If you're using a terminal that isn't xterm, please specify which.
> This applies in general to *any* issue that involves exotic key
> combinations, because different terminals handle them differently.

I know I don't like xterm so I never use it. I mainly use lxterminal
and sometimes gnome-terminal but they both must be 'exotic' since they
behave as David said.



Re: Copy from Firefox and paste into Terminal with Vim

2024-02-06 Thread Greg Wooledge
On Tue, Feb 06, 2024 at 09:38:11PM +0700, Max Nikulin wrote:
> On 06/02/2024 19:28, Greg Wooledge wrote:
> > On Mon, Feb 05, 2024 at 10:28:53PM -0800, David Christensen wrote:
> > > Continuing from above in Vim in Insert mode, if I then simultaneously 
> > > press
> > > the Ctrl, Shift, and v keys, and then release all keys, Vim inserts the
> > > contents of the clipboard; as confirmed by:
> > > 
> > >  xclip -o -selection CLIPBOARD
> > 
> > How's that possible?  Are you running a GUI version of vim (gvim?)
> > instead of running vim in a terminal?  Or are you using an exotic
> > terminal?
> 
> Are you considering any vte-based terminal as an exotic one? GNOME terminal,
> konsole, lxterminal, and others... They have [Ctrl+Shift+v] hotkey out of
> the box in addition to [Insert]-based ones.

Anything that came from a desktop environment is pretty exotic to me.
I'm pretty old-school.  If xterm can't do it, then I'll call it exotic.

> As to + and * registers. What kind of vim do you use? At least vim-gtk3
> provides console vim binary built with x11 support. Perhaps it is
> +xterm_clipboard option.

unicorn:~$ vim --version | sed -n -e 1,2p -e /GUI/p -e /clip/p
VIM - Vi IMproved 9.0 (2022 Jun 28, compiled May 04 2023 10:24:44)
Included patches: 1-1378, 1499
Huge version without GUI.  Features included (+) or not (-):
-clipboard +keymap+printer   +vertsplit
+eval  -mouse_jsbterm -sun_workshop  -xterm_clipboard



Re: Copy from Firefox and paste into Terminal with Vim

2024-02-06 Thread Max Nikulin

On 06/02/2024 19:28, Greg Wooledge wrote:

On Mon, Feb 05, 2024 at 10:28:53PM -0800, David Christensen wrote:

Continuing from above in Vim in Insert mode, if I then simultaneously press
the Ctrl, Shift, and v keys, and then release all keys, Vim inserts the
contents of the clipboard; as confirmed by:

 xclip -o -selection CLIPBOARD


How's that possible?  Are you running a GUI version of vim (gvim?)
instead of running vim in a terminal?  Or are you using an exotic
terminal?


Are you considering any vte-based terminal as an exotic one? GNOME 
terminal, konsole, lxterminal, and others... They have [Ctrl+Shift+v] 
hotkey out of the box in addition to [Insert]-based ones.


As to + and * registers. What kind of vim do you use? At least vim-gtk3 
provides console vim binary built with x11 support. Perhaps it is 
+xterm_clipboard option.




Re: Copy from Firefox and paste into Terminal with Vim

2024-02-06 Thread tomas
On Tue, Feb 06, 2024 at 09:31:33PM +0700, Max Nikulin wrote:

[...]

> Concerning set "mouse=", I usually use it, but even when mouse handling is
> active in terminal, it is possible to hold [Shift] to get mouse events
> handled by terminal instead of Vim or another application running in
> terminal.

Indeed! Thanks for this one, Max :-)

Cheers
-- 
t


signature.asc
Description: PGP signature


Re: Copy from Firefox and paste into Terminal with Vim

2024-02-06 Thread Max Nikulin

On 06/02/2024 18:33, Ralph Aichinger wrote:

As others have written, vim has changed copy+paste defaults some time
ago. Some even call this changing defaults "they broke copy+paste" .


I am using vim in GUI terminal applications and I have not noticed it. 
Vim is a rare application that provides access to both PRIMARY_SELECTION 
and CLIPBOARD out of the box. E.g. in Emacs it is necessary to configure 
custom bindings, using existing user options you can choose any, but not 
both.


P.S.

Concerning set "mouse=", I usually use it, but even when mouse handling 
is active in terminal, it is possible to hold [Shift] to get mouse 
events handled by terminal instead of Vim or another application running 
in terminal.




Re: Copy from Firefox and paste into Terminal with Vim

2024-02-06 Thread Max Nikulin

On 06/02/2024 13:28, David Christensen wrote:

On 2/5/24 19:03, Max Nikulin wrote:

    xclip -o -selection PRIMARY
    xclip -o -selection CLIPBOARD


That is useful.


I expected that you would try both commands when vim is unable to paste. 
It would allow to discriminate whether it is Firefox or Vim issue.



If I start Firefox, browse to https://www.toyota.com/dealers, select the
the first dealer contents, start Vim, press and release the double-quote 
key, press and release the asterisk key, and press and release the p 
key, Vim inserts a blank line.


What is the effect of ["], [+], [p] keystrokes?

or C-R* in insert mode. 


I do not understand your notation:

     C-R*


[Ctrl+R], [*] or [Ctrl+R], [+]

:help i_CTRL-R


... Ctrl+Shift+V


I was trying to recommend against it, despite currently bracketed paste 
is enabled by default in BASH.


https://security.stackexchange.com/questions/39118/how-can-i-protect-myself-from-this-kind-of-clipboard-abuse

As to vim docs

:help gui-selection
:help quoteplus

and for completeness

:help registers

Perhaps

:help user-manual

contains description as well



Re: Copy from Firefox and paste into Terminal with Vim

2024-02-06 Thread John Hasler
My .vimrc contains

syntax on
set mouse-=a


And pasting works.

VIM - Vi IMproved 9.0 (2022 Jun 28, compiled Nov 20 2023 16:05:25)
Included patches: 1-2116
-- 
John Hasler 
j...@sugarbit.com
Elmwood, WI USA



Re: Copy from Firefox and paste into Terminal with Vim

2024-02-06 Thread Greg Wooledge
On Tue, Feb 06, 2024 at 06:15:39AM -0500, Dan Ritter wrote:
> https://www.oreilly.com/library/view/learning-the-vi/9780596529833/ch04s03.html
> 
> The "+ and "* buffers will get filled with primary and clipboard
> selections when they occur, or you can fill them yourself so
> that other applications can read from them.

That page does not contain a + or * character at all, and while it
does describe buffers, it does not describe buffers whose names are
anything other than lowercase letters.  In fact, it explicitly says
there are only 26 of them (a-z).

Furthermore, in my own testing just now, I'm unable to get this to
work.  vim (version 2:9.0.1378-2) running in urxvt, command mode,
pressing "+ or "* generates a terminal bell.  Pressing p after
either one of these pastes what's in vim's unnamed default buffer.



Re: Copy from Firefox and paste into Terminal with Vim

2024-02-06 Thread Greg Wooledge
On Mon, Feb 05, 2024 at 10:28:53PM -0800, David Christensen wrote:
> Continuing from above in Vim in Insert mode, if I then simultaneously press
> the Ctrl, Shift, and v keys, and then release all keys, Vim inserts the
> contents of the clipboard; as confirmed by:
> 
> xclip -o -selection CLIPBOARD

How's that possible?  Are you running a GUI version of vim (gvim?)
instead of running vim in a terminal?  Or are you using an exotic
terminal?

In xterm and urxvt, Ctrl-Shift-v is identical to Ctrl-v ("literal
next"), so there's no way vim can distinguish the two.  And yes, I
tested it just to be sure.  In both xterm and urxvt, vim, insert
mode, Ctrl-Shift-v acts exactly like Ctrl-v.

If you're using a terminal that isn't xterm, please specify which.
This applies in general to *any* issue that involves exotic key
combinations, because different terminals handle them differently.



Re: Copy from Firefox and paste into Terminal with Vim

2024-02-06 Thread Ralph Aichinger
On Mon, 2024-02-05 at 15:14 -0800, David Christensen wrote:
> I am unable to determine if the problem is Firefox, Vim, or something
> else.
> 
> Comments or suggestions?

As others have written, vim has changed copy+paste defaults some time
ago. Some even call this changing defaults "they broke copy+paste" ;).
One easy thing you might want to check is if this also happens in
neovim. Neovim did not make this copy+paste change, and it might 
behave subtly different. It's quick to install and check.

/ralph



Re: Copy from Firefox and paste into Terminal with Vim

2024-02-06 Thread Dan Ritter
David Christensen wrote: 
> On 2/5/24 16:48, Dan Ritter wrote:
> > David Christensen wrote:
> 
> 
> Please provide a URL that describes the Vim "+ and "* buffers, how to
> interact with them within Vim, how to interact with them from other apps,
> etc..

https://www.oreilly.com/library/view/learning-the-vi/9780596529833/ch04s03.html

The "+ and "* buffers will get filled with primary and clipboard
selections when they occur, or you can fill them yourself so
that other applications can read from them.

:set clipboard=unnamed, unnamedplus

makes the basic vim clipboard -- the one without a name, the one
that you use if you just dd or y a line -- be the same as the
X11 primary selection buffer.

https://vimdoc.sourceforge.net/htmldoc/gui.html#clipboard

-dsr-



Re: Copy from Firefox and paste into Terminal with Vim

2024-02-06 Thread Klaus Singvogel
David Christensen wrote:
> On 2/5/24 21:45, to...@tuxteam.de wrote:
> > Try ":set mouse=" and see whether it helps. Perhaps it's that.

That's the way. That's the fix for the root cause.

> I am unable to correlate that Vim setting change to the Vim paste problems.

But it's vim, which is changing the way how Copy is handled for its input.

Best regards,
Klaus.
-- 
Klaus Singvogel
GnuPG-Key-ID: 1024R/5068792D  1994-06-27



Re: Copy from Firefox and paste into Terminal with Vim

2024-02-05 Thread tomas
On Mon, Feb 05, 2024 at 11:07:53PM -0800, David Christensen wrote:
> On 2/5/24 21:45, to...@tuxteam.de wrote:

[...]

> I am not aware of any problems pasting into other applications, just pasting
> into Vim.
> 
> 
> > Vim has changed its defaults a while ago in an annoying way.
> > 
> > Try ":set mouse=" and see whether it helps. Perhaps it's that.
> 
> 
> I am unable to correlate that Vim setting change to the Vim paste problems.

Pity. In my case it does help, but my setup is rather exotic
these days (I use X's primary selection as far as possible,
some brain dead applications don't grok that anymore).

Hope you find a solution

Cheers
-- 
t


signature.asc
Description: PGP signature


Re: Copy from Firefox and paste into Terminal with Vim

2024-02-05 Thread David Christensen

On 2/5/24 21:45, to...@tuxteam.de wrote:

On Mon, Feb 05, 2024 at 03:14:45PM -0800, David Christensen wrote:

debian-user:

I have a laptop with:


[copy in Firefox, paste in vim]


I am unable to determine if the problem is Firefox, Vim, or something else.


Are you able to paste into another application?



Thank you for the reply. :-)


I am not aware of any problems pasting into other applications, just 
pasting into Vim.




Vim has changed its defaults a while ago in an annoying way.

Try ":set mouse=" and see whether it helps. Perhaps it's that.



I am unable to correlate that Vim setting change to the Vim paste problems.


David




Re: Copy from Firefox and paste into Terminal with Vim

2024-02-05 Thread David Christensen

On 2/5/24 16:48, Dan Ritter wrote:

David Christensen wrote:

Normally, I can cut and paste between Xfce desktop applications.


Enter a Zip Code of "12345", highlight the first result, copy it to the
clipboard, start Terminal, open a file with Vim, press "i" to enter insert
mode, and paste, sometimes I see what I copied to the clipboard and
sometimes I see nothing.


I am unable to determine if the problem is Firefox, Vim, or something else.


Are you aware that there are at least three 'clipboards' here?

X11 primary selection: this usually get filled by selecting text
in a terminal. It usually gets pasted by Button 2. In vim, this
is the "+ buffer.

X11 clipboard: this usually gets filled by ctrl-c or
ctrl-shift-c or a menu "Copy". It usually gets pasted by ctrl-v
or ctrl-shift-v or a menu "Paste". In vim, this is the "*
buffer.



Thank you for the reply.


I was aware of the X11 clipboard and interacting with it via Edit menus, 
context menus (right-click), Ctrl+C, Ctrl+X, Ctrl+V, Shift+Delete, 
Shift+Insert, etc..



I was aware of X11 select and paste via middle-click.


Please provide a URL that describes the Vim "+ and "* buffers, how to 
interact with them within Vim, how to interact with them from other 
apps, etc..




Vim can bypass a chunk of this by combining primary and
clipboard:

:set clipboard=unnamed,unnamedplus



I entered the above command into Vim, but am unsure what behavior or 
change in behavior I am supposed to see (?).



David



Re: Copy from Firefox and paste into Terminal with Vim

2024-02-05 Thread David Christensen

On 2/5/24 19:03, Max Nikulin wrote:

On 06/02/2024 06:14, David Christensen wrote:

Enter a Zip Code of "12345", highlight the first result, copy it
to the clipboard,
[...]> But if I close the above Firefox window, start a Firefox 
instance,

browse to:


If you terminate an application handling selection then content is 
not available any more.



Thank you for the reply.  :-)


I did not attempt to paste from the X primary selection after closing 
Firefox.




To debug you may use xsel or xclip

xclip -o -selection PRIMARY
xclip -o -selection CLIPBOARD



That is useful.


To access primary selection or clipboard in vim use * and + 
registers: "*p in normal mode 



If I start Firefox, browse to https://www.toyota.com/dealers, select the
the first dealer contents, start Vim, press and release the double-quote 
key, press and release the asterisk key, and press and release the p 
key, Vim inserts a blank line.



or C-R* in insert mode. 



I do not understand your notation:

C-R*


Continuing from above in Vim in normal (command) mode, if I then press 
and release the i key, then simultaneously press the Ctrl, r, and 
asterisk keys, and then release all keys, nothing happens.




... Ctrl+Shift+V



Continuing from above in Vim in Insert mode, if I then simultaneously 
press the Ctrl, Shift, and v keys, and then release all keys, Vim 
inserts the contents of the clipboard; as confirmed by:


xclip -o -selection CLIPBOARD


David



Re: Copy from Firefox and paste into Terminal with Vim

2024-02-05 Thread tomas
On Mon, Feb 05, 2024 at 03:14:45PM -0800, David Christensen wrote:
> debian-user:
> 
> I have a laptop with:

[copy in Firefox, paste in vim]

> I am unable to determine if the problem is Firefox, Vim, or something else.

Are you able to paste into another application?

Vim has changed its defaults a while ago in an annoying way.

Try ":set mouse=" and see whether it helps. Perhaps it's that.

Cheers
-- 
t


signature.asc
Description: PGP signature


Re: Copy from Firefox and paste into Terminal with Vim

2024-02-05 Thread Max Nikulin

On 06/02/2024 06:14, David Christensen wrote:
Enter a Zip Code of "12345", highlight the first result, copy it to the 
clipboard,

[...]> But if I close the above Firefox window, start a Firefox instance,

browse to:


If you terminate an application handling selection then content is not 
available any more. To make selection "persistent", you may try some 
clipboard manager, but it may have not always desirable side effects.


To debug you may use xsel or xclip

xclip -o -selection PRIMARY
xclip -o -selection CLIPBOARD

To access primary selection or clipboard in vim use * and + registers: 
"*p in normal mode or C-R* in insert mode. It is safer than middle click 
or [Ctrl+Shift+V] handled by terminal since selection may contain 
terminal control characters (e.g. to exit from vim and to run rm -rf ~ 
in terminal).





Re: Copy from Firefox and paste into Terminal with Vim

2024-02-05 Thread Dan Ritter
David Christensen wrote: 
> Normally, I can cut and paste between Xfce desktop applications.
> 
> 
> Enter a Zip Code of "12345", highlight the first result, copy it to the
> clipboard, start Terminal, open a file with Vim, press "i" to enter insert
> mode, and paste, sometimes I see what I copied to the clipboard and
> sometimes I see nothing.
> 
> 
> I am unable to determine if the problem is Firefox, Vim, or something else.

Are you aware that there are at least three 'clipboards' here?

X11 primary selection: this usually get filled by selecting text
in a terminal. It usually gets pasted by Button 2. In vim, this
is the "+ buffer.

X11 clipboard: this usually gets filled by ctrl-c or
ctrl-shift-c or a menu "Copy". It usually gets pasted by ctrl-v
or ctrl-shift-v or a menu "Paste". In vim, this is the "*
buffer.

X11 secondary selection: you are unlikely to encounter it, but
when you do, it will be bizarre. Read: 
http://www.cs.man.ac.uk/~lindsec/secondary-selection.html

Vim can bypass a chunk of this by combining primary and
clipboard:

:set clipboard=unnamed,unnamedplus

in which case "* and "+ will be pasted simultaneously from vim.

-dsr-



Re: Copy from Firefox and paste into Terminal with Vim

2024-02-05 Thread DdB
Am 06.02.2024 um 00:14 schrieb David Christensen:
> Comments or suggestions?
This may be unrelated, but ...
I can copy/paste using the mouse, or - if i use the keyboard - i need to
copy paste using CTRL-Shift-C and CTRL-Shift-V (when in the terminal
emulator like gnome-terminal or terminator)




Re: Copy from Firefox and paste into Terminal with Vim

2024-02-05 Thread David Christensen

On 2/5/24 15:44, Bret Busby wrote:

On 6/2/24 07:14, David Christensen wrote:

debian-user:

I have a laptop with:

2024-02-05 15:04:48 dpchrist@laalaa ~
$ cat /etc/debian_version ; uname -a ; dpkg-query -W xfce4 firefox-esr 
vim

11.8
Linux laalaa 5.10.0-27-amd64 #1 SMP Debian 5.10.205-2 (2023-12-31) 
x86_64 GNU/Linux

firefox-esr    115.7.0esr-1~deb11u1
vim    2:8.2.2434-3+deb11u1
xfce4    4.16

2024-02-05 15:10:08 dpchrist@laalaa ~
$ grep -v '"' .vimrc | grep .
map q 
set autoindent
set backspace=indent,eol,start
set nocompatible
set nomodeline
set number
set numberwidth=8
set paste
set shiftwidth=4
set wildmode=longest,list


Normally, I can cut and paste between Xfce desktop applications.


For example, if I start Firefox, disable all extensions, browse to:

https://www.toyota.com/dealers/

Enter a Zip Code of "12345", highlight the first result, copy it to 
the clipboard, and paste into this message, I see:


Lia Toyota of Colonie
2116 Central Ave., Rte. 5, Schenectady NY 12304
(5.3 miles)
Today's Hours: 7:00 AM to 7:00 PM
(518) 374-3700


But if I close the above Firefox window, start a Firefox instance, 
browse to:


https://www.toyota.com/dealers/

Enter a Zip Code of "12345", highlight the first result, copy it to 
the clipboard, start Terminal, open a file with Vim, press "i" to 
enter insert mode, and paste, sometimes I see what I copied to the 
clipboard and sometimes I see nothing.

...

How exactly are you copying and pasting?

Are you marking the text and using Copy and Paste from the menu 
generated by clicking the non-dominant mouse button, or, are you marking 
the text, and using  to copy then  to paste?



Thank you for the reply.  :-)


Copy from Firefox -- drag to highlight text, then:

1.  Press Ctrl+C, or

2.  Right-click and choose Copy.


Paste into Vim:

1.  Middle click, or

2.  Right-click and choose Paste.


What happens if you copy and paste to an editor such as gedit? 
Does that work consistently? If so, what happens if you copy and paste to gedit, 
and then, copy from gedit, and paste to the vim window?



Copying from any Xfce window and pasting into Mousepad seems to work 
consistently.



Copying from Firefox, Mousepad, and potentially other Xfce windows into 
Vim does not work consistently.



Does it make any difference whether you have the vim session open, and 
the file open, into which you want to paste, before you copy the text 
that you want to paste into it?



No.


Have you tried the text editor that is the default editor for alpine 
(previously known as pine) - I think it is either nano or pico?



No.


David



Re: Copy from Firefox and paste into Terminal with Vim

2024-02-05 Thread Bret Busby

On 6/2/24 07:14, David Christensen wrote:

debian-user:

I have a laptop with:

2024-02-05 15:04:48 dpchrist@laalaa ~
$ cat /etc/debian_version ; uname -a ; dpkg-query -W xfce4 firefox-esr vim
11.8
Linux laalaa 5.10.0-27-amd64 #1 SMP Debian 5.10.205-2 (2023-12-31) 
x86_64 GNU/Linux

firefox-esr    115.7.0esr-1~deb11u1
vim    2:8.2.2434-3+deb11u1
xfce4    4.16

2024-02-05 15:10:08 dpchrist@laalaa ~
$ grep -v '"' .vimrc | grep .
map q 
set autoindent
set backspace=indent,eol,start
set nocompatible
set nomodeline
set number
set numberwidth=8
set paste
set shiftwidth=4
set wildmode=longest,list


Normally, I can cut and paste between Xfce desktop applications.


For example, if I start Firefox, disable all extensions, browse to:

https://www.toyota.com/dealers/

Enter a Zip Code of "12345", highlight the first result, copy it to the 
clipboard, and paste into this message, I see:


Lia Toyota of Colonie
2116 Central Ave., Rte. 5, Schenectady NY 12304
(5.3 miles)
Today's Hours: 7:00 AM to 7:00 PM
(518) 374-3700


But if I close the above Firefox window, start a Firefox instance, 
browse to:


https://www.toyota.com/dealers/

Enter a Zip Code of "12345", highlight the first result, copy it to the 
clipboard, start Terminal, open a file with Vim, press "i" to enter 
insert mode, and paste, sometimes I see what I copied to the clipboard 
and sometimes I see nothing.



I am unable to determine if the problem is Firefox, Vim, or something else.


Comments or suggestions?


David


How exactly are you copying and pasting?

Are you marking the text and using Copy and Paste from the menu 
generated by clicking the non-dominant mouse button, or, are you marking 
the text, and using  to copy then  to paste?


What happens if you copy and paste to an editor such as gedit? Does that 
work consistently? If so, what happens if you copy and paste to gedit, 
and then, copy from gedit, and paste to the vim window?


Does it make any difference whether you have the vim session open, and 
the file open, into which you want to paste, before you copy the text 
that you want to paste into it?


Have you tried the text editor that is the default editor for alpine 
(previously known as pine) - I think it is either nano or pico?



Bret Busby
Armadale
Western Australia
(UTC+0800)
.