Don't use unnamed register for clipboard
dblume

dblume commited on 2024-05-01 22:13:34
Showing 2 changed files, with 28 additions and 2 deletions.


Using unnamed register for clipboard is annoying because operations
like delete and change also overwrite the unnamed register.

Instead, use a <leader> command to specify the clipboard register.

Also add a commented-out WSL clipboard-tool for convenience.
... ...
@@ -16,7 +16,27 @@ set hidden          " Don't abandon Scratch buffer when hidden.
16 16
 set culopt=number   " Otherwise diff views have an underline. neovim issue 9800
17 17
 " Set the title of the terminal window. Consider changing titlestring, %t, %M
18 18
 set title titlestring=%f%m\ -\ nvim
19
-set clipboard^=unnamed  " Synchronize vim's default register and clipboard
19
+
20
+" WSL clipboard-tool fom 'help clipboard'
21
+"let g:clipboard = {
22
+"            \   'name': 'WslClipboard',
23
+"            \   'copy': {
24
+"            \      '+': '/mnt/c/Windows/system32/clip.exe',
25
+"            \      '*': '/mnt/c/Windows/system32/clip.exe',
26
+"            \    },
27
+"            \   'paste': {
28
+"            \      '+': 'powershell.exe -c [Console]::Out.Write($(Get-Clipboard -Raw).tostring().replace("`r", ""))',
29
+"            \      '*': 'powershell.exe -c [Console]::Out.Write($(Get-Clipboard -Raw).tostring().replace("`r", ""))',
30
+"            \   },
31
+"            \   'cache_enabled': 0,
32
+"            \ }
33
+
34
+" Yank and put into the system Clipboard (register + or *)
35
+" Otherwise make explicit commands "+yy "+y "+Y (or * instead of + as needed)
36
+" N.B. Don't use unnamed register for clipboard (set clipboard=unnamed)
37
+"      Delete operations would overwrite clipboard before pasting.
38
+nnoremap <leader>c "+
39
+vnoremap <leader>c "+
20 40
 
21 41
 " Make j and k move to the next row, not file line
22 42
 nnoremap j gj
... ...
@@ -18,7 +18,13 @@ set ttimeoutlen=100 " Affects Esc key, not leader.
18 18
 set noruler         " Don't show cursor pos on right side of status bar
19 19
 " Set the title of the terminal window. Consider changing titlestring, %t, %M
20 20
 set title titlestring=%f%m\ -\ vim
21
-set clipboard^=unnamed  " Synchronize vim's default register and clipboard
21
+
22
+" Yank and put into the system Clipboard (register + or *)
23
+" Otherwise make explicit commands "+yy "+y "+Y (or * instead of + as needed)
24
+" N.B. Don't use unnamed register for clipboard (set clipboard=unnamed)
25
+"      Delete operations would overwrite clipboard before pasting.
26
+nnoremap <leader>c "+
27
+vnoremap <leader>c "+
22 28
 
23 29
 if v:version >= 703
24 30
   " Do save the undo tree to file, but not in the local directory.
25 31