From a4689e85ec5291e8003988f8616c97386bf6c5c4 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Kim=20Silkeb=C3=A6kken?= Date: Mon, 28 Mar 2011 10:12:08 +0200 Subject: [PATCH 1/3] Use substitute() for markers, works better with Unicode --- plugin/EasyMotion.vim | 7 ++++--- 1 file changed, 4 insertions(+), 3 deletions(-) diff --git a/plugin/EasyMotion.vim b/plugin/EasyMotion.vim index 80198c2..b11d3ac 100644 --- a/plugin/EasyMotion.vim +++ b/plugin/EasyMotion.vim @@ -163,10 +163,11 @@ if ! has_key(lines, line_num) let current_line = getline(line_num) - let lines[line_num] = { 'orig': current_line, 'marker': split(current_line, '\zs') } + let lines[line_num] = { 'orig': current_line, 'marker': current_line } endif - let lines[line_num]['marker'][col_num - 1] = s:index_to_key[single_group ? element : current_group] + " Substitute marker character + let lines[line_num]['marker'] = substitute(lines[line_num]['marker'], '\%' . col_num . 'c.', s:index_to_key[single_group ? element : current_group], '') " Add highlighting coordinates call add(hl_coords, '\%' . line_num . 'l\%' . col_num . 'c') @@ -208,7 +209,7 @@ catch endtry - call setline(line_num, join(line['marker'], '')) + call setline(line_num, line['marker']) endfor redraw From 99dfdfb7320d71c2ea7ce45255c9b0aa282ef636 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Kim=20Silkeb=C3=A6kken?= Date: Mon, 28 Mar 2011 10:14:51 +0200 Subject: [PATCH 2/3] Make the motions work in visual mode --- plugin/EasyMotion.vim | 65 +++++++++++++++++++++++++++++++++---------- 1 file changed, 50 insertions(+), 15 deletions(-) diff --git a/plugin/EasyMotion.vim b/plugin/EasyMotion.vim index b11d3ac..65c9072 100644 --- a/plugin/EasyMotion.vim +++ b/plugin/EasyMotion.vim @@ -9,8 +9,8 @@ " http://www.vim.org/scripts/script.php?script_id=3437 " " This script addresses some issues with the original PreciseJump -" script. It only works in normal mode (for now), and it works correctly -" with the following motions: f F t T w e b +" script. It works correctly with the following motions in both normal +" and visual mode: f F t T w e b " " Default key mapping: " - f {char} @@ -60,14 +60,21 @@ " Default key mapping {{{ if g:EasyMotion_do_mapping nnoremap f :call EasyMotionF(0) + vnoremap f :call EasyMotionF(0, visualmode()) nnoremap F :call EasyMotionF(1) + vnoremap F :call EasyMotionF(1, visualmode()) nnoremap t :call EasyMotionT(0) + vnoremap t :call EasyMotionT(0, visualmode()) nnoremap T :call EasyMotionT(1) + vnoremap T :call EasyMotionT(1, visualmode()) nnoremap w :call EasyMotionW() + vnoremap w :call EasyMotionW(visualmode()) nnoremap e :call EasyMotionE() + vnoremap e :call EasyMotionE(visualmode()) nnoremap b :call EasyMotionB() + vnoremap b :call EasyMotionB(visualmode()) endif " }}} " Initialize variables {{{ @@ -83,19 +90,19 @@ " Motion functions {{{ " F key motions {{{ " Go to {char} to the right or the left - function! EasyMotionF(direction) + function! EasyMotionF(direction, ...) call Prompt('Search for character') let char = getchar() let re = '\C' . escape(nr2char(char), '.$^~') - call EasyMotion(re, a:direction) + call EasyMotion(re, a:direction, a:0 > 0 ? a:1 : '') endfunction " }}} " T key motions {{{ " Go to {char} to the right (before) or the left (after) - function! EasyMotionT(direction) + function! EasyMotionT(direction, ...) call Prompt('Search for character') let char = getchar() @@ -106,25 +113,25 @@ let re = '\C.' . escape(nr2char(char), '.$^~') endif - call EasyMotion(re, a:direction) + call EasyMotion(re, a:direction, a:0 > 0 ? a:1 : '') endfunction " }}} " W key motions {{{ " Beginning of word forward - function! EasyMotionW() - call EasyMotion('\<.', 0) + function! EasyMotionW(...) + call EasyMotion('\<.', 0, a:0 > 0 ? a:1 : '') endfunction " }}} " E key motions {{{ " End of word forward - function! EasyMotionE() - call EasyMotion('.\>', 0) + function! EasyMotionE(...) + call EasyMotion('.\>', 0, a:0 > 0 ? a:1 : '') endfunction " }}} " B key motions {{{ " Beginning of word backward - function! EasyMotionB() - call EasyMotion('\<.', 1) + function! EasyMotionB(...) + call EasyMotion('\<.', 1, a:0 > 0 ? a:1 : '') endfunction " }}} " }}} @@ -268,9 +275,10 @@ endif endtry endfunction "}}} - function! s:EasyMotion(regexp, direction) " {{{ + function! s:EasyMotion(regexp, direction, ...) " {{{ let orig_pos = [line('.'), col('.')] let targets = [] + let visualmode = a:0 > 0 ? a:1 : '' " Find motion targets while 1 @@ -300,6 +308,9 @@ call Message('No matches') + " Restore cursor position + call setpos('.', [0, orig_pos[0], orig_pos[1]]) + return endif @@ -351,10 +362,34 @@ " Cancelled by user call Message('Operation cancelled') + " Restore cursor position/selection + if ! empty(visualmode) + silent exec 'normal! `<' . visualmode . '`>' + else + call setpos('.', [0, orig_pos[0], orig_pos[1]]) + endif + return else - " Jump to coords - call setpos('.', [0, coords[0], coords[1]]) + if ! empty(visualmode) + " Store original marks + let m_a = getpos("'a") + let m_b = getpos("'b") + + " Store start/end positions + call setpos("'a", [0, orig_pos[0], orig_pos[1]]) + call setpos("'b", [0, coords[0], coords[1]]) + + " Update selection + silent exec 'normal! `a' . visualmode . '`b' + + " Restore original marks + call setpos("'a", m_a) + call setpos("'b", m_b) + else + " Update cursor position + call setpos('.', [0, coords[0], coords[1]]) + endif call Message('Jumping to [' . coords[0] . ', ' . coords[1] . ']') endif From c1c4444e58286e600225bfce5ea78823f3e23946 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Kim=20Silkeb=C3=A6kken?= Date: Mon, 28 Mar 2011 10:18:00 +0200 Subject: [PATCH 3/3] Update comment header --- plugin/EasyMotion.vim | 11 +++++------ 1 file changed, 5 insertions(+), 6 deletions(-) diff --git a/plugin/EasyMotion.vim b/plugin/EasyMotion.vim index 65c9072..ef37507 100644 --- a/plugin/EasyMotion.vim +++ b/plugin/EasyMotion.vim @@ -1,18 +1,17 @@ -" EasyMotion - vim motions on speed +" EasyMotion - Vim motions on speed! " " Author: Kim Silkebækken " Source: https://github.com/Lokaltog/EasyMotion -" Version: 1.0 +" Version: 1.0.1 " Modified: 2011-03-28 " -" Heavily modified version of Bartlomiej Podolak's PreciseJump script: +" Based on Bartlomiej Podolak's PreciseJump script: " http://www.vim.org/scripts/script.php?script_id=3437 " -" This script addresses some issues with the original PreciseJump -" script. It works correctly with the following motions in both normal +" This script works correctly with the following motions in both normal " and visual mode: f F t T w e b " -" Default key mapping: +" Default key mapping for both normal and visual mode: " - f {char} " - F {char} " - t {char}