maxbrunsfeld / vim-yankstack

A lightweight implementation of emacs's kill-ring for vim
437 stars 29 forks source link

Insert mode mappings #10

Closed mMontu closed 12 years ago

mMontu commented 12 years ago

The insert mode mappings to cycle between pastes aren't working on my machine. I defined them as described on the help file:

imap <a-p> <Plug>yankstack_insert_mode_paste imap <a-y> <Plug>yankstack_substitute_older_paste imap <a-Y> <Plug>yankstack_substitute_newer_paste

I'm able to paste with , but <a-y> or <a-Y> are silent ignored.

Did I miss something?

maxbrunsfeld commented 12 years ago

Nope, you're right. This is a bug. Thanks!

mMontu commented 12 years ago

If this is going to be changed, I'd suggest a slight modification: a single mapping for both yankstack_insert_mode_paste and yankstack_substitute_older_paste. Then calling this mapping without any previous paste would yield the behavior of yankstack_insert_mode_paste, and after pasting it would behave as yankstack_substitute_older_paste. Then it would be possible to use the same two mappings of normal mode in insert mode.

Thanks for sharing this awesome plugin!

maxbrunsfeld commented 12 years ago

I'm finally getting around to fixing this, and I think I'm going to take your suggestion. I also think I'm going to do the same thing in normal and visual modes. So if you type alt-p and you haven't previously pasted, it will paste. Similarly, if you type alt-shift-p without pasting beforehand, it will paste with shift-p. Otherwise, (if you have already just pasted) those keys will cycle back and forth through the yankstack as usual. What do you think of that behavior?

mMontu commented 12 years ago

I think it will be very nice!!

maxbrunsfeld commented 12 years ago

Ok, I've changed the behavior of the key bindings in the way that we talked about. There are still some issues I need to work out regarding how the cursor is placed after doing a multi-line paste in insert mode using alt-p or alt-shift-p. Also, if you haven't already pasted, alt-p and alt-shift-p both do the same thing: the same as pasting with p (I take back what I said above about alt-shift-p behaving like shift-p, since I found that too complicated and unnecessary).

Let me know how this works for you when you get the chance!

mMontu commented 12 years ago

I've tested it a little and it works fine for when yanking entire lines. But it seems that there are some issues when yanking a few words. This is a case that shows problem:

1 - Open a new buffer and copy the first paragraph of :h yankstack-introduction 2 - Yank the following text on second line: "implementation of the Emacs 'kill ring'" 3 - :Yanks shows that text was correctly yanked 4 - Move before the last word, "paste.", and type i<a-p>. Instead of "implementation of the Emacs 'kill ring' paste." the text changes to "pimplementation of the Emacs 'kill ring'aste.", as it started with cursor one column to the left.

While writing this test case I noticed a different problem, which may be related to some configuration/plugins on my machine: 1 - Open gVim 2 - :h yankstack-introduction 3 - <cr><cr>y] - move to the start of paragraph and copy it 4 - <c-w>kP - move to empty buffer and paste the paragraph 5 - jwvt';y 6 - :Yanks (check the text copied as before) 7 - /paste<cr> 8 - i<a-p> -> instead of pasting the text, cursor moves to the start of first line, and no other change is done. 9 - ni<a-p> -> moving back to paste and trying again replaces the entire paragraph with the last yank 10 - performing some other edits on the buffer changes the behavior to the problem first described (paste starting one column to the left).

If you don't see this behavior I can try to disable plugins/features until I find the configuration/plugin that causes the interference.

maxbrunsfeld commented 12 years ago

I don't think the second problem is just your machine. I think it's because your last change to the buffer was a paste, so when you type alt-p, yankstack tries to replace your last paste with an older paste, rather than doing a new paste.

So it has to do with the dual purpose of alt-p. Maybe I should not just be checking based on the last change to the buffer, but also the mode you were in when you last pasted. If you're in a different mode than you were when you last pasted, and you type alt-p, you should do a new paste, not substitute an older one.

I think I'm going to try adding that. Also, I've reproduced the first problem you mentioned above. Working on it. Thanks!

mMontu commented 12 years ago

Yes, I think you are righ about the second problemt. The outputs on steps 8 and 9 indeed matches the :Yanks contents.

Thank you very much for making yankstack even better!

maxbrunsfeld commented 12 years ago

@mMontu, I believed I've fixed the remaining bugs. I'm curious how it works for you. Thanks for your suggestion about about the key bindings!

mMontu commented 12 years ago

It works fine in insert mode! But it seems to have changed on normal mode:

1- perform the four steps above to paste some code before the end of paragraph ("... paste.") 2 - <Esc>j - go back to normal mode and down one line 3 - p<a-p> - instead of paste and cycle on yanks history, it is pasting twice

After performing some tests with <a-p> and <a-P> on insert mode, I moved to normal mode I found myself trying to paste with <a-p> and <a-P> instead of p and P, but both <a-p> and <a-P> works like p when there is no previous paste. I think it would be nice if in this case <a-P> maps to P.

Thanks!

mMontu commented 12 years ago

I just remembered that you said you tried to make <a-P> to shift-p but decided to left it behaving as p. Please, just ignore what I said at the end of the last comment. Sorry for bothering you.

maxbrunsfeld commented 12 years ago

So in normal mode, when you paste with p and then attempt to cycle through pastes with alt-p, you see a second paste? I haven't been able to reproduce this yet. Thanks for doing this testing.

mMontu commented 12 years ago

Yes, it triggers a second paste. But if I type alt-p twice I see a paste and then a cycle through pastes. I've just found that this happen always, therefore it is not needed to follow those steps, just opening gVim, typing some text, yanking and issuing p followed by alt-p causes a second paste.

I've tried a fresh installation of ms-windows gVim, with ~/_vimrc (equivalent of ~/.vimrc) containing only call yankstack#setup() and ~/vimfiles (equivalent of ~/.vim) containing only yankstack files and the problem still happens. For the moment I can't on any different OS, but maybe the problem only occurs on ms-windows.

Thanks for your time and effort!

maxbrunsfeld commented 12 years ago

Ok @mMontu, I'm going to close this issue and open a new issue (#13) for the bug you're describing on windows.