1.0.0 - Remade structure for GNU Stow

This commit is contained in:
2020-09-30 10:39:09 +02:00
parent d5c2147ed1
commit af44571593
766 changed files with 131648 additions and 18 deletions

View File

@@ -0,0 +1,2 @@
.rvmrc
doc/tags

View File

@@ -0,0 +1,4 @@
source 'https://rubygems.org'
gem "vimbot", :git => "git@github.com:maxbrunsfeld/vimbot.git"
gem "rspec"

View File

@@ -0,0 +1,25 @@
GIT
remote: git@github.com:maxbrunsfeld/vimbot.git
revision: 489cb3283a89d3e7891d9d9765188179c764317b
specs:
vimbot (0.0.1)
GEM
remote: https://rubygems.org/
specs:
diff-lcs (1.1.3)
rspec (2.8.0)
rspec-core (~> 2.8.0)
rspec-expectations (~> 2.8.0)
rspec-mocks (~> 2.8.0)
rspec-core (2.8.0)
rspec-expectations (2.8.0)
diff-lcs (~> 1.1.2)
rspec-mocks (2.8.0)
PLATFORMS
ruby
DEPENDENCIES
rspec
vimbot!

File diff suppressed because one or more lines are too long

View File

@@ -0,0 +1,197 @@
" yankstack.vim - keep track of your history of yanked/killed text
"
" Maintainer: Max Brunsfeld <https://github.com/maxbrunsfeld>
" Version: 1.0.6
" Todo:
"
let s:yankstack_tail = []
let g:yankstack_size = 30
let s:last_paste = { 'changedtick': -1, 'key': '', 'mode': 'n', 'count': 1, 'register': '' }
if !exists('g:yankstack_yank_keys')
let g:yankstack_yank_keys = ['c', 'C', 'd', 'D', 's', 'S', 'x', 'X', 'y', 'Y']
endif
function! s:yank_with_key(key)
call s:before_yank()
return a:key
endfunction
function! s:paste_with_key(key, mode, register, count)
return s:paste_from_yankstack(a:key, a:mode, a:register, a:count, 1)
endfunction
function! s:paste_from_yankstack(key, mode, register, count, is_new)
let keys = a:count . a:key
let keys = (a:register == s:default_register()) ? keys : ('"' . a:register . keys)
let s:last_paste = { 'key': a:key, 'mode': a:mode, 'register': a:register, 'count': a:count, 'changedtick': -1 }
call feedkeys("\<Plug>yankstack_after_paste", "m")
if a:mode == 'n'
exec 'normal!' keys
elseif a:mode == 'v'
if a:is_new
call s:before_yank()
call feedkeys("\<Plug>yankstack_substitute_older_paste", "t")
exec 'normal! gv' . keys
else
let head = s:get_yankstack_head()
exec 'normal! gv' . keys
call s:set_yankstack_head(head)
endif
" In insert mode, this function's return value is used in an
" expression mapping. In other modes, it is called for its
" side effects only.
elseif a:mode == 'i'
return keys
endif
silent! call repeat#setreg(a:register)
silent! call repeat#set(a:key, a:count)
endfunction
function! s:substitute_paste(offset, current_mode)
if s:last_change_was_paste()
silent undo
call s:yankstack_rotate(a:offset)
return s:paste_from_yankstack(s:last_paste.key, s:last_paste.mode, s:last_paste.register, s:last_paste.count, 0)
else
return s:paste_from_yankstack(s:default_paste_key(a:current_mode), a:current_mode, v:register, '', 1)
endif
endfunction
function! s:before_yank()
let head = s:get_yankstack_head()
if !empty(head.text) && (empty(s:yankstack_tail) || (head != s:yankstack_tail[0]))
call insert(s:yankstack_tail, head)
let s:yankstack_tail = s:yankstack_tail[: g:yankstack_size-1]
endif
endfunction
function! s:yankstack_rotate(offset)
if empty(s:yankstack_tail) | return | endif
let offset_left = a:offset
while offset_left != 0
let head = s:get_yankstack_head()
if offset_left > 0
let entry = remove(s:yankstack_tail, 0)
call add(s:yankstack_tail, head)
let offset_left -= 1
elseif offset_left < 0
let entry = remove(s:yankstack_tail, -1)
call insert(s:yankstack_tail, head)
let offset_left += 1
endif
call s:set_yankstack_head(entry)
endwhile
endfunction
function! s:get_yankstack_head()
let reg = s:default_register()
return { 'text': getreg(reg), 'type': getregtype(reg) }
endfunction
function! s:set_yankstack_head(entry)
let reg = s:default_register()
call setreg(reg, a:entry.text, a:entry.type)
endfunction
function! s:after_paste()
let s:last_paste.changedtick = b:changedtick
endfunction
function! s:last_change_was_paste()
return b:changedtick == s:last_paste.changedtick
endfunction
function! s:default_register()
let clipboard_flags = split(&clipboard, ',')
if index(clipboard_flags, 'unnamedplus') >= 0
return "+"
elseif index(clipboard_flags, 'unnamed') >= 0
return "*"
else
return "\""
endif
endfunction
function! s:default_paste_key(mode)
if a:mode == 'i'
return "\<C-g>u\<C-r>" . s:default_register()
else
return "p"
endif
endfunction
function! g:Yankstack()
return [s:get_yankstack_head()] + s:yankstack_tail
endfunction
command! -nargs=0 Yanks call s:show_yanks()
function! s:show_yanks()
echohl WarningMsg | echo "--- Yanks ---" | echohl None
let i = 0
for yank in g:Yankstack()
call s:show_yank(yank, i)
let i += 1
endfor
endfunction
function! s:show_yank(yank, index)
let index = printf("%-4d", a:index)
let lines = split(a:yank.text, '\n')
let line = empty(lines) ? '' : lines[0]
let line = substitute(line, '\t', repeat(' ', &tabstop), 'g')
if len(line) > 80 || len(lines) > 1
let line = line[: 80] . '…'
endif
echohl Directory | echo index
echohl None | echon line
echohl None
endfunction
function! yankstack#setup()
if exists('g:yankstack_did_setup') | return | endif
let g:yankstack_did_setup = 1
let paste_keys = ['p', 'P', 'gp', 'gP']
let word_characters = split("qwertyuiopasdfghjklzxcvbnm1234567890_", '\zs')
for key in g:yankstack_yank_keys
exec 'nnoremap <silent> <expr>' key '<SID>yank_with_key("' . key . '")'
exec 'xnoremap <silent> <expr>' key '<SID>yank_with_key("' . key . '")'
endfor
for key in paste_keys
exec 'nnoremap <silent>' key ':<C-u>call <SID>paste_with_key("' . key . '", "n", v:register, v:count1)<CR>'
exec 'xnoremap <silent>' key ':<C-u>call <SID>paste_with_key("' . key . '", "v", v:register, v:count1)<CR>'
endfor
for key in word_characters
exec 'smap <expr>' key '<SID>yank_with_key("' . key . '")'
endfor
endfunction
nnoremap <silent> <Plug>yankstack_substitute_older_paste :<C-u>call <SID>substitute_paste(v:count1, 'n')<CR>
nnoremap <silent> <Plug>yankstack_substitute_newer_paste :<C-u>call <SID>substitute_paste(-v:count1, 'n')<CR>
xnoremap <silent> <Plug>yankstack_substitute_older_paste :<C-u>call <SID>substitute_paste(v:count1, 'v')<CR>
xnoremap <silent> <Plug>yankstack_substitute_newer_paste :<C-u>call <SID>substitute_paste(-v:count1, 'v')<CR>
inoremap <silent> <Plug>yankstack_substitute_older_paste <C-r>=<SID>substitute_paste(v:count1, 'i')<CR>
inoremap <silent> <Plug>yankstack_substitute_newer_paste <C-r>=<SID>substitute_paste(-v:count1, 'i')<CR>
nnoremap <silent> <Plug>yankstack_after_paste :call <SID>after_paste()<CR>
xnoremap <silent> <Plug>yankstack_after_paste :<C-u>call <SID>after_paste()<CR>
inoremap <silent> <Plug>yankstack_after_paste <C-o>:call <SID>after_paste()<CR>
if !exists('g:yankstack_map_keys') || g:yankstack_map_keys
nmap <M-p> <Plug>yankstack_substitute_older_paste
xmap <M-p> <Plug>yankstack_substitute_older_paste
imap <M-p> <Plug>yankstack_substitute_older_paste
nmap <M-P> <Plug>yankstack_substitute_newer_paste
xmap <M-P> <Plug>yankstack_substitute_newer_paste
imap <M-P> <Plug>yankstack_substitute_newer_paste
endif

View File

@@ -0,0 +1,124 @@
*yankstack.txt* Plugin for storing and cycling through yanked text strings.
Author: Max Brunsfeld <http://www.github.com/maxbrunsfeld>
|yankstack-introduction| Introduction
|yankstack-installation| Installation
|yankstack-initialization| Initialization
|yankstack-commands| Commands
|yankstack-configuration| Configuration
|yankstack-changelog| Changelog
INTRODUCTION *yankstack-introduction*
[Yankstack.vim](https://github.com/maxbrunsfeld/vim-yankstack) is a
lightweight implementation of the Emacs 'kill ring' for Vim. It allows you to
yank and delete things without worrying about losing the text that you yanked
previously. It effectively turns your default register into a stack, and lets
you cycle through the items in the stack after doing a paste.
This plugin is intended to be a simpler alternative to the {Yankring} plugin
(https://github.com/chrismetcalf/vim-yankring).
INSTALLATION *yankstack-installation*
I recommend loading your plugins with {Pathogen}
(https://github.com/tpope/vim-pathogen), so you can just clone this repo into
your "bundle" directory.
KEY MAPPINGS *yankstack-mappings*
By default, yankstack adds only 2 key mappings, in normal and visual modes:
Mapping Action ~
meta-p cycle backward through your history of yanks
meta-shift-p cycle forwards through your history of yanks
After pasting some text using |p| or |P|, you can cycle through your
yank history using these commands.
Typing either of these keys without pasting first will do a normal paste
(the same as typing `p`). This also works in insert mode.
A note about the meta key - if you're using MacVim, and you want to use
this plugin's default key bindings (or any bindings involving the `option`
key), you must :set |macmeta|.
COMMANDS *yankstack-commands*
You can see the contents of the yank-stack using the :Yanks command.
Its output is similar to the |registers| command. >
:Yanks (lists the contents of the yank-stack)
CONFIGURATION *yankstack-configuration*
If you want to load yankstack without defining any of the default key
mappings, just add >
let g:yankstack_map_keys = 0
to your |.vimrc| file.
Yankstack defines three plugin mappings that you can map to keys of your
choosing. The same mappings work in normal and insert modes.
Mapping Name Action ~
<Plug>yankstack_substitute_older_paste cycle BACKWARDs through your history of yanks
<Plug>yankstack_substitute_newer_paste cycle FORWARDS through your history of yanks
For example, if you wanted to define some mappings based on your |leader| key, you could do this: >
nmap <leader>p <Plug>yankstack_substitute_older_paste
nmap <leader>P <Plug>yankstack_substitute_newer_paste
COMPATIBILITY *yankstack-compatibility*
Yankstack works by mapping the yank and paste keys to functions that do some
book-keeping before calling through to the normal yank/paste keys. You may
want to define your own mappings of the yank and paste keys. For example, I
like to map the |Y| key to "y$", so that it behaves the same as |D| and |C|.
The yankstack mappings need to happen **BEFORE** you define any such
mappings of your own. To achieve this, just call 'yankstack#setup()'in your
|vimrc|, before defining your mappings: >
call yankstack#setup()
nmap Y y$
CHANGELOG *yankstack-changelog*
1.0.5 (2012-07-19)
- Fix bug where on certain versions of vim, the first time you tried
to cycle through your yanks after doing a normal paste, an extra
paste was created.
1.0.4 (2012-07-01)
- Make it so that yankstack-cycling keys cause a normal paste if they are
used without pasting first. Fix stack-cycling in insert-mode.
1.0.3 (2012-05-04):
- Fix bug when overwriting text in select mode. This was causing
problems for snipMate users.
1.0.2 (2012-4-20):
- Add test coverage using rspec and [vimbot](https://github.com/maxbrunsfeld/vimbot)!
- Perfect the behavior of the yankstack when pasting over text in visual
mode
- Fix bug where 's' and 'S' didn't push to the yankstack
1.0.1 (2012-02-11):
- Change default key bindings, update readme, add link to github page.
1.0.1 (2011-12-08):
- Fix bug when displaying empty yanks.
1.0 (2011-12-04):
- Remove unnecessary dependency on the undotree() function. Plugin should
now work on any recent version of vim.
*yankstack-license*
Copyright (c) Max Brunsfeld. Distributed under the same terms as Vim itself.
See |license|.
vim:tw=78:ts=8:ft=help:norl:

View File

@@ -0,0 +1 @@
call yankstack#setup()

View 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