|
1 | | -*wayland.txt* For Vim version 9.2. Last change: 2026 Feb 14 |
| 1 | +*wayland.txt* For Vim version 9.2. Last change: 2026 Apr 20 |
2 | 2 |
|
3 | 3 |
|
4 | 4 | VIM REFERENCE MANUAL by Bram Moolenaar |
@@ -54,15 +54,12 @@ try connecting again. |
54 | 54 | 2. Wayland Selections *wayland-selections* |
55 | 55 |
|
56 | 56 | Vim supports the wlr-data-control-unstable-v1 and ext-data-control-v1 |
57 | | -protocols, for accessing the current Wayland selection. These are the best |
58 | | -case scenario protocols, see |wayland-focus-steal|. Selection in this case |
| 57 | +protocols, for accessing the current Wayland selection. Selection in this case |
59 | 58 | essentially means the "clipboard." You can check if your Wayland compositor |
60 | 59 | supports either of these protocols by running the wayland-info command, which |
61 | 60 | should be bundled with libwayland on your system: > |
62 | 61 | wayland-info | grep -E '(ext_data_control|zwlr_data_control)' |
63 | 62 | <If grep finds a match, then you have either or both protocols on your system. |
64 | | -If you don't get any match, then please see |wayland-focus-steal| for more |
65 | | -information. |
66 | 63 |
|
67 | 64 | Some compositors that are known to support either or both protocols: |
68 | 65 | 1. KWin (KDE) |
@@ -90,39 +87,65 @@ Vim determines which one to use when accessing the clipboard using the |
90 | 87 |
|
91 | 88 | *wayland-primary-selection* |
92 | 89 | If you find X11 style primary selections useful, Wayland also implements this |
93 | | -behaviour in its own protocols: |
94 | | - |
95 | | -- The primary selection protocol is the most widely supported, but requires |
96 | | - focus in order to be used, see |wayland-focus-steal|. |
97 | | - |
98 | | -- Data control protocol available on your system, such as the ext or wlr |
99 | | - protocols, then primary selection is also supported. This is unless you are |
100 | | - using version 1 (not the same as the 'v1' in the protocol name), of the |
101 | | - wlr-data-control protocol. Then the primary selection protocol will be used |
102 | | - as a fallback. |
103 | | - |
104 | | - *wayland-focus-steal* *wayland-gnome* |
105 | | -If you are using the GNOME desktop environment on Wayland, as of this writing, |
106 | | -there is no method of accessing/modifying the clipboard for external clients |
107 | | -such as Vim without being focused. Focused in this case means the client has |
108 | | -received some sort of input event, such as a window being focused. This is |
109 | | -what the wlr-data-control-unstable-v1 and ext-data-control-v1 protocols solve. |
110 | | -If your Wayland compositor does not support the above protocols, then the |
111 | | -above explanation applies. |
112 | | - |
113 | | -To solve this problem, Vim implements a way of gaining focus in order to |
114 | | -access the clipboard, by creating a temporary transparent top-level surface. |
115 | | -This is by default disabled and can be enabled via the 'wlsteal' option. |
116 | | -Moreover, a seat that has a keyboard is also required, see 'wlseat', and the |
117 | | -xdg-shell protocol must be available. Additionally, Vim must be compiled with |
118 | | -the |+wayland_focus_steal| feature. |
119 | | - |
120 | | -Note that this method can have several side effects from the result of focus |
121 | | -stealing. For example, if you have a taskbar that shows currently opened apps |
122 | | -in your desktop environment, then when Vim attempts to steal focus, it may |
123 | | -"flicker," as if a window was opened then immediately closed after. |
124 | | -Additionally, if you are in fullscreen mode, this focus stealing won't work, |
125 | | -because the created surface won't ever gain focus. If this happens, Vim will |
126 | | -seem to freeze temporarily, see 'wltimeoutlen' for more information. |
| 90 | +feature using the protocols that Vim supports. This is unless you are using |
| 91 | +version 1 (not the same as the 'v1' in the protocol name), of the |
| 92 | +wlr-data-control protocol, then primary selection will not be supported. You |
| 93 | +can check this using > |
| 94 | + wayland-info | grep -E '(ext_data_control|zwlr_data_control)' |
| 95 | +If the "version:" entry for "zwlr_data_control_manager_v1" is "2" or greater, |
| 96 | +then primary selection is supported. If you also get |
| 97 | +"ext_data_control_manager_v1", then Vim will use that protocol instead, which |
| 98 | +has primary selection support builtin into it. |
| 99 | + |
| 100 | +If your Wayland compositor does not support the wlr-data-control-v1 or the |
| 101 | +ext-data-control-v1 protocol, Vim cannot access the clipboard directly through |
| 102 | +the Wayland protocol. External tools such as wl-clipboard can be used instead |
| 103 | +via a user-defined |clipboard-providers|. |
| 104 | + |
| 105 | +Example: define a provider that shells out to `wl-copy` and `wl-paste`: >vim9 |
| 106 | + |
| 107 | + vim9script |
| 108 | + |
| 109 | + def Available(): bool |
| 110 | + return executable('wl-copy') && executable('wl-paste') |
| 111 | + enddef |
| 112 | + |
| 113 | + def Copy(reg: string, type: string, str: list<string>) |
| 114 | + var args = "wl-copy" |
| 115 | + |
| 116 | + if reg == "*" |
| 117 | + args ..= " -p" |
| 118 | + endif |
| 119 | + |
| 120 | + system(args, str) |
| 121 | + enddef |
| 122 | + |
| 123 | + def Paste(reg: string): tuple<string, list<string>> |
| 124 | + var args = "wl-paste --type text/plain;charset=utf-8" |
| 125 | + |
| 126 | + if reg == "*" |
| 127 | + args ..= " -p" |
| 128 | + endif |
| 129 | + |
| 130 | + return ("", systemlist(args)) |
| 131 | + enddef |
| 132 | + |
| 133 | + v:clipproviders["wl_clipboard"] = { |
| 134 | + available: Available, |
| 135 | + copy: { |
| 136 | + "+": Copy, |
| 137 | + "*": Copy |
| 138 | + }, |
| 139 | + paste: { |
| 140 | + "+": Paste, |
| 141 | + "*": Paste |
| 142 | + } |
| 143 | + } |
| 144 | + |
| 145 | + set clipmethod=wl_clipboard |
| 146 | + |
| 147 | + |
| 148 | +This relies on the wl-clipboard package being installed |
| 149 | +(https://github.com/bugaevc/wl-clipboard). |
127 | 150 |
|
128 | 151 | vim:tw=78:ts=8:noet:ft=help:norl |
0 commit comments