From d3ee7bb8d953347bd27ca79561eb5dedb569d979 Mon Sep 17 00:00:00 2001 From: haya14busa Date: Wed, 5 Feb 2014 14:20:50 +0900 Subject: [PATCH] Improve command line for find motion Add: - autocmd User - InsertRegister - EMCommandLine Map, NoreMap, UnMap - Emacs like keymapping by default Change: - Modify default buffer completion key from to --- autoload/EasyMotion/command_line.vim | 74 ++++++++++++++++++++-------- plugin/EasyMotion.vim | 21 ++++---- 2 files changed, 63 insertions(+), 32 deletions(-) diff --git a/autoload/EasyMotion/command_line.vim b/autoload/EasyMotion/command_line.vim index f2b898d..14e540d 100644 --- a/autoload/EasyMotion/command_line.vim +++ b/autoload/EasyMotion/command_line.vim @@ -2,7 +2,7 @@ " FILE: autoload/EasyMotion/command_line.vim " AUTHOR: haya14busa " Reference: https://github.com/osyo-manga/vim-over -" Last Change: 01 Feb 2014. +" Last Change: 05 Feb 2014. " License: MIT license {{{ " Permission is hereby granted, free of charge, to any person obtaining " a copy of this software and associated documentation files (the @@ -36,12 +36,15 @@ let s:search = s:cmdline.make_plain("/") let s:search.highlights.prompt = "Question" " Add Module: {{{ -call s:search.connect(s:cmdline.module_delete()) -call s:search.connect(s:cmdline.module_cursor_move()) -call s:search.connect(s:cmdline.module_paste()) -call s:search.connect(s:cmdline.module_buffer_complete()) -call s:search.connect(s:cmdline.module_history("/")) -call s:search.connect(s:cmdline.module_no_insert_special_chars()) +call s:search.connect('Delete') +call s:search.connect('CursorMove') +call s:search.connect('Paste') +call s:search.connect('BufferComplete') +call s:search.connect('InsertRegister') +call s:search.connect(s:cmdline.get_module('History').make('/')) +call s:search.connect(s:cmdline.get_module('NoInsert').make_special_chars()) +call s:search.connect(s:cmdline.get_module('KeyMapping').make_emacs()) +call s:search.connect(s:cmdline.get_module('Doautocmd').make('EMCommandLine')) let s:module = { \ "name" : "EasyMotion", @@ -70,20 +73,51 @@ call s:search.connect(s:module) "}}} " CommandLine Keymap: {{{ -let s:default_key_mapping = { -\ "\" : "(buffer-complete)", -\ "\" : "(em-scroll-f)", -\ "\" : "(em-scroll-b)", -\ "\" : "(em-jumpback)", -\ "\" : "(em-openallfold)", -\} -function! EasyMotion#command_line#keymaps() "{{{ - return extend(deepcopy(s:default_key_mapping), - \ g:EasyMotion_command_line_key_mappings) -endfunction "}}} -function! s:search.keymappings() "{{{ - return EasyMotion#command_line#keymaps() +function! s:search.keymapping() "{{{ + return { +\ "\" : { +\ "key" : "(buffer-complete)", +\ "noremap" : 1, +\ }, +\ "\" : { +\ "key" : "(em-scroll-f)", +\ "noremap" : 1, +\ }, +\ "\" : { +\ "key" : "(em-scroll-b)", +\ "noremap" : 1, +\ }, +\ "\" : { +\ "key" : "(em-jumpback)", +\ "noremap" : 1, +\ }, +\ "\" : { +\ "key" : "(em-openallfold)", +\ "noremap" : 1, +\ }, +\ } endfunction "}}} + +" Fins Motion CommandLine Mapping Command: {{{ +function! EasyMotion#command_line#cmap(args) + let lhs = s:as_keymapping(a:args[0]) + let rhs = s:as_keymapping(a:args[1]) + call s:search.cmap(lhs, rhs) +endfunction +function! EasyMotion#command_line#cnoremap(args) + let lhs = s:as_keymapping(a:args[0]) + let rhs = s:as_keymapping(a:args[1]) + call s:search.cnoremap(lhs, rhs) +endfunction +function! EasyMotion#command_line#cunmap(lhs) + let lhs = s:as_keymapping(a:lhs) + call s:search.cunmap(lhs) +endfunction +function! s:as_keymapping(key) + execute 'let result = "' . substitute(a:key, '\(<.\{-}>\)', '\\\1', 'g') . '"' + return result +endfunction +"}}} "}}} " Event: {{{ diff --git a/plugin/EasyMotion.vim b/plugin/EasyMotion.vim index b38b499..7918be8 100644 --- a/plugin/EasyMotion.vim +++ b/plugin/EasyMotion.vim @@ -3,7 +3,7 @@ " Author: Kim Silkebækken " haya14busa " Source: https://github.com/Lokaltog/vim-easymotion -" Last Change: 02 Feb 2014. +" Last Change: 04 Feb 2014. " == Script initialization {{{ if expand("%:p") ==# expand(":p") unlet! g:EasyMotion_loaded @@ -387,18 +387,15 @@ if g:EasyMotion_do_mapping == 1 endif "}}} " == CommandLine Mapping {{{ -function! s:key_mapping(lhs, rhs) - let g:EasyMotion_command_line_key_mappings[a:lhs] = a:rhs -endfunction - -function! s:as_keymapping(key) - execute 'let result = "' . substitute(a:key, '\(<.\{-}>\)', '\\\1', 'g') . '"' - return result -endfunction - command! -nargs=* -\ EMCommandLineNoremap -\ call call("s:key_mapping", map([], "s:as_keymapping(v:val)")) +\ EMCommandLineNoreMap +\ call EasyMotion#command_line#cnoremap([]) +command! -nargs=* +\ EMCommandLineMap +\ call EasyMotion#command_line#cmap([]) +command! -nargs=1 +\ EMCommandLineUnMap +\ call EasyMotion#command_line#cunmap() "}}} " == Restore 'cpoptions' {{{