Coder Social home page Coder Social logo

vim-yoink's Introduction

Yoink.vim

Yoink will automatically maintain a history of yanks that you can choose between when pasting.

It provides very similar functionality to nvim-miniyank, YankRing.vim, vim-yankstack or the yank features in vim-easyclip.

Also see here if you prefer watching a video explanation of this plugin instead of the below text.

Mappings

Note that by default Yoink will not affect the way Vim behaves in any way. You have to add one or more of the following maps or enable one of the optional settings to produce an effect.

For example, if you want to add a key to swap the most recent paste around in the yank history:

nmap <c-n> <plug>(YoinkPostPasteSwapBack)
nmap <c-p> <plug>(YoinkPostPasteSwapForward)

nmap p <plug>(YoinkPaste_p)
nmap P <plug>(YoinkPaste_P)

" Also replace the default gp with yoink paste so we can toggle paste in this case too
nmap gp <plug>(YoinkPaste_gp)
nmap gP <plug>(YoinkPaste_gP)

With these mappings, immediately after performing a paste, you can cycle through the history by hitting <c-n> and <c-p>

We also need to override the p and P keys to notify Yoink that a paste has occurred, so that swapping via the <c-n> and <c-p> keys can be enabled. Otherwise paste functionality should be the same as default.

Note that yoink does not support swapping when doing paste in visual mode and so we do not add an xmap for p here. However, the vim-subversive plugin integrates with Yoink and does provide that functionality.

Note that the swap operations above will only affect the current paste and the history order will be unchanged. However - if you do want to permanently cycle through the history, you can do that too:

nmap [y <plug>(YoinkRotateBack)
nmap ]y <plug>(YoinkRotateForward)

Now when you hit [y/]y the current yank will change and you will see a preview of it in the status bar

You might also want to add a map for toggling whether the current paste is formatted or not:

nmap <c-=> <plug>(YoinkPostPasteToggleFormat)

Now, hitting <c-=> after a paste will toggle between formatted and unformatted (equivalent to using the = key). By default pastes will not be formatted until you toggle it afterwards using <c-=> (however you can also change this with the yoinkAutoFormatPaste setting as described below)

Finally, you can also optionally add the following map:

nmap y <plug>(YoinkYankPreserveCursorPosition)
xmap y <plug>(YoinkYankPreserveCursorPosition)

After adding this map, yank will function exactly the same as previously with the one difference being that the cursor position will not change after performing a yank. This can be more useful especially when yanking a large text object such as a paragraph.

Commands

:Yanks - Display the current yank history

:ClearYanks - Delete history. This will reduce the history down to 1 entry taken from the default register.

Settings

You can optionally override the default behaviour with the following settings:

  • g:yoinkMaxItems - History size. Default: 10.
  • g:yoinkSyncNumberedRegisters - When set to 1, every time the yank history changes the numbered registers 1 - 9 will be updated to sync with the first 9 entries in the yank history. See here for an explanation of why we would want do do this. Default: 0.
  • g:yoinkIncludeDeleteOperations - When set to 1, delete operations such as x or d or s will also be added to the yank history. Default: 0
  • g:yoinkSavePersistently - When set to 1, the yank history will be saved persistently across sessions of Vim. Note: Requires Neovim. See here for details. Default: 0
  • g:yoinkAutoFormatPaste - When set to 1, after a paste occurs it will automatically be formatted (using = key). Default: 0. Note that you can also leave this off and use the toggle key instead for cases where you want to format after the paste.
  • g:yoinkMoveCursorToEndOfPaste - When set to 1, the cursor will always be placed at the end of the paste. Default is 0 which will match normal Vim behaviour and place the cursor at the beginning when pasting multiline yanks. Setting to 1 can be nicer because it makes the post-paste cursor position more consistent between multiline and non-multiline pastes (that is, the cursor will be at the end in both cases). And also causes consecutive multiline pastes to be ordered correctly instead of interleaved together. Will also add to the jumplist if the cursor is moved more than 1 line.
  • g:yoinkSwapClampAtEnds - When set to 1, when we reach the beginning or end of the yank history, the swap will stop there. When set to 0, it will cycle back to the other end of the history so you can swap in the same direction forever. Default: 1
  • g:yoinkIncludeNamedRegisters - When set to 1, all yanks for all registers will be included in the history. When set to 0, only changes to the default register will be recorded. Default: 1
  • g:yoinkSyncSystemClipboardOnFocus - When set to 0, the System Clipboard feature described below will be disabled. Default: 1

Persistent/Shared History

When g:yoinkSavePersistently is set to 1, the yank history will be saved persistently by taking advantage of Neovim's "ShaDa" feature. Note that since ShaDa support only exists in Neovim this feature is not available for Vim.

