From 6b7781118620d17ea4036d11049e2407f81202ee Mon Sep 17 00:00:00 2001 From: haya14busa Date: Thu, 16 Jan 2014 23:18:56 +0900 Subject: [PATCH 1/2] Implement next/previous motion like `;` & `,` --- autoload/EasyMotion.vim | 14 ++++++ doc/easymotion.txt | 15 +++++++ plugin/EasyMotion.vim | 12 +++++ t/easymotion_spec.vim | 97 +++++++++++++++++++++++++++++++++++++++++ 4 files changed, 138 insertions(+) diff --git a/autoload/EasyMotion.vim b/autoload/EasyMotion.vim index 036b36c..17a534f 100644 --- a/autoload/EasyMotion.vim +++ b/autoload/EasyMotion.vim @@ -413,6 +413,20 @@ function! EasyMotion#DotRepeat(visualmode) " {{{ silent call s:EasyMotion(re, direction, 0, is_exclusive) endfor endfunction " }}} +function! EasyMotion#NextPrevious(visualmode, direction) " {{{ + " Repeat previous motion with previous targets + if s:previous ==# {} + call s:Message("Previous targets doesn't exist") + return + endif + let re = s:previous.regexp + let search_direction = (a:direction >= 1 ? 'b' : '') + + for i in range(v:count1) + call searchpos(re, search_direction) + endfor + call EasyMotion#reset() +endfunction " }}} " }}} " == Helper functions {{{ " -- Message ----------------------------- diff --git a/doc/easymotion.txt b/doc/easymotion.txt index a4e62d1..d530ddb 100644 --- a/doc/easymotion.txt +++ b/doc/easymotion.txt @@ -151,6 +151,8 @@ EasyMotion table *easymotion-plug-table* (easymotion-bd-n) | See |(easymotion-bd-n)| (easymotion-jumptoanywhere) | See |(easymotion-jumptoanywhere)| (easymotion-repeat) | See |(easymotion-repeat)| + (easymotion-next) | See |(easymotion-next)| + (easymotion-previous) | See |(easymotion-previous)| (easymotion-sol-j) | See |(easymotion-sol-j)| (easymotion-eol-j) | See |(easymotion-eol-j)| | @@ -256,6 +258,19 @@ Repeat ~ (easymotion-j) etc...) but only repeat input characters. +(easymotion-next) *(easymotion-next)* +(easymotion-previous) *(easymotion-previous)* + + Jump to next/previous much. Only this motion can be move to offscrren + match. This motion wrap around the end of the file if you set + |'wrapscan'| in your vimrc. + + Example: +> + nmap ; (easymotion-next) + nmap , (easymotion-previous) +< + EasyMotion dot repeat~ *easymotion-dotrepeat* *easymotion-textobjct* diff --git a/plugin/EasyMotion.vim b/plugin/EasyMotion.vim index e128833..0c777bd 100644 --- a/plugin/EasyMotion.vim +++ b/plugin/EasyMotion.vim @@ -250,6 +250,18 @@ xnoremap (easymotion-dotrepeat) \ :call EasyMotion#DotRepeat(1) "}}} +" -- Next,Previous Motion {{{ +noremap (easymotion-next) + \ :call EasyMotion#NextPrevious(0,0) +xnoremap (easymotion-next) + \ :call EasyMotion#NextPrevious(1,0) + +noremap (easymotion-previous) + \ :call EasyMotion#NextPrevious(0,1) +xnoremap (easymotion-previous) + \ :call EasyMotion#NextPrevious(1,1) +"}}} + " -- Line Motion {{{ " Word Line: {{{ noremap (easymotion-wl) :call EasyMotion#WBL(0,0) diff --git a/t/easymotion_spec.vim b/t/easymotion_spec.vim index 32b7dee..44a7dc1 100644 --- a/t/easymotion_spec.vim +++ b/t/easymotion_spec.vim @@ -291,6 +291,22 @@ describe 'Default settings' \ ==# ':call EasyMotion#DotRepeat(1)' " }}} + " Next, Previous motion {{{ + Expect maparg('(easymotion-next)', 'n') + \ ==# ':call EasyMotion#NextPrevious(0,0)' + Expect maparg('(easymotion-next)', 'o') + \ ==# ':call EasyMotion#NextPrevious(0,0)' + Expect maparg('(easymotion-next)', 'v') + \ ==# ':call EasyMotion#NextPrevious(1,0)' + + Expect maparg('(easymotion-previous)', 'n') + \ ==# ':call EasyMotion#NextPrevious(0,1)' + Expect maparg('(easymotion-previous)', 'o') + \ ==# ':call EasyMotion#NextPrevious(0,1)' + Expect maparg('(easymotion-previous)', 'v') + \ ==# ':call EasyMotion#NextPrevious(1,1)' + " }}} + " Line Motion: {{{ " word Expect maparg('(easymotion-wl)', 'n') ==# ':call EasyMotion#WBL(0,0)' @@ -390,6 +406,7 @@ describe 'Default settings' Expect exists('*EasyMotion#SelectPhraseYank') ==# 1 Expect exists('*EasyMotion#SelectPhraseDelete') ==# 1 Expect exists('*EasyMotion#Repeat') ==# 1 + Expect exists('*EasyMotion#NextPrevious') ==# 1 Expect exists('*EasyMotion#DotRepeat') ==# 1 "}}} end @@ -946,3 +963,83 @@ describe 'g:EasyMotion_smartsign' " }}} end "}}} + +" Next & Previous {{{ +describe '(easymotion-next) & (easymotion-previous)' + before + new + let g:EasyMotion_keys = 'abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ' + map s (easymotion-s) + map ; (easymotion-next) + map , (easymotion-previous) + set wrapscan + call EasyMotion#init() + call AddLine('poge huga hiyo poyo') + " 1234567890123456789 + end + + after + close! + end + + " provide next & previous motion to replace `;`, `,` {{{ + it 'provide next & previous motion to replace `;`, `,`' + normal! 0 + let l = line('.') + Expect CursorPos() == [l,1,'p'] + normal sha + Expect CursorPos() == [l,6,'h'] + + normal ; + Expect CursorPos() == [l,11,'h'] + + normal , + Expect CursorPos() == [l,6,'h'] + + " wrapscan + normal , + Expect CursorPos() == [l,11,'h'] + normal ; + Expect CursorPos() == [l,6,'h'] + + normal! $ + let l = line('.') + Expect CursorPos() == [l,19,'o'] + + normal , + Expect CursorPos() == [l,11,'h'] + + end + "}}} + + " next & previous motion count {{{ + it 'next & previous motion count' + normal! 0 + let l = line('.') + Expect CursorPos() == [l,1,'p'] + normal sha + Expect CursorPos() == [l,6,'h'] + + normal ; + Expect CursorPos() == [l,11,'h'] + + normal 2, + Expect CursorPos() == [l,11,'h'] + + " wrapscan + normal 4, + Expect CursorPos() == [l,11,'h'] + normal 3; + Expect CursorPos() == [l,6,'h'] + + normal! $ + let l = line('.') + Expect CursorPos() == [l,19,'o'] + + normal , + Expect CursorPos() == [l,11,'h'] + + end + "}}} +end +"}}} From 04d8a9a1e8ae67306b20b488ba3d716b27173330 Mon Sep 17 00:00:00 2001 From: haya14busa Date: Thu, 16 Jan 2014 23:19:54 +0900 Subject: [PATCH 2/2] Doc: Fix indent --- doc/easymotion.txt | 18 +++++++++--------- 1 file changed, 9 insertions(+), 9 deletions(-) diff --git a/doc/easymotion.txt b/doc/easymotion.txt index d530ddb..fa42e6d 100644 --- a/doc/easymotion.txt +++ b/doc/easymotion.txt @@ -246,17 +246,17 @@ Jump To Anywhere ~ Repeat ~ (easymotion-repeat) *(easymotion-repeat)* - Repeat last motion! + Repeat last motion! - Repeat last motion type including input target character. - Nothing will happen when previous motion doesn't exist. + Repeat last motion type including input target character. + Nothing will happen when previous motion doesn't exist. - Last Find Motion~ - In Find motion (e.g. |(easymoion-s)| ), to type `` - without input characters invoke last find motion. This - does not repeat motion type (e.g. othrer word motion, - (easymotion-j) etc...) but only repeat input - characters. + Last Find Motion~ + In Find motion (e.g. |(easymoion-s)| ), to type `` + without input characters invoke last find motion. This + does not repeat motion type (e.g. othrer word motion, + (easymotion-j) etc...) but only repeat input + characters. (easymotion-next) *(easymotion-next)* (easymotion-previous) *(easymotion-previous)*