mirror of
https://github.com/amix/vimrc
synced 2025-06-16 01:25:00 +08:00
Added yankstack, a replacement for YankRing
This commit is contained in:
115
sources_non_forked/vim-yankstack/spec/fixtures/repeat.vim
vendored
Normal file
115
sources_non_forked/vim-yankstack/spec/fixtures/repeat.vim
vendored
Normal file
@ -0,0 +1,115 @@
|
||||
" repeat.vim - Let the repeat command repeat plugin maps
|
||||
" Maintainer: Tim Pope
|
||||
" Version: 1.1
|
||||
" GetLatestVimScripts: 2136 1 :AutoInstall: repeat.vim
|
||||
|
||||
" Installation:
|
||||
" Place in either ~/.vim/plugin/repeat.vim (to load at start up) or
|
||||
" ~/.vim/autoload/repeat.vim (to load automatically as needed).
|
||||
"
|
||||
" License:
|
||||
" Copyright (c) Tim Pope. Distributed under the same terms as Vim itself.
|
||||
" See :help license
|
||||
"
|
||||
" Developers:
|
||||
" Basic usage is as follows:
|
||||
"
|
||||
" silent! call repeat#set("\<Plug>MappingToRepeatCommand",3)
|
||||
"
|
||||
" The first argument is the mapping that will be invoked when the |.| key is
|
||||
" pressed. Typically, it will be the same as the mapping the user invoked.
|
||||
" This sequence will be stuffed into the input queue literally. Thus you must
|
||||
" encode special keys by prefixing them with a backslash inside double quotes.
|
||||
"
|
||||
" The second argument is the default count. This is the number that will be
|
||||
" prefixed to the mapping if no explicit numeric argument was given. The
|
||||
" value of the v:count variable is usually correct and it will be used if the
|
||||
" second parameter is omitted. If your mapping doesn't accept a numeric
|
||||
" argument and you never want to receive one, pass a value of -1.
|
||||
"
|
||||
" Make sure to call the repeat#set function _after_ making changes to the
|
||||
" file.
|
||||
"
|
||||
" For mappings that use a register and want the same register used on
|
||||
" repetition, use:
|
||||
"
|
||||
" silent! call repeat#setreg("\<Plug>MappingToRepeatCommand", v:register)
|
||||
"
|
||||
" This function can (and probably needs to be) called before making changes to
|
||||
" the file (as those typically clear v:register). Therefore, the call sequence
|
||||
" in your mapping will look like this:
|
||||
"
|
||||
" nnoremap <silent> <Plug>MyMap
|
||||
" \ :<C-U>execute 'silent! call repeat#setreg("\<lt>Plug>MyMap", v:register)'<Bar>
|
||||
" \ call <SID>MyFunction(v:register, ...)<Bar>
|
||||
" \ silent! call repeat#set("\<lt>Plug>MyMap")<CR>
|
||||
|
||||
if exists("g:loaded_repeat") || &cp || v:version < 700
|
||||
finish
|
||||
endif
|
||||
let g:loaded_repeat = 1
|
||||
|
||||
let g:repeat_tick = -1
|
||||
let g:repeat_reg = ['', '']
|
||||
|
||||
" Special function to avoid spurious repeats in a related, naturally repeating
|
||||
" mapping when your repeatable mapping doesn't increase b:changedtick.
|
||||
function! repeat#invalidate()
|
||||
let g:repeat_tick = -1
|
||||
endfunction
|
||||
|
||||
function! repeat#set(sequence,...)
|
||||
let g:repeat_sequence = a:sequence
|
||||
let g:repeat_count = a:0 ? a:1 : v:count
|
||||
let g:repeat_tick = b:changedtick
|
||||
endfunction
|
||||
|
||||
function! repeat#setreg(sequence,register)
|
||||
let g:repeat_reg = [a:sequence, a:register]
|
||||
endfunction
|
||||
|
||||
function! repeat#run(count)
|
||||
if g:repeat_tick == b:changedtick
|
||||
let r = ''
|
||||
if g:repeat_reg[0] ==# g:repeat_sequence && !empty(g:repeat_reg[1])
|
||||
if g:repeat_reg[1] ==# '='
|
||||
" This causes a re-evaluation of the expression on repeat, which
|
||||
" is what we want.
|
||||
let r = '"=' . getreg('=', 1) . "\<CR>"
|
||||
else
|
||||
let r = '"' . g:repeat_reg[1]
|
||||
endif
|
||||
endif
|
||||
|
||||
let c = g:repeat_count
|
||||
let s = g:repeat_sequence
|
||||
let cnt = c == -1 ? "" : (a:count ? a:count : (c ? c : ''))
|
||||
call feedkeys(r . cnt, 'n')
|
||||
call feedkeys(s)
|
||||
else
|
||||
call feedkeys((a:count ? a:count : '') . '.', 'n')
|
||||
endif
|
||||
endfunction
|
||||
|
||||
function! repeat#wrap(command,count)
|
||||
let preserve = (g:repeat_tick == b:changedtick)
|
||||
exe 'norm! '.(a:count ? a:count : '').a:command . (&foldopen =~# 'undo' ? 'zv' : '')
|
||||
if preserve
|
||||
let g:repeat_tick = b:changedtick
|
||||
endif
|
||||
endfunction
|
||||
|
||||
nnoremap <silent> . :<C-U>call repeat#run(v:count)<CR>
|
||||
nnoremap <silent> u :<C-U>call repeat#wrap('u',v:count)<CR>
|
||||
if maparg('U','n') ==# ''
|
||||
nnoremap <silent> U :<C-U>call repeat#wrap('U',v:count)<CR>
|
||||
endif
|
||||
nnoremap <silent> <C-R> :<C-U>call repeat#wrap("\<Lt>C-R>",v:count)<CR>
|
||||
|
||||
augroup repeatPlugin
|
||||
autocmd!
|
||||
autocmd BufLeave,BufWritePre,BufReadPre * let g:repeat_tick = (g:repeat_tick == b:changedtick || g:repeat_tick == 0) ? 0 : -1
|
||||
autocmd BufEnter,BufWritePost * if g:repeat_tick == 0|let g:repeat_tick = b:changedtick|endif
|
||||
augroup END
|
||||
|
||||
" vim:set ft=vim et sw=4 sts=4:
|
9
sources_non_forked/vim-yankstack/spec/spec_helper.rb
Normal file
9
sources_non_forked/vim-yankstack/spec/spec_helper.rb
Normal file
@ -0,0 +1,9 @@
|
||||
require "vimbot"
|
||||
|
||||
PLUGIN_ROOT = File.expand_path("../..", __FILE__)
|
||||
VIM_REPEAT_PATH = File.expand_path("spec/fixtures/repeat.vim", PLUGIN_ROOT)
|
||||
|
||||
RSpec.configure do |c|
|
||||
c.alias_it_should_behave_like_to :it_has_behavior, 'has behavior:'
|
||||
end
|
||||
|
@ -0,0 +1,343 @@
|
||||
require "spec_helper"
|
||||
|
||||
describe "Yankstack" do
|
||||
let(:vim) { Vimbot::Driver.new }
|
||||
|
||||
before(:all) do
|
||||
vim.start
|
||||
|
||||
vim.set "visualbell"
|
||||
vim.set "noerrorbells"
|
||||
vim.set "macmeta"
|
||||
|
||||
vim.set "runtimepath+=#{PLUGIN_ROOT}"
|
||||
vim.runtime "plugin/yankstack.vim"
|
||||
|
||||
vim.source VIM_REPEAT_PATH
|
||||
end
|
||||
|
||||
after(:all) { vim.stop }
|
||||
before(:each) { vim.clear_buffer }
|
||||
|
||||
shared_examples "yanking and pasting" do
|
||||
let(:yank_keys) { "yw" }
|
||||
|
||||
before do
|
||||
vim.insert "first_line<CR>", "second_line<CR>", "third_line<CR>", "fourth_line"
|
||||
vim.normal "gg"
|
||||
vim.normal yank_keys, 'j', yank_keys, 'j', yank_keys, 'j', yank_keys
|
||||
end
|
||||
|
||||
it "pushes every yanked string to the :Yanks stack" do
|
||||
yank_entries[0].should match /0\s+fourth_line/
|
||||
yank_entries[1].should match /1\s+third_line/
|
||||
yank_entries[2].should match /2\s+second_line/
|
||||
yank_entries[3].should match /3\s+first_line/
|
||||
end
|
||||
|
||||
describe "yanking with different keys" do
|
||||
before do
|
||||
vim.normal "A", "<CR>", "line to delete", "<Esc>", "^"
|
||||
end
|
||||
|
||||
keys_that_change_register = [
|
||||
'cc', 'C',
|
||||
'dd', 'D',
|
||||
's', 'S',
|
||||
'x', 'X',
|
||||
'yy', 'Y'
|
||||
]
|
||||
|
||||
keys_that_change_register.each do |key|
|
||||
it "pushes to the stack when deleting text with '#{key}'" do
|
||||
vim.normal key
|
||||
yank_entries[1].should match /1\s+fourth_line/
|
||||
end
|
||||
end
|
||||
|
||||
it "pushes to the stack when overwriting text in select mode" do
|
||||
vim.type "V"
|
||||
vim.type "<c-g>", "this overwrites the last line"
|
||||
yank_entries[0].should include "line to delete"
|
||||
yank_entries[1].should include "fourth_line"
|
||||
end
|
||||
end
|
||||
|
||||
context "in normal mode" do
|
||||
before { vim.normal "o", "<Esc>" }
|
||||
|
||||
describe "pasting a string with 'p'" do
|
||||
before { vim.normal "p" }
|
||||
|
||||
it "pastes the most recently yanked string" do
|
||||
vim.line_number.should == 5
|
||||
vim.line.should == "fourth_line"
|
||||
end
|
||||
|
||||
describe "pressing the repeat key with '.'" do
|
||||
it "pastes again" do
|
||||
pending unless File.exists?(VIM_REPEAT_PATH)
|
||||
|
||||
vim.type "."
|
||||
vim.line.should == "fourth_linefourth_line"
|
||||
end
|
||||
end
|
||||
|
||||
describe "typing the 'cycle paste' key" do
|
||||
before { vim.normal "<M-p>" }
|
||||
|
||||
it "replaces the pasted string with the previously yanked text" do
|
||||
vim.line.should == "third_line"
|
||||
end
|
||||
|
||||
it "rotates the previously yanked text to the top of the yank stack" do
|
||||
yank_entries[0].should include 'third_line'
|
||||
yank_entries[1].should include 'second_line'
|
||||
yank_entries[2].should include 'first_line'
|
||||
yank_entries[-1].should include 'fourth_line'
|
||||
end
|
||||
|
||||
it "rotates through the yanks when pressed multiple times" do
|
||||
vim.normal "<M-p>"
|
||||
vim.line.should == "second_line"
|
||||
vim.normal "<M-p>"
|
||||
vim.line.should == "first_line"
|
||||
|
||||
vim.normal "<M-P>"
|
||||
vim.line.should == "second_line"
|
||||
vim.normal "<M-P>"
|
||||
vim.line.should == "third_line"
|
||||
vim.normal "<M-P>"
|
||||
vim.line.should == "fourth_line"
|
||||
end
|
||||
end
|
||||
end
|
||||
|
||||
describe "typing the `substitute_older_paste` key without pasting first" do
|
||||
before { vim.type "<M-p>" }
|
||||
|
||||
it "pastes the most recently yanked string" do
|
||||
vim.line_number.should == 5
|
||||
vim.line.should == "fourth_line"
|
||||
end
|
||||
|
||||
describe "typing the 'cycle paste' key" do
|
||||
before { vim.normal "<M-p>" }
|
||||
|
||||
it "replaces the pasted text with the previously yanked text" do
|
||||
vim.line.should == "third_line"
|
||||
end
|
||||
end
|
||||
end
|
||||
|
||||
describe "typing the `substitute_newer_paste` key without pasting first" do
|
||||
before { vim.type "<M-P>" }
|
||||
|
||||
it "pastes the most recently yanked string" do
|
||||
vim.line_number.should == 5
|
||||
vim.line.should == "fourth_line"
|
||||
end
|
||||
|
||||
describe "typing the 'cycle paste' key" do
|
||||
before { vim.normal "<M-p>" }
|
||||
|
||||
it "replaces the pasted text with the previously yanked text" do
|
||||
vim.line.should == "third_line"
|
||||
end
|
||||
end
|
||||
end
|
||||
|
||||
it "allows pasting from a non-default register" do
|
||||
reg = 'a'
|
||||
vim.normal "gg"
|
||||
vim.normal %("#{reg}y$)
|
||||
vim.normal "G"
|
||||
|
||||
vim.normal %("#{reg}p)
|
||||
vim.line.should == "first_line"
|
||||
end
|
||||
|
||||
it "allows pasting with a count" do
|
||||
vim.normal "3p"
|
||||
vim.line_number.should == 5
|
||||
vim.line.should == "fourth_line" * 3
|
||||
end
|
||||
end
|
||||
|
||||
context "in visual mode, with text highlighted" do
|
||||
before do
|
||||
vim.normal "A<CR>", "line to overwrite"
|
||||
vim.normal "V"
|
||||
end
|
||||
|
||||
describe "pasting a string with 'p'" do
|
||||
before do
|
||||
vim.type "p"
|
||||
end
|
||||
|
||||
it "overwrites the selection with the most recently yanked string" do
|
||||
vim.line.should == "fourth_line"
|
||||
end
|
||||
|
||||
it "moves the the overwritten text to the bottom of the stack" do
|
||||
yank_entries[0].should include "fourth_line"
|
||||
yank_entries[1].should include "third_line"
|
||||
yank_entries[2].should include "second_line"
|
||||
yank_entries[-1].should include "line to overwrite"
|
||||
end
|
||||
|
||||
describe "typing the 'cycle older paste' key" do
|
||||
before { vim.normal "<M-p>" }
|
||||
|
||||
it "replaces the pasted text with the previously yanked text" do
|
||||
vim.line.should == "third_line"
|
||||
end
|
||||
|
||||
it "moves the previously yanked text to the top of the stack" do
|
||||
yank_entries[0].should include "third_line"
|
||||
yank_entries[1].should include "second_line"
|
||||
yank_entries[2].should include "first_line"
|
||||
yank_entries[-2].should include "line to overwrite"
|
||||
yank_entries[-1].should include "fourth_line"
|
||||
end
|
||||
|
||||
describe "typing the 'cycle newer paste' key" do
|
||||
before { vim.normal "<M-P>" }
|
||||
|
||||
it "replaces the pasted text with the previously yanked text" do
|
||||
vim.line.should == "fourth_line"
|
||||
end
|
||||
|
||||
it "moves the previously yanked text to the top of the stack" do
|
||||
yank_entries[0].should include "fourth_line"
|
||||
yank_entries[1].should include "third_line"
|
||||
yank_entries[2].should include "second_line"
|
||||
yank_entries[3].should include "first_line"
|
||||
yank_entries[-1].should include "line to overwrite"
|
||||
end
|
||||
end
|
||||
end
|
||||
end
|
||||
|
||||
describe "typing the `substitute_older_paste` key without pasting first" do
|
||||
before { vim.type "<M-p>" }
|
||||
|
||||
it "overwrites the selection with the most recently yanked string" do
|
||||
vim.line_number.should == 5
|
||||
vim.line.should == "fourth_line"
|
||||
end
|
||||
end
|
||||
|
||||
describe "typing the `substitute_newer_paste` key without pasting first" do
|
||||
before { vim.type "<M-P>" }
|
||||
|
||||
it "overwrites the selection with the most recently yanked string" do
|
||||
vim.line_number.should == 5
|
||||
vim.line.should == "fourth_line"
|
||||
end
|
||||
end
|
||||
|
||||
it "allows pasting with a count" do
|
||||
vim.type "3p"
|
||||
|
||||
vim.line_number.should == 5
|
||||
vim.line.should == "fourth_line"
|
||||
|
||||
vim.normal 'j'
|
||||
vim.line_number.should == 6
|
||||
vim.line.should == "fourth_line"
|
||||
|
||||
vim.normal 'j'
|
||||
vim.line_number.should == 7
|
||||
vim.line.should == "fourth_line"
|
||||
end
|
||||
end
|
||||
|
||||
context "in insert mode" do
|
||||
before do
|
||||
vim.normal "A<Cr>", "()", "<Left>"
|
||||
vim.type "<M-p>"
|
||||
end
|
||||
|
||||
describe "typing the `substitute_older_paste` after a character-wise yank" do
|
||||
it "pastes the most recently yanked text after the cursor" do
|
||||
vim.line_number.should == 5
|
||||
vim.line.should == "(fourth_line)"
|
||||
end
|
||||
|
||||
it "stays in insert mode, with the cursor at the end of the pasted text" do
|
||||
vim.should be_in_insert_mode
|
||||
vim.column_number.should == "(fourth_line".length + 1
|
||||
end
|
||||
|
||||
describe "typing the `substitute_older_paste` key again" do
|
||||
before { vim.type "<M-p>" }
|
||||
|
||||
it "replaces the pasted text with the previously yanked text" do
|
||||
vim.line_number.should == 5
|
||||
vim.line.should == "(third_line)"
|
||||
end
|
||||
|
||||
it "stays in insert mode, with the cursor at the end of the pasted text" do
|
||||
vim.should be_in_insert_mode
|
||||
vim.column_number.should == "(third_line".length+1
|
||||
end
|
||||
|
||||
it "rotates the previously yanked text to the top of the yank stack" do
|
||||
yank_entries[0].should include 'third_line'
|
||||
yank_entries[1].should include 'second_line'
|
||||
yank_entries[2].should include 'first_line'
|
||||
yank_entries[-1].should include 'fourth_line'
|
||||
end
|
||||
|
||||
it "rotates through the yanks when pressed multiple times" do
|
||||
vim.type "<M-p>"
|
||||
vim.line_number.should == 5
|
||||
vim.line.should == "(second_line)"
|
||||
|
||||
vim.type "<M-p>"
|
||||
vim.line_number.should == 5
|
||||
vim.line.should == "(first_line)"
|
||||
|
||||
vim.type "<M-P>"
|
||||
vim.line_number.should == 5
|
||||
vim.line.should == "(second_line)"
|
||||
|
||||
vim.type "<M-P>"
|
||||
vim.line_number.should == 5
|
||||
vim.line.should == "(third_line)"
|
||||
|
||||
vim.type "<M-P>"
|
||||
vim.line_number.should == 5
|
||||
vim.line.should == "(fourth_line)"
|
||||
end
|
||||
end
|
||||
end
|
||||
|
||||
describe "typing `substitute_older_paste` after a line-wise yank" do
|
||||
let(:yank_keys) { "yy" }
|
||||
|
||||
xit "pastes and puts the cursor after the pasted text" do
|
||||
vim.line_number.should == 6
|
||||
vim.line.should == ")"
|
||||
vim.type "<Up>"
|
||||
vim.line.should == "(fourth_line"
|
||||
end
|
||||
end
|
||||
end
|
||||
end
|
||||
|
||||
describe "when using the normal default register" do
|
||||
it_has_behavior "yanking and pasting"
|
||||
end
|
||||
|
||||
describe "when using the system clipboard as the default register" do
|
||||
before { vim.set "clipboard", "unnamed" }
|
||||
it_has_behavior "yanking and pasting"
|
||||
end
|
||||
|
||||
def yank_entries
|
||||
@yank_entries ||= vim.command("Yanks").split("\n")[1..-1]
|
||||
end
|
||||
end
|
||||
|
Reference in New Issue
Block a user