You can also use this feature to sync the yank history across multiple running instances of Vim by updating Neovim's shada file. For example, if you execute :wshada in the first instance and then :rshada in the second instance, the second instance will be synced with the yank history in the first instance. If this becomes a common operation you might consider using key bindings for this.

Note also that the ! option must be added to Neovims shada setting for this feature to work. For example: set shada=!,'100,<50,s10,h (see :h 'shada' for details)

System Clipboard

Another feature worth mentioning is that if you have &clipboard set to either unnamed or unnamedplus then Yoink will automatically record yanks that occur outside of Vim. It does this by checking if the system clipboard was changed every time Vim gains focus and if so adding the new yank to the history.

Note that you can disable it by setting g:yoinkSyncSystemClipboardOnFocus to 0 then restarting vim

Integration with vim-cutlass

If you also have vim-cutlass installed then I suggest you set g:yoinkIncludeDeleteOperations to 1. Otherwise the 'cut' operator that you use will not be added to the yank history.

FAQ

  • I want the yank history in the autocomplete list

If you're using ncm2 for autocomplete you can use this. If you're using something else please create a github issue and we can look at adding a source for that

  • I want to rotate to a specific number in the :Yanks list. How do I do this?

Just pass a count to the [y command. For example, to rotate to yank #12 as displayed in the :Yanks list, execute 12[y

  • I want to add to the yank history manually from my own vimscript

You can call yoink#manualYank for this. Note that calling this will also set the contents of the default register with the given value. If you just want to add to history without affecting the default register, you can call yoink#addTextToHistory instead

  • I want to use Yoink <c-p> mapping in conjunction with the default ctrlp.vim mapping

Just use the following mappings:

let g:ctrlp_map=''
nmap <expr> <c-p> yoink#canSwap() ? '<plug>(YoinkPostPasteSwapForward)' : '<Plug>(ctrlp)'
  • I want to use the same binding for paste to trigger the swap afterwards

Try adding this to your .vimrc:

nmap <expr> p yoink#canSwap() ? '<plug>(YoinkPostPasteSwapBack)' : '<plug>(YoinkPaste_p)'
nmap <expr> P yoink#canSwap() ? '<plug>(YoinkPostPasteSwapForward)' : '<plug>(YoinkPaste_P)'

vim-yoink's People

Contributors

rlisowski avatar subnut avatar svermeulen avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar

vim-yoink's Issues

Vim error on entering visual mode

Every so often (haven't narrowed it down yet, but new buffers may be more likely? Or recently-opened vim instances with no viminfo for them...) I get the following error constantly repeating when I enter visual mode and try to move.

Error detected while processing function yoink#onYank[14]..<SNR>196_addToHi
story:                                                                     
line   16:                                                                 
E684: list index out of range: 1 

Clipboard error : Target STRING not available

Hi,

I've just started using the plugin. When starting neovim, I get the error Clipboard error : Target STRING not available. This only affects neovim, but not vim.

Googling around, I found neovim/neovim#2642 (comment), which relates to logic of monitoring the system's clipboard via yankrinkg.

And indeed, setting let g:yoinkSyncSystemClipboardOnFocus = 0 prevents this error.
Is there a way of having this fixed, while retaining the monitoring of the system's clipboard?

Last action was not paste - swap ignored

I am using the following version of vim: VIM - Vi IMproved 8.1 (2018 May 18, compiled Feb 19 2019 12:07:03) macOS version

I installed vim-yoink via Plug. The package did seem to install successfully. For example, if I enter the command :Yanks I get a nonempty list of the items that I have just yanked. However, when I type p in normal mode to paste, and then type <c-n> or <c-n>, I get the message Last action was not paste - swap ignored. Any help that you might be able to provide would be greatly appreciated!

Ctrl-N and ctrl-p after paste does not work.

I am using neovim (version 0.3.4) on Windows 10 and Ctrl-N, Ctrl-P right after paste does not work. The message I got is:

Last action was not paste - swap ignored

My setting for yoink is:

    " it seems that ctrl-n and ctrl-p does not work on neovim
    nmap <c-n> <plug>(YoinkPostPasteSwapBack)
    nmap <c-p> <plug>(YoinkPostPasteSwapForward)

    nmap p <plug>(YoinkPaste_p)
    nmap P <plug>(YoinkPaste_P)

    " cycle the yank stack with the following mappings
    nmap [y <plug>(YoinkRotateBack)
    nmap ]y <plug>(YoinkRotateForward)

    " not change the cursor position
    " nmap y <plug>(YoinkYankPreserveCursorPosition)
    " xmap y <plug>(YoinkYankPreserveCursorPosition)

    " move cursor to end of paste after multiline paste
    let g:yoinkMoveCursorToEndOfPaste = 1

    " record yanks in system clipboard
    let g:yoinkSyncSystemClipboardOnFocus = 1

I have also noticed with this plugin enabled, the cursor will be put at the end of the pasted text instead of the first character of the pasted text.

The command verbose nmap p shows:

n p <Plug>(YoinkPaste_p) 
Last set from ~\AppData\Local\nvim\init.vim

Incorrect visual-block selection paste with vim-subversive and vim-yoink

Hello.

Here is a minimal vimrc file (.vimrc.minimal):

set nocompatible

set encoding=utf-8

" vim-yoink
let g:yoinkSyncNumberedRegisters = 1
let g:yoinkIncludeDeleteOperations = 1
let g:yoinkSavePersistently = 0
let g:yoinkMoveCursorToEndOfPaste = 1

filetype off
set runtimepath+=~/.vim/plugins/Vundle.vim
call vundle#begin('~/.vim/plugins/')
Plugin 'svermeulen/vim-cutlass'
Plugin 'svermeulen/vim-yoink'
Plugin 'svermeulen/vim-subversive'
call vundle#end()
filetype on

" vim-cutlass
nnoremap x d
xnoremap x d
nnoremap xx dd
nnoremap X D

" vim-subversive
xmap p <plug>(SubversiveSubstitute)
xmap P <plug>(SubversiveSubstitute)

" vim-yoink
nmap p <plug>(YoinkPaste_p)
nmap P <plug>(YoinkPaste_P)
nmap y <plug>(YoinkYankPreserveCursorPosition)
xmap y <plug>(YoinkYankPreserveCursorPosition)
nmap [y <plug>(YoinkRotateBack)
nmap ]y <plug>(YoinkRotateForward)

Here is a minimal example file (example.txt):

Name Year Value
Bill 2022 1
Sam  2021 0
Bob  2020 2

Steps to reproduce:

  1. vim -u .vimrc.minimal example.txt
  2. Execute in normal mode: wj<Ctrl-V>3j3lygvp

Expected behavior:
File is not visibly changed.

Actual behavior:
File is trashed with incorrect paste.

Additional notes:
Default paste works fine. You can replace the final p with gp to observe it.
Not sure if this issue belongs here or to subversive repo.

vim --version:

VIM - Vi IMproved 9.0 (2022 Jun 28, compiled Sep 01 2022 00:00:00)
Included patches: 1-348
Modified by <[email protected]>
Compiled by <[email protected]>
Huge version with GTK3 GUI.  Features included (+) or not (-):
+acl               +file_in_path      +mouse_urxvt       -tag_any_white
+arabic            +find_in_path      +mouse_xterm       -tcl
+autocmd           +float             +multi_byte        +termguicolors
+autochdir         +folding           +multi_lang        +terminal
-autoservername    -footer            -mzscheme          +terminfo
+balloon_eval      +fork()            +netbeans_intg     +termresponse
+balloon_eval_term +gettext           +num64             +textobjects
+browse            -hangul_input      +packages          +textprop
++builtin_terms    +iconv             +path_extra        +timers
+byte_offset       +insert_expand     +perl/dyn          +title
+channel           +ipv6              +persistent_undo   +toolbar
+cindent           +job               +popupwin          +user_commands
+clientserver      +jumplist          +postscript        +vartabs
+clipboard         +keymap            +printer           +vertsplit
+cmdline_compl     +lambda            +profile           +vim9script
+cmdline_hist      +langmap           -python            +viminfo
+cmdline_info      +libcall           +python3/dyn       +virtualedit
+comments          +linebreak         +quickfix          +visual
+conceal           +lispindent        +reltime           +visualextra
+cryptv            +listcmds          +rightleft         +vreplace
+cscope            +localmap          +ruby/dyn          +wildignore
+cursorbind        +lua/dyn           +scrollbind        +wildmenu
+cursorshape       +menu              +signs             +windows
+dialog_con_gui    +mksession         +smartindent       +writebackup
+diff              +modify_fname      +sodium            +X11
+digraphs          +mouse             +sound             -xfontset
+dnd               +mouseshape        +spell             +xim
-ebcdic            +mouse_dec         +startuptime       +xpm
+emacs_tags        +mouse_gpm         +statusline        +xsmp_interact
+eval              -mouse_jsbterm     -sun_workshop      +xterm_clipboard
+ex_extra          +mouse_netterm     +syntax            -xterm_save
+extra_search      +mouse_sgr         +tag_binary
-farsi             -mouse_sysmouse    -tag_old_static
   system vimrc file: "/etc/vimrc"
     user vimrc file: "$HOME/.vimrc"
 2nd user vimrc file: "~/.vim/vimrc"
      user exrc file: "$HOME/.exrc"
  system gvimrc file: "$VIM/gvimrc"
    user gvimrc file: "$HOME/.gvimrc"
2nd user gvimrc file: "~/.vim/gvimrc"
       defaults file: "$VIMRUNTIME/defaults.vim"
    system menu file: "$VIMRUNTIME/menu.vim"
  fall-back for $VIM: "/usr/share/vim"
Compilation: gcc -c -I. -Iproto -DHAVE_CONFIG_H -DFEAT_GUI_GTK -I/usr/include/gtk-3.0 -I/usr/include/pango-1.0 -I/usr/include/glib-2.0 -I/usr/lib64/glib-2.0/include -I/usr/include/sysprof-4 -I/usr/include/harfbuzz -I/usr/include/freetype2 -I/usr/include/libpng16 -I/usr/include/libmount -I/usr/include/blkid -I/usr/include/fribidi -I/usr/include/libxml2 -I/usr/include/cairo -I/usr/include/pixman-1 -I/usr/include/gdk-pixbuf-2.0 -I/usr/include/gio-unix-2.0 -I/usr/include/cloudproviders -I/usr/include/atk-1.0 -I/usr/include/at-spi2-atk/2.0 -I/usr/include/dbus-1.0 -I/usr/lib64/dbus-1.0/include -I/usr/include/at-spi-2.0 -pthread -O2 -flto=auto -ffat-lto-objects -fexceptions -g -grecord-gcc-switches -pipe -Wall -Werror=format-security -Wp,-D_GLIBCXX_ASSERTIONS -specs=/usr/lib/rpm/redhat/redhat-hardened-cc1 -fstack-protector-strong -specs=/usr/lib/rpm/redhat/redhat-annobin-cc1 -m64 -mtune=generic -fasynchronous-unwind-tables -fstack-clash-protection -fcf-protection -D_GNU_SOURCE -D_FILE_OFFSET_BITS=64 -DSYS_VIMRC_FILE=/etc/vimrc -D_REENTRANT -U_FORTIFY_SOURCE -D_FORTIFY_SOURCE=1
Linking: gcc -L. -Wl,-z,relro -Wl,--as-needed -Wl,-z,now -specs=/usr/lib/rpm/redhat/redhat-hardened-ld -specs=/usr/lib/rpm/redhat/redhat-annobin-cc1 -Wl,--build-id=sha1 -fstack-protector-strong -rdynamic -Wl,-export-dynamic -Wl,--no-as-needed -Wl,--enable-new-dtags -Wl,-z,relro -Wl,--as-needed -Wl,-z,now -specs=/usr/lib/rpm/redhat/redhat-hardened-ld -specs=/usr/lib/rpm/redhat/redhat-annobin-cc1 -Wl,--build-id=sha1 -Wl,-z,relro -Wl,--as-needed -Wl,-z,now -specs=/usr/lib/rpm/redhat/redhat-hardened-ld -specs=/usr/lib/rpm/redhat/redhat-annobin-cc1 -Wl,--build-id=sha1 -Wl,-dT,/builddir/build/BUILD/vim90/.package_note-vim-9.0.348-1.fc36.x86_64.ld -L/usr/local/lib -o vim -lgtk-3 -lgdk-3 -lz -lpangocairo-1.0 -lpango-1.0 -lharfbuzz -latk-1.0 -lcairo-gobject -lcairo -lgdk_pixbuf-2.0 -lgio-2.0 -lgobject-2.0 -lglib-2.0 -lSM -lICE -lXpm -lXt -lX11 -lSM -lICE -lm -lselinux -lncurses -lcanberra -lsodium -lacl -lattr -lgpm -Wl,--enable-new-dtags -Wl,-z,relro -Wl,--as-needed -Wl,-z,now -specs=/usr/lib/rpm/redhat/redhat-hardened-ld -specs=/usr/lib/rpm/redhat/redhat-annobin-cc1 -Wl,--build-id=sha1 -Wl,-z,relro -Wl,--as-needed -Wl,-z,now -specs=/usr/lib/rpm/redhat/redhat-hardened-ld -specs=/usr/lib/rpm/redhat/redhat-annobin-cc1 -Wl,--build-id=sha1 -fstack-protector-strong -L/usr/local/lib -L/usr/lib64/perl5/CORE -lperl -lpthread -lresolv -ldl -lm -lcrypt -lutil -lc

yoink#isSwapping returns 0 after YoinkPaste_p

I wanted to spend only one map on this plugin, so I mapped:

    nmap <expr> <leader>p yoink#isSwapping() ? '<plug>(YoinkPostPasteSwapForward)' : '<plug>(YoinkPaste_p)'
    nmap <expr> <leader>P yoink#isSwapping() ? '<plug>(YoinkPostPasteSwapBack)' : '<plug>(YoinkPaste_P)'

However, this only ever pastes, it doesn't swap. Manually calling isSwapping echos 0.

Neovim 4.3

Conflict with tpope's vim-surround

I'm finding that there's some conflict with tpope's vim-surround plugin. I migrated to this from vim-easyclip, so that I could save my cuts to the yank ring with the option yoinkIncludeDeleteOperations which is not in easyclip. Easyclip didn't have any issues with vim-surround, but since migrating to yoink the change surround cs function is not working correctly.

given:

function () {
    thing*
    other thing
}

where * is my cursor, when I type cs{(, I'd expect tpope's surround plugin to give me:

function () ( thing
        other thing
        )

which it does, when yoink's let g:yoinkIncludeDeleteOperations = 0. If it is = 1 then it gives me:

function () 
    (
     {
     }
    )

(or sometimes even whatever is in the clipboard appears in the middle).

Feature request: `gp` and `gP`

Is it possible to add gp and gP shortcuts to Yoink? These commands in Vim put cursor after the pasted item. Currently doing gp followed by [p (YoinkPostPasteSwapBack) results in "Last action was not paste — swap ignored".

Persistence history

It'd be nice if the history could persist in new sessions of vim. If you don't have any plans for it I can work on it.

Slow deletion with global command even though `g:yoinkIncludeDeleteOperations=0`

Steps to reproduce:

  1. Open a large file with tons of lines.
  2. Search for some pattern.
  3. Execute :g!//d (or :g//d)

I never set g:yoinkIncludeDeleteOperations to 1 (and echoing it says its value is 0), and I loaded a file with 2605423 lines.
I copied the entire content of the file to a new unnamed buffer and executed the global command, which deleted 2515135 lines.
The following is the result of the profiling.

FUNCTION  yoink#onYank()
    Defined: ~/nonos/dotfiles-private/nvim/plugged/vim-yoink/autoload/yoink.vim line 478
Called 2515136 times
Total time: 109.557102
 Self time: 109.557102

count  total (s)   self (s)
2515136             10.853081     if (a:ev.operator == 'y' || g:yoinkIncludeDeleteOperations)
                            
                                    let isDefaultRegister = a:ev.regname == '' || a:ev.regname == yoink#getDefaultReg()
                            
                                    if isDefaultRegister || g:yoinkIncludeNamedRegisters
                            
                                        " We don't use a:ev.regcontents because it's a list of lines and not the raw text
                                        " The raw text is needed when comparing getDefaultYankInfo in a few places
                                        " above
                                        let entry = { 'text': getreg(a:ev.regname), 'type': a:ev.regtype }
                            
                                        " We add an offset for named registers so that the default register is always at 
                                        " index 0 in the yank history
                                        call s:addToHistory(entry, isDefaultRegister ? 0 : 1)
                                    endif
2515136              2.070463     end
                            
2515136              9.740949     if (a:ev.operator == 'y' && len(s:yankStartCursorPos) > 0)
                                    call setpos('.', s:yankStartCursorPos)
                                    call winrestview(s:yankStartWinView)
                                    call s:clearYankStartData()
2515136              2.178040     endif

Since g:yoinkIncludeDeleteOperations=0, it doesn't look like the deleted lines are stored in the yank history.
But the slowdown is too much and I hope this could be fixed ;)

clipboard: error -2

Sometimes I start my neovim, this error occurs:

" || clipboard: error -2
" || Error detected while processing function
" autoload/yoink.vim|438| yoink#onVimEnter[1]
" autoload/yoink.vim|354| yoink#addCurrentDefaultRegToHistory[2]
" autoload/yoink.vim|374| yoink#getDefaultYankInfo[1]
" autoload/yoink.vim|386| yoink#getYankInfoForReg[1]
" /usr/share/nvim/runtime/autoload/provider/clipboard.vim|234| provider#clipboard#Call[6]
" /usr/share/nvim/runtime/autoload/provider/clipboard.vim|161| 49[8]
" || E691: Can only compare List with List
" || Error detected while processing function
" autoload/yoink.vim|438| yoink#onVimEnter[1]
" autoload/yoink.vim|354| yoink#addCurrentDefaultRegToHistory[2]
" autoload/yoink.vim|374| yoink#getDefaultYankInfo[1]
" autoload/yoink.vim|386| yoink#getYankInfoForReg[1]
" /usr/share/nvim/runtime/autoload/provider/clipboard.vim|234| provider#clipboard#Call[6]
" /usr/share/nvim/runtime/autoload/provider/clipboard.vim|161| 49[8]
" || E15: Invalid expression: match(&clipboard, '\v(unnamed|unnamedplus)') >= 0 && get(s:selections[a:reg].data, 0, []) == clipboard_data
" || Error detected while processing function
" autoload/yoink.vim|438| yoink#onVimEnter[1]
" autoload/yoink.vim|354| yoink#addCurrentDefaultRegToHistory[2]
" autoload/yoink.vim|374| yoink#getDefaultYankInfo[1]
" autoload/yoink.vim|386| yoink#getYankInfoForReg[1]
" || clipboard: provider returned invalid data

The error sometimes occur, So I have not found any regular pattern, reason or any method to reproduce it. I have to disable this autocmd to avoid it.

I use neovim 0.5.0 on linux 5.13.13.

Any advice which can help me find the reason is thankful.

Detected both cutlass and yoink installed - however g:yoinkIncludeDeleteOperations is set to 0.

Hi!

I seem to be somewhat confused. Long story short, It seems like g:yoinkSyncNumberedRegisters negates effect of g:yoinkIncludeDeleteOperations, which in turn leads to Detected both cutlass and yoink installed - however g:yoinkIncludeDeleteOperations is set to 0. error.

I have cutlas with yoink installed alongside, with this config:

"map yank "ring" to [p ]p
nmap [p <plug>(YoinkPostPasteSwapBack)
nmap ]p <plug>(YoinkPostPasteSwapForward)
nmap p <plug>(YoinkPaste_p)
nmap P <plug>(YoinkPaste_P)

let g:yoinkIncludeDeleteOperations = 0
let g:yoinkSyncNumberedRegisters = 1

"map x to 'cut'
nnoremap x d
xnoremap x d
nnoremap xx dd
nnoremap X D

I.e., I expect only x and y to go into yank history. This config seems to work, but throws error .

Testing scenario:

a
b
c
d

Sequence normal ggyyjyyjyyjxx<Esc>:reg.

Expected result: d in 1 and " register.

Actual:

let g:yoinkIncludeDeleteOperations = 0
let g:yoinkSyncNumberedRegisters = 1
  l  ""   d^J
  l  "0   c^J
  l  "1   d^J
  l  "2   b^J
let g:yoinkIncludeDeleteOperations = 1
let g:yoinkSyncNumberedRegisters = 1
  l  ""   c^J
  l  "0   c^J
  l  "1   c^J
  l  "2   b^J
  l  "3   a^J
let g:yoinkIncludeDeleteOperations = 1
let g:yoinkSyncNumberedRegisters = 0
  l  ""   d^J
  l  "0   c^J
  l  "1   d^J
  l  "2   c^J

I.e., the first (and the only one) of the three configs seemsto yield requested behaviour, yet refuses to start without an error.

Question is: am I missing something? If this is expected behaviour, how do I make the error go away properly? (I mean, yeah, I have removed the lines from the plugin, but that is not very persistent. I can also fork the repo and redirect the PlugInstall, but that does not sound right either.)

History in Coc autocomplete

I want the yank history in the autocomplete list

Not sure how difficult it is to add Coc, but thought I would create an issue to see.

[feature] filter the content to save persistently

I notice if save too many lines (>500) and enable save persistently, the neovim seem to be a little slow. Can we have a variable to determine a threshold, when the number of line is greater than the threshold, don't save it persistently?

Thanks!

Popup

First of all, thanks for this very useful plugin. I've been using it and it seems to be doing exactly what it claims to do. I just wonder if it's possible to have an option that enables a popup that shows the list of yanks in the text area immediately after you paste.

PS: I'm using coc.vim for autocomplete.

Idententtaion not honoured while copying.

map <C-p> o <ESC>"+P
nmap P <plug>(YoinkPaste_P)

I have this in ~/.vimrc to copy from system clipboard directly, but indentation is not correct whilst using Yoink i.e. mapping P in this case.

Repeat paste broken

When this plugin is active you are unable to paste a yanked section of text multiple times.
For example:

" 'yy' to yank below line
line to copy

" '5p' to paste this line 5 times

" actual output
line to copy

" expected output
line to copy
line to copy
line to copy
line to copy
line to copy

Here is a minimal vimrc I used for testing:

set nocompatible
call plug#begin('~/.vim/plugged')
Plug 'svermeulen/vim-yoink'
call plug#end()
let g:yoinkIncludeDeleteOperations = 1
nmap <c-n> <plug>(YoinkPostPasteSwapBack)
nmap <c-p> <plug>(YoinkPostPasteSwapForward)
nmap p <plug>(YoinkPaste_p)
nmap P <plug>(YoinkPaste_P)
let g:yoinkSwapClampAtEnds = 0
nmap [y <plug>(YoinkRotateBack)
nmap ]y <plug>(YoinkRotateForward)

Is this something that can be fixed?

Thanks

bug: Cannot directly paste after delete.

When I type command dp, only delete action works but paste action doesn't.
It since the v:register change to _ after the d action. Maybe, the code I found in easyclip should be added:

if reg ==# '_'
  let reg = EasyClip#GetDefaultReg()
end

Mapping `p` is causing delay, is there any way to fix this?

nmap p <plug>(YoinkPaste_p)

  • I've checked and I don't have any other mappings beginning with 'p'.
  • Normally p will paste instantaneously
  • Adding the above mapping causes a delay to occur
  • If I map YoinkPaste_p to pp or anything else, there is no delay.

Does anyone else experience this issue, and is there a way to fix it?

❯ nvim -v
NVIM v0.4.2
Build type: Release
LuaJIT 2.0.5
Compilation: /usr/local/Homebrew/Library/Homebrew/shims/mac/super/clang -U_FORTIFY_SOURCE -D_FORTIFY_SOURCE=1 -DNDEBUG -DMIN_LOG_LEVEL=3 -Wall -Wextra -pedantic -Wno-unused-parameter -Wstrict-prototypes -std=gnu99 -Wshadow -Wconversion -Wmissing-prototypes -Wimplicit-fallthrough -Wvla -fstack-protector-strong -fdiagnostics-color=auto -DINCLUDE_GENERATED_DECLARATIONS -D_GNU_SOURCE -DNVIM_MSGPACK_HAS_FLOAT32 -DNVIM_UNIBI_HAS_VAR_FROM -I/tmp/neovim-20190916-88369-176iaxs/neovim-0.4.2/build/config -I/tmp/neovim-20190916-88369-176iaxs/neovim-0.4.2/src -I/usr/local/include -I/tmp/neovim-20190916-88369-176iaxs/neovim-0.4.2/deps-build/include -I/usr/local/opt/gettext/include -I/Applications/Xcode.app/Contents/Developer/Platforms/MacOSX.platform/Developer/SDKs/MacOSX10.14.sdk/usr/include -I/tmp/neovim-20190916-88369-176iaxs/neovim-0.4.2/build/src/nvim/auto -I/tmp/neovim-20190916-88369-176iaxs/neovim-0.4.2/build/include
Compiled by [email protected]

Features: +acl +iconv +tui
See ":help feature-compile"

   system vimrc file: "$VIM/sysinit.vim"
  fall-back for $VIM: "/usr/local/Cellar/neovim/0.4.2/share/nvim"

Run :checkhealth for more info
 337   │ FUNCTION  yoink#paste()
 338   │     Defined: ~/.dotfiles/.config/nvim/plugged/vim-yoink/autoload/yoink.vim line 134
 339   │ Called 1 time
 340   │ Total time:   0.000537
 341   │  Self time:   0.000440
 342   │
 343   │ count  total (s)   self (s)
 344   │     1              0.000013     let previousPosition = getpos('.')
 345   │     1              0.000307     exec "normal! \"" . s:currentPasteRegister . s:cnt . s:currentPasteType
 346   │
 347   │     1   0.000140   0.000052     call yoink#adjustLastChangeIfNecessary()
 348   │
 349   │     1              0.000004     if g:yoinkMoveCursorToEndOfPaste
 350   │                                     let newPosition = getpos('.')
 351   │                                     if abs(newPosition[1] - previousPosition[1]) > 1
 352   │                                         " Only add to the jump list if the paste moved the cursor more than 1 line
 353   │                                         call setpos('.', previousPosition)
 354   │                                         normal! m`
 355   │                                         call setpos('.', newPosition)
 356   │                                     endif
 357   │     1              0.000001     endif
 358   │
 359   │     1   0.000034   0.000025     call yoink#startUndoRepeatSwap()

addToHistory doesn't handle empty history properly resulting in E684, E727, E714

Hello.

Consider the following situation:

  1. Empty history of yanks, i.e. s:history is []
  2. Non-empty text gets yanked into a non-default register
  3. let g:yoinkSyncNumberedRegisters = 1 let g:yoinkIncludeDeleteOperations = 1

This results in multiple errors that happen as follows:

  1. yoink#onYank inside the first if clause calls addToHistory with the second parameter 1.
  2. addToHistory defines offset to be 1 and history to be []
  3. addToHistory doesn't do anything with empty list inside a for loop
  4. addToHistory tries to insert into an empty list before the first position resulting in E684.
    For example, try :call insert([], 'a', 1)
  5. Now onHistoryChanged comes into play. First it calls range(1, -1), which throws E727, then it tries to iterate over 0, which throws E714.

Here's a debugging patch I've used:

diff --git a/autoload/yoink.vim b/autoload/yoink.vim
index 337cf92..9ca0fec 100644
--- a/autoload/yoink.vim
+++ b/autoload/yoink.vim
@@ -184,7 +184,7 @@ function! yoink#postPasteToggleFormat()
endfunction
function s:isCloseEnoughChangeTick(tick)
-    return abs(b:changedtick - a:tick) <= g:yoinkChangeTickThreshold
+    return abs(b:changedtick - a:tick) <= g:yoinkChangeTickThreshold
endfunction
function! s:tryStartSwap()
@@ -274,6 +274,7 @@ function! s:onHistoryChanged()
if g:yoinkSyncNumberedRegisters
let history = yoink#getYankHistory()
+        echom "history length is " len(history) " range is " range(1, min([len(history) - 1, 9]))
" We skip the first one because it's assumed that's set to the default register
" already (or failing that, the '0' register)
for i in range(1, min([len(history) - 1, 9]))
@@ -310,7 +311,9 @@ function! s:addToHistory(entry, ...)
endif
endfor
+        echom "history before insert: " history
call insert(history, a:entry, offset)
+        echom "history after insert: " history
if len(history) > g:yoinkMaxItems
call remove(history, g:yoinkMaxItems, -1)
endif
@@ -493,8 +496,9 @@ function! yoink#onYank(ev) abort
" above
let entry = { 'text': getreg(a:ev.regname), 'type': a:ev.regtype }
-            " We add an offset for named registers so that the default register is always at
+            " We add an offset for named registers so that the default register is always at
" index 0 in the yank history
+            echom entry " " isDefaultRegister
call s:addToHistory(entry, isDefaultRegister ? 0 : 1)
endif
end

Here's a message log from a real-life situation where this problem has occurred:

Messages maintainer: Mike Williams <[email protected]>
1 more line; before #758  1 second ago
1 change; before #759  3 seconds ago
1 more line; before #757  14:21:41
1 line less; after #757  14:21:41
{'type': 'V', 'text': '    Suppose $i \in \overline{0,q-1}$, $k \in \overline{0,m}$. Then monomials $x^{i\pi^k}$ and $x^{\Sk{k}(i)}$^@'}   0
history before insert:  []
Error detected while processing function yoink#onYank[15]..<SNR>168_addToHistory:
line   17:
E684: List index out of range: 1
history after insert:  []
Error detected while processing function yoink#onYank[15]..<SNR>168_addToHistory[22]..<SNR>168_onHistoryChanged:
line    4:
E727: Start past end
history length is  0  range is  0
Error detected while processing function yoink#onYank[15]..<SNR>168_addToHistory[22]..<SNR>168_onHistoryChanged:
line    7:
E727: Start past end
Error detected while processing function yoink#onYank[15]..<SNR>168_addToHistory[22]..<SNR>168_onHistoryChanged:
line    7:
E714: List required
{'type': 'V', 'text': '    Suppose $i \in \overline{0,q-1}$, $k \in \overline{0,m}$. Then monomials $x^{i\pi^k}$ and $x^{\Sk{k}(i)}$^@'}   1
history before insert:  []
history after insert:  [{'type': 'V', 'text': '    Suppose $i \in \overline{0,q-1}$, $k \in \overline{0,m}$. Then monomials $x^{i\pi^k}$ and $x^{\Sk{k}(i)}$^@'}]
history length is  1  range is  []

The problem occurs from time to time mostly with tex files. I use vimtex for tex files.
I don't know how to reproduce it consistently. However, there are obvious problems with handling
the corner case of an empty list in several places. I'd say we should fix those and this problem will
most likely be fixed along the way.

Proposed patch (unable to do a PR right now):

diff --git a/autoload/yoink.vim b/autoload/yoink.vim
index 337cf92..90f2903 100644
--- a/autoload/yoink.vim
+++ b/autoload/yoink.vim
@@ -295,8 +295,8 @@ function! yoink#addTextToHistory(text, ...)
endfunction
function! s:addToHistory(entry, ...)
-    let offset = a:0 ? a:1 : 0
let history = yoink#getYankHistory()
+    let offset = (a:0 && !empty(history)) ? a:1 : 0
if !empty(a:entry.text) && (empty(history) || (a:entry != history[0]))
" Remove it if it is already added somewhere in the history

[Question] How paste registers from delete actions

Hello, I'm having a hard time using the x register. Whenever I cut something with x, and then try to paste with p/P --each mapped as suggested nmap p <plug>(YoinkPaste_p)-- I don't get the cutted text pasted. I have to swap along the yanks. Is it there a way yo make the cuts to be stored in the first register that Yoink uses when pasting?

Thanks in advance

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.