mjbrownie / swapit

vim plugin: Extensible Keyword Swapper
39 stars 8 forks source link

"count" is not supported #4

Closed bootleq closed 10 years ago

bootleq commented 13 years ago

Currently, [count] is not supported.

When doing 4<C-A> on "1", should result in "5", now get result as "2".

mjbrownie commented 13 years ago

Thanks,

In the very least this should be offered in the pass through.

If you are feeling energetic the speeddating plugin appears to implement this functionality in a similar manner as would be desired. A patch would be great.

https://github.com/tpope/vim-speeddating/blob/master/plugin/speeddating.vim#L93

I'll try to have a look when I can.

bootleq commented 13 years ago

I'll try a patch later, use the v:count variable should help.

inkarkat commented 10 years ago

This has been fixed and should be closed!

mjbrownie commented 10 years ago

oops. didn't see the notice on this one

Hotschke commented 9 years ago

I use swapit together with tpope/vim-speeddating and tpope/vim-repeat. I have added following mappings to my vimrc:

nmap <Plug>SwapItFallbackIncrement <Plug>SpeedDatingUp
nmap <Plug>SwapItFallbackDecrement <Plug>SpeedDatingDown

However, dot-repeating does not work for swapitlists:

11 - Ok 31-12-2015 - Ok Wednesday - Nope (could be delegated to speeddating to make it work) False - Nope

Is it possible to add support for repeat.vim for swapit itself?

Hotschke commented 9 years ago

I have tried to add this on my own according to http://vimcasts.org/episodes/creating-repeatable-mappings-with-repeat-vim/

diff --git a/plugin/swapit.vim b/plugin/swapit.vim
index 97c9e81..c1710da 100755
--- a/plugin/swapit.vim
+++ b/plugin/swapit.vim
@@ -152,8 +152,12 @@ endif
 "Command/AutoCommand Configuration {{{1
 "
 " For executing the listing
-nnoremap <silent><c-a> :<c-u>call SwapWord(expand("<cword>"), v:count, 'forward', 'no')<cr>
-nnoremap <silent><c-x> :<c-u>call SwapWord(expand("<cword>"), v:count, 'backward','no')<cr>
+nnoremap <silent><Plug>SwapIncrement :<c-u>call SwapWord(expand("<cword>"), v:count, 'forward', 'no')<CR> 
+            \ :call repeat#set("\<Plug>SwapIncrement")<CR>
+nnoremap <silent><Plug>SwapDecrement :<c-u>call SwapWord(expand("<cword>"), v:count, 'backward','no')<CR>
+            \ :call repeat#set("\<Plug>SwapDecrement")<CR>
+nmap <silent><c-a> <Plug>SwapIncrement
+nmap <silent><c-x> <Plug>SwapDecrement
 vnoremap <silent><c-a> :<c-u>let swap_count = v:count<Bar>call SwapWord(<SID>GetSelection(), swap_count, 'forward', 'yes')<Bar>unlet swap_count<cr>
 vnoremap <silent><c-x> :<c-u>let swap_count = v:count<Bar>call SwapWord(<SID>GetSelection(), swap_count, 'backward','yes')<Bar>unlet swap_count<cr>
 "inoremap <silent><c-b> <esc>b"sdwi <c-r>=SwapInsert()<cr>

However, the cursors moves unintended:

FILE:|Monday (column=1) CMD:<CTRL-A> FILE:Tu|esday (column=3) CMD:. FILE: Wedn|esday (column=5) CMD:. FILE: Thursd|ay (column=7)

This does not happen without the changes to plugin/swapit.vim given in the above diff.

mjbrownie commented 9 years ago

Hi there. I noticed your mappings have a space on the newline "\ :call ". Does '\:call' work instead?

Hotschke commented 9 years ago

Indeed it works. Thanks for the help. Following works

diff --git a/plugin/swapit.vim b/plugin/swapit.vim
index 97c9e81..64e3c97 100755
--- a/plugin/swapit.vim
+++ b/plugin/swapit.vim
@@ -152,8 +152,12 @@ endif
 "Command/AutoCommand Configuration {{{1
 "
 " For executing the listing
-nnoremap <silent><c-a> :<c-u>call SwapWord(expand("<cword>"), v:count, 'forward', 'no')<cr>
-nnoremap <silent><c-x> :<c-u>call SwapWord(expand("<cword>"), v:count, 'backward','no')<cr>
+nnoremap <silent><Plug>SwapIncrement :<c-u>call SwapWord(expand("<cword>"), v:count, 'forward', 'no')<CR>
+            \:call repeat#set("\<Plug>SwapIncrement", v:count)<CR>
+nnoremap <silent><Plug>SwapDecrement :<c-u>call SwapWord(expand("<cword>"), v:count, 'backward','no')<CR>
+            \:call repeat#set("\<Plug>SwapDecrement", v:count)<CR>
+nmap <silent><c-a> <Plug>SwapIncrement
+nmap <silent><c-x> <Plug>SwapDecrement
 vnoremap <silent><c-a> :<c-u>let swap_count = v:count<Bar>call SwapWord(<SID>GetSelection(), swap_count, 'forward', 'yes')<Bar>unlet swap_count<cr>
 vnoremap <silent><c-x> :<c-u>let swap_count = v:count<Bar>call SwapWord(<SID>GetSelection(), swap_count, 'backward','yes')<Bar>unlet swap_count<cr>
 "inoremap <silent><c-b> <esc>b"sdwi <c-r>=SwapInsert()<cr>
Hotschke commented 9 years ago

One thing I have noticed using counts with repeat.vim. Consider incrementing weekdays with a count of 2:

Monday
2<CTRL-A>
Wednesday
.
Thursday

I would have expected by pressing dot that Wednesday changes to Friday. I have already added v:count to the call of repeat#set. Is it possible that the value in v:count is changed after SwapWord?

Using <bar> instead of changing to normal mode again does not fix it:

nnoremap <silent><Plug>SwapIncrement :<c-u>call SwapWord(expand("<cword>"), v:count, 'forward', 'no')<bar>
            \call repeat#set("\<Plug>SwapIncrement", v:count)<CR>
nnoremap <silent><Plug>SwapDecrement :<c-u>call SwapWord(expand("<cword>"), v:count, 'backward','no')<bar>
            \call repeat#set("\<Plug>SwapDecrement", v:count)<CR>
Hotschke commented 9 years ago

Using a variable similar to the visual mode mappings resolves the counting issue of my previous comment:

nnoremap <silent><Plug>SwapIncrement :<c-u>let swap_count = v:count<Bar>
            \call SwapWord(expand("<cword>"), swap_count, 'forward', 'no')<Bar>
            \call repeat#set("\<Plug>SwapIncrement", swap_count)<Bar>
            \unlet swap_count<CR>
nnoremap <silent><Plug>SwapDecrement :<c-u>let swap_count = v:count<Bar>
            \call SwapWord(expand("<cword>"), swap_count, 'backward','no')<Bar>
            \call repeat#set("\<Plug>SwapDecrement", swap_count)<Bar>
            \unlet swap_count<CR>