"============================================================================= " FILE: mappings.vim " AUTHOR: Shougo Matsushita " License: MIT license {{{ " Permission is hereby granted, free of charge, to any person obtaining " a copy of this software and associated documentation files (the " "Software"), to deal in the Software without restriction, including " without limitation the rights to use, copy, modify, merge, publish, " distribute, sublicense, and/or sell copies of the Software, and to " permit persons to whom the Software is furnished to do so, subject to " the following conditions: " " The above copyright notice and this permission notice shall be included " in all copies or substantial portions of the Software. " " THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS " OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF " MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. " IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY " CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, " TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE " SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. " }}} "============================================================================= let s:save_cpo = &cpo set cpo&vim " Define default mappings. function! unite#mappings#define_default_mappings() abort "{{{ " Plugin keymappings "{{{ nnoremap (unite_exit) \ :call exit() nnoremap (unite_all_exit) \ :call all_exit() nnoremap (unite_choose_action) \ :call choose_action() if b:unite.prompt_linenr == 0 nnoremap (unite_insert_enter) \ :call insert_enter2() nnoremap (unite_insert_head) \ :call insert_enter2() nnoremap (unite_append_enter) \ :call insert_enter2() nnoremap (unite_append_end) \ :call insert_enter2() else nnoremap (unite_insert_enter) \ insert_enter('i') nnoremap (unite_insert_head) \ insert_enter('A'. \ (repeat("\", len(substitute( \ unite#helper#get_input(), '.', 'x', 'g'))))) nnoremap (unite_append_enter) \ insert_enter('a') nnoremap (unite_append_end) \ insert_enter('A') endif nnoremap (unite_toggle_mark_current_candidate) \ :call toggle_mark('j') nnoremap (unite_toggle_mark_current_candidate_up) \ :call toggle_mark('k') nnoremap (unite_redraw) \ :call redraw() nnoremap (unite_rotate_next_source) \ :call rotate_source(1) nnoremap (unite_rotate_previous_source) \ :call rotate_source(0) nnoremap (unite_print_candidate) \ :call print_candidate() nnoremap (unite_print_message_log) \ :call print_message_log() nnoremap (unite_cursor_top) \ :call cursor_top() nnoremap (unite_cursor_bottom) \ :call cursor_bottom() nnoremap (unite_next_screen) \ :call move_screen(1) nnoremap (unite_next_half_screen) \ :call move_half_screen(1) nnoremap (unite_quick_match_default_action) \ :call unite#mappings#_quick_match(0) nnoremap (unite_quick_match_jump) \ :call unite#mappings#_quick_match(1) nnoremap (unite_input_directory) \ :call input_directory() nnoremap (unite_do_default_action) \ unite#do_action(unite#get_current_unite().context.default_action) nnoremap (unite_delete_backward_path) \ :call delete_backward_path() nnoremap (unite_restart) \ :call restart() nnoremap (unite_toggle_mark_all_candidates) \ :call toggle_mark_all_candidates() nnoremap (unite_toggle_transpose_window) \ :call toggle_transpose_window() nnoremap (unite_toggle_auto_preview) \ :call toggle_auto_preview() nnoremap (unite_toggle_auto_highlight) \ :call toggle_auto_highlight() nnoremap (unite_narrowing_input_history) \ :call narrowing_input_history() nnoremap (unite_narrowing_dot) \ :call narrowing_dot() nnoremap (unite_disable_max_candidates) \ :call disable_max_candidates() nnoremap (unite_quick_help) \ :call quick_help() nnoremap (unite_new_candidate) \ :call do_new_candidate_action() nnoremap (unite_smart_preview) \ :call smart_preview() vnoremap (unite_toggle_mark_selected_candidates) \ :call toggle_mark_candidates( \ getpos("'<")[1], getpos("'>")[1]) inoremap (unite_exit) \ :call exit() inoremap (unite_insert_leave) \ :call insert_leave() inoremap (unite_delete_backward_char) \ smart_imap((unite#helper#get_input() == '' ? \ "\:\call \all_exit()\" : "\")) inoremap (unite_delete_backward_line) \ smart_imap(repeat("\", \ unite#util#strchars(unite#helper#get_input()))) inoremap (unite_delete_backward_word) \ smart_imap("\") inoremap (unite_delete_backward_path) \ :call delete_backward_path() inoremap (unite_select_next_page) \ pumvisible() ? "\" : repeat("\", winheight(0)) inoremap (unite_select_previous_page) \ pumvisible() ? "\" : repeat("\", winheight(0)) inoremap (unite_toggle_mark_current_candidate) \ :call toggle_mark('j') inoremap (unite_toggle_mark_current_candidate_up) \ :call toggle_mark('k') inoremap (unite_choose_action) \ :call choose_action() inoremap (unite_move_head) \ smart_imap(repeat("\", len(substitute( \ unite#helper#get_input(), '.', 'x', 'g')))) inoremap (unite_move_left) \ smart_imap("\") inoremap (unite_move_right) \ smart_imap2("\") inoremap (unite_quick_match_default_action) \ :call unite#mappings#_quick_match(0) inoremap (unite_quick_match_jump) \ :call unite#mappings#_quick_match(1) inoremap (unite_input_directory) \ :call input_directory() inoremap (unite_do_default_action) \ unite#do_action(unite#get_current_unite().context.default_action) inoremap (unite_toggle_transpose_window) \ :call toggle_transpose_window() inoremap (unite_toggle_auto_preview) \ :call toggle_auto_preview() inoremap (unite_toggle_auto_highlight) \ :call toggle_auto_highlight() inoremap (unite_narrowing_input_history) \ :call narrowing_input_history() inoremap (unite_disable_max_candidates) \ :call disable_max_candidates() inoremap (unite_redraw) \ :call redraw() inoremap (unite_new_candidate) \ :call do_new_candidate_action() inoremap (unite_print_message_log) \ :call print_message_log() inoremap (unite_complete) \ complete() "}}} if exists('g:unite_no_default_keymappings') \ && g:unite_no_default_keymappings return endif " Normal mode key-mappings. execute s:nowait_map('n') 'i' \ '(unite_insert_enter)' execute s:nowait_map('n') 'I' \ '(unite_insert_head)' execute s:nowait_map('n') 'A' \ '(unite_append_end)' execute s:nowait_map('n') 'q' \ '(unite_exit)' execute s:nowait_map('n') '' \ '(unite_exit)' execute s:nowait_map('n') 'Q' \ '(unite_all_exit)' execute s:nowait_map('n') 'g' \ '(unite_all_exit)' execute s:nowait_map('n') '' \ '(unite_do_default_action)' execute s:nowait_map('n') '' \ '(unite_toggle_mark_current_candidate)' execute s:nowait_map('n') '' \ '(unite_toggle_mark_current_candidate_up)' execute s:nowait_map('n') '' \ '(unite_choose_action)' execute s:nowait_map('n') '' \ '(unite_rotate_next_source)' execute s:nowait_map('n') '' \ '(unite_rotate_previous_source)' execute s:nowait_map('n') '' \ '(unite_print_message_log)' execute s:nowait_map('n') '' \ '(unite_print_candidate)' execute s:nowait_map('n') '' \ '(unite_redraw)' execute s:nowait_map('n') 'gg' \ '(unite_cursor_top)' execute s:nowait_map('n') '' \ '(unite_cursor_top)' execute s:nowait_map('n') 'G' \ '(unite_cursor_bottom)' execute s:nowait_map('n') '' \ '(unite_cursor_bottom)$' execute s:nowait_map('n') 'j' \ '(unite_loop_cursor_down)' execute s:nowait_map('n') '' \ '(unite_loop_cursor_down)' execute s:nowait_map('n') 'k' \ '(unite_loop_cursor_up)' execute s:nowait_map('n') '' \ '(unite_loop_cursor_up)' execute s:nowait_map('n') 'J' \ '(unite_skip_cursor_down)' execute s:nowait_map('n') 'K' \ '(unite_skip_cursor_up)' execute s:nowait_map('n') '' \ '(unite_delete_backward_path)' execute s:nowait_map('n') '' \ '(unite_restart)' execute s:nowait_map('n') '*' \ '(unite_toggle_mark_all_candidates)' execute s:nowait_map('n') 'M' \ '(unite_disable_max_candidates)' execute s:nowait_map('n') 'g?' \ '(unite_quick_help)' execute s:nowait_map('n') 'N' \ '(unite_new_candidate)' execute s:nowait_map('n') '.' \ '(unite_narrowing_dot)' execute s:nowait_map('n') 'p' \ '(unite_smart_preview)' execute s:nowait_map('n') '<2-LeftMouse>' \ '(unite_do_default_action)' execute s:nowait_map('n') '' \ '(unite_exit)' execute s:nowait_expr('nmap') 'a' \ 'unite#smart_map("\(unite_append_enter)", \ "\(unite_choose_action)")' execute s:nowait_expr('nnoremap') 'd' \ 'unite#smart_map(''d'', unite#do_action(''delete''))' execute s:nowait_expr('nnoremap') 'b' \ 'unite#smart_map(''b'', unite#do_action(''bookmark''))' execute s:nowait_expr('nnoremap') 'e' \ 'unite#smart_map(''e'', unite#do_action(''edit''))' execute s:nowait_expr('nmap') 'x' \ 'unite#smart_map(''x'', "\(unite_quick_match_default_action)")' execute s:nowait_expr('nnoremap') 't' \ 'unite#smart_map(''t'', unite#do_action(''tabopen''))' execute s:nowait_expr('nnoremap') 'yy' \ 'unite#smart_map(''yy'', unite#do_action(''yank''))' execute s:nowait_expr('nnoremap') 'o' \ 'unite#smart_map(''o'', unite#do_action(''open''))' " Visual mode key-mappings. xmap \ (unite_toggle_mark_selected_candidates) " Insert mode key-mappings. imap (unite_choose_action) imap (unite_select_next_line) imap (unite_select_next_line) imap (unite_select_previous_line) imap (unite_select_previous_line) imap (unite_select_next_page) imap (unite_select_previous_page) imap (unite_do_default_action) imap (unite_delete_backward_char) imap (unite_delete_backward_char) imap (unite_delete_backward_line) imap (unite_delete_backward_word) imap (unite_move_head) imap (unite_move_head) imap (unite_move_left) imap (unite_move_right) imap (unite_redraw) if has('gui_running') imap (unite_insert_leave) endif execute s:nowait_map('i') '' \ '(unite_exit)' imap <2-LeftMouse> (unite_do_default_action) imap (unite_exit) imap \ unite#smart_map(' ', "\(unite_toggle_mark_current_candidate)") imap \ unite#smart_map(' ', "\(unite_toggle_mark_current_candidate_up)") inoremap \ unite#do_action('delete') inoremap \ unite#do_action('edit') inoremap \ unite#do_action('tabopen') inoremap \ unite#do_action('yank') inoremap \ unite#do_action('open') endfunction"}}} function! s:nowait_map(mode) abort "{{{ return a:mode.'map ' \ . ((v:version > 703 || (v:version == 703 && has('patch1261'))) ? \ '' : '') endfunction "}}} function! s:nowait_expr(map) abort "{{{ return a:map . ' ' \ . ((v:version > 703 || (v:version == 703 && has('patch1261'))) ? \ '' : '') endfunction "}}} function! unite#mappings#narrowing(word, ...) abort "{{{ let is_escape = get(a:000, 0, 1) setlocal modifiable let unite = unite#get_current_unite() let unite.input = is_escape ? escape(a:word, ' *') : a:word let unite.context.input = unite.input call unite#handlers#_on_insert_enter() call unite#view#_redraw_prompt() call unite#helper#cursor_prompt() call unite#view#_bottom_cursor() startinsert! endfunction"}}} function! unite#mappings#do_action(...) abort "{{{ return call('unite#action#do', a:000) endfunction"}}} function! unite#mappings#set_current_matchers(matchers) abort "{{{ let unite = unite#get_current_unite() let unite.current_matchers = a:matchers let unite.context.is_redraw = 1 return mode() ==# 'i' ? "a\" : "g\" endfunction"}}} function! unite#mappings#set_current_sorters(sorters) abort "{{{ let unite = unite#get_current_unite() let unite.current_sorters = a:sorters let unite.context.is_redraw = 1 return mode() ==# 'i' ? "a\" : "g\" endfunction"}}} function! unite#mappings#set_current_converters(converters) abort "{{{ let unite = unite#get_current_unite() let unite.current_converters = a:converters let unite.context.is_redraw = 1 return mode() ==# 'i' ? "a\" : "g\" endfunction"}}} function! unite#mappings#get_current_matchers() abort "{{{ return unite#get_current_unite().current_matchers endfunction"}}} function! unite#mappings#get_current_sorters() abort "{{{ return unite#get_current_unite().current_sorters endfunction"}}} function! unite#mappings#get_current_converters() abort "{{{ return unite#get_current_unite().current_converters endfunction"}}} function! s:smart_imap(map) abort "{{{ call s:clear_complete() if line('.') == b:unite.prompt_linenr \ && col('.') <= len(b:unite.context.prompt) return '' else return (line('.') != b:unite.prompt_linenr ? \ "\" . b:unite.prompt_linenr . 'Gzb$a' : '') . a:map endif endfunction"}}} function! s:smart_imap2(map) abort "{{{ call s:clear_complete() if line('.') == b:unite.prompt_linenr \ && col('.') >= col('$') return '' else return (line('.') != b:unite.prompt_linenr ? \ "\" . b:unite.prompt_linenr . 'Gzb$a' : '') . a:map endif endfunction"}}} function! s:do_new_candidate_action() abort "{{{ if empty(unite#helper#get_current_candidate()) " Get source name. if len(unite#get_sources()) != 1 call unite#print_error('No candidates and multiple sources.') return endif " Dummy candidate. let candidates = unite#init#_candidates_source([{}], \ unite#get_sources()[0].name) else let candidates = [unite#helper#get_current_candidate()] endif return unite#action#do('unite__new_candidate', candidates) endfunction"}}} " key-mappings functions. function! s:exit() abort "{{{ let context = unite#get_context() call unite#force_quit_session() if context.tab && winnr('$') == 1 && !context.temporary " Close window. close endif endfunction"}}} function! s:all_exit() abort "{{{ call unite#all_quit_session() endfunction"}}} function! s:restart() abort "{{{ let unite = unite#get_current_unite() let context = unite.context let context.resume = 0 let context.unite__is_restart = 1 let sources = map(deepcopy(unite.sources), \ 'empty(v:val.args) ? v:val.name : [v:val.name] + v:val.args') call unite#force_quit_session() call unite#start(sources, context) endfunction"}}} function! s:delete_backward_path() abort "{{{ let context = unite#get_context() if context.input != '' call unite#mappings#narrowing( \ substitute(context.input, '[^/ ]*.$', '', ''), 0) else let context.path = substitute(context.path, '[^/ ]*.$', '', '') call unite#redraw() endif endfunction"}}} function! s:toggle_mark(map) abort "{{{ call unite#helper#skip_prompt() let candidate = unite#helper#get_current_candidate() if empty(candidate) return endif if !get(candidate, 'is_dummy', 0) let candidate.unite__is_marked = !candidate.unite__is_marked let candidate.unite__marked_time = has('reltime') && has('float') ? \ str2float(reltimestr(reltime())) : localtime() call unite#view#_redraw_line() endif let context = unite#get_context() execute 'normal!' (a:map ==# 'j' && context.prompt_direction !=# 'below' \ || a:map ==# 'k' && context.prompt_direction ==# 'below') ? \ unite#mappings#cursor_down(1) : unite#mappings#cursor_up(1) endfunction"}}} function! s:toggle_mark_all_candidates() abort "{{{ call unite#view#_redraw_all_candidates() call s:toggle_mark_candidates(1, line('$')) endfunction"}}} function! s:toggle_mark_candidates(start, end) abort "{{{ if a:start < 0 " Ignore. return endif let unite = unite#get_current_unite() let pos = getpos('.') try call cursor(a:start, 1) let prev = -1 for _ in range(a:start, a:end) if line('.') == prev || line('.') < a:start || line('.') > a:end break endif let prev = line('.') if line('.') == unite.prompt_linenr call unite#helper#skip_prompt() else let context = unite#get_context() if context.prompt_direction ==# 'below' call s:toggle_mark('k') else call s:toggle_mark('j') endif endif endfor finally call setpos('.', pos) call unite#view#_bottom_cursor() endtry endfunction"}}} function! s:quick_help() abort "{{{ call unite#start_temporary([['mapping', bufnr('%')]], {}, 'mapping-help') endfunction"}}} function! s:choose_action() abort "{{{ let candidates = unite#helper#get_marked_candidates() if empty(candidates) if empty(unite#helper#get_current_candidate()) return endif let candidates = [ unite#helper#get_current_candidate() ] endif call unite#mappings#_choose_action(candidates) endfunction"}}} function! unite#mappings#_choose_action(candidates, ...) abort "{{{ call filter(a:candidates, \ '!has_key(v:val, "is_dummy") || !v:val.is_dummy') if empty(a:candidates) return endif let context = deepcopy(get(a:000, 0, {})) let context.source__sources = unite#init#_loaded_sources( \ unite#util#uniq(map(copy(a:candidates), \ 'v:val.source')), context) let context.buffer_name = 'action' let context.profile_name = 'action' let context.default_action = 'default' let context.start_insert = 1 let context.truncate = 1 call call((has_key(context, 'vimfiler__current_directory') \ || &filetype !=# 'unite' ? \ 'unite#start' : 'unite#start_temporary'), \ [[[unite#sources#action#define(), a:candidates]], context]) endfunction"}}} function! s:insert_enter(key) abort "{{{ setlocal modifiable let unite = unite#get_current_unite() return (line('.') != unite.prompt_linenr) ? \ (unite.context.prompt_focus ? \ unite.prompt_linenr.'GA' : 'gI') : \ (a:key == 'i' && col('.') <= 1 \ || a:key == 'a' && col('.') < 1) ? \ 'A' : \ a:key endfunction"}}} function! s:insert_enter2() abort "{{{ nnoremap (unite_insert_enter) \ insert_enter('i') nnoremap (unite_insert_head) \ insert_enter('A'. \ (repeat("\", len(substitute( \ unite#helper#get_input(), '.', 'x', 'g'))))) nnoremap (unite_append_enter) \ insert_enter('a') nnoremap (unite_append_end) \ insert_enter('A') setlocal modifiable " Restore prompt call unite#handlers#_on_insert_enter() let unite = unite#get_current_unite() call cursor(unite.init_prompt_linenr, 0) call unite#view#_bottom_cursor() startinsert! endfunction"}}} function! s:insert_leave() abort "{{{ call unite#helper#skip_prompt() endfunction"}}} function! s:redraw() abort "{{{ call unite#clear_message() call unite#force_redraw() endfunction"}}} function! s:rotate_source(is_next) abort "{{{ let unite = unite#get_current_unite() for _ in unite#loaded_sources_list() let unite.sources = a:is_next ? \ add(unite.sources[1:], unite.sources[0]) : \ insert(unite.sources[: -2], unite.sources[-1]) if !empty(unite.sources[0].unite__candidates) break endif endfor let unite.statusline = unite#view#_get_status_string(unite) let &l:statusline = unite.statusline call unite#view#_redraw_candidates() endfunction"}}} function! s:print_candidate() abort "{{{ let candidate = unite#helper#get_current_candidate() if empty(candidate) " Ignore. return endif echo 'abbr: ' . candidate.unite__abbr echo 'word: ' . candidate.word endfunction"}}} function! s:print_message_log() abort "{{{ for msg in unite#get_current_unite().msgs echohl Comment | echo msg | echohl None endfor for msg in unite#get_current_unite().err_msgs echohl WarningMsg | echo msg | echohl None endfor endfunction"}}} function! s:cursor_top() abort "{{{ let unite = unite#get_current_unite() if v:count == 0 execute 'normal!' (unite.prompt_linenr == 1 ? '2' : '') . 'gg0z.' else if v:count > len(unite.current_candidates) + (unite.prompt_linenr == 1) call unite#view#_redraw_all_candidates() endif execute 'normal!' v:count . 'gg0z.' endif endfunction"}}} function! s:cursor_bottom() abort "{{{ if v:count == 0 call unite#view#_redraw_all_candidates() normal! G else let unite = unite#get_current_unite() if v:count > len(unite.current_candidates) + (unite.prompt_linenr == 1) call unite#view#_redraw_all_candidates() endif execute 'normal!' v:count . 'G' endif endfunction"}}} function! s:insert_selected_candidate() abort "{{{ let candidate = unite#helper#get_current_candidate() if empty(candidate) " Ignore. return endif call unite#mappings#narrowing(candidate.word) endfunction"}}} function! unite#mappings#_quick_match(is_jump) abort "{{{ if !empty(unite#helper#get_marked_candidates()) call unite#util#print_error('Marked candidates is detected.') return endif let unite = unite#get_current_unite() let quick_match_table = s:get_quick_match_table() call unite#view#_quick_match_redraw(quick_match_table, 1) if mode() !~# '^c' echo 'Input quick match key: ' endif let char = '' while char == '' let char = nr2char(getchar()) endwhile redraw echo '' stopinsert call unite#view#_quick_match_redraw(quick_match_table, 0) let num = get(quick_match_table, char, -1) let candidate = unite#helper#get_current_candidate(num) if num < 0 || empty(candidate) call unite#util#print_error('Canceled.') if unite.context.quick_match && char == "\" call unite#force_quit_session() endif return endif if candidate.is_dummy call unite#util#print_error('Dummy.') return endif if a:is_jump call unite#view#_search_cursor(candidate) else call unite#action#do( \ unite.context.default_action, [candidate]) endif endfunction"}}} function! s:input_directory() abort "{{{ let path = unite#util#substitute_path_separator( \ input('Input narrowing directory: ', \ unite#helper#get_input(), 'dir')) let path = path.(path == '' || path =~ '/$' ? '' : '/') call unite#mappings#narrowing(path) endfunction"}}} function! unite#mappings#loop_cursor_up(mode) abort "{{{ " Loop. call unite#view#_redraw_all_candidates() if a:mode ==# 'i' noautocmd startinsert endif call cursor(line('$'), 1) endfunction"}}} function! unite#mappings#loop_cursor_down(mode) abort "{{{ " Loop. call unite#view#_redraw_all_candidates() if a:mode ==# 'i' noautocmd startinsert endif call cursor(1, 1) endfunction"}}} function! unite#mappings#cursor_up(is_skip_not_matched) abort "{{{ let is_insert = mode() ==# 'i' let prompt_linenr = unite#get_current_unite().prompt_linenr let num = line('.') - 1 let cnt = 1 let offset = prompt_linenr == 1 ? 1 : 0 if line('.') == prompt_linenr && g:unite_enable_auto_select let cnt += 1 endif while 1 let candidate = get(unite#get_unite_candidates(), num - offset - cnt, {}) if num >= cnt && !empty(candidate) && (candidate.is_dummy \ || (a:is_skip_not_matched && !candidate.is_matched)) let cnt += 1 continue endif break endwhile if is_insert return repeat("\", cnt) . \ (unite#helper#is_prompt(line('.') - cnt) ? "\" : "\") else return cnt == 1 ? 'k' : cnt.'k' endif endfunction"}}} function! unite#mappings#cursor_down(is_skip_not_matched) abort "{{{ let is_insert = mode() ==# 'i' let prompt_linenr = unite#get_current_unite().prompt_linenr let num = line('.') - 1 let cnt = 1 let offset = prompt_linenr == 1 ? 1 : 0 if line('.') == prompt_linenr && g:unite_enable_auto_select let cnt += 1 endif while 1 let candidate = get(unite#get_unite_candidates(), num - offset + cnt, {}) if !empty(candidate) && (candidate.is_dummy \ || (a:is_skip_not_matched && !candidate.is_matched)) let cnt += 1 continue endif break endwhile if is_insert return repeat("\", cnt) . \ (unite#helper#is_prompt(line('.') + cnt) ? "\" : "\") else return cnt == 1 ? 'j' : cnt.'j' endif endfunction"}}} function! s:smart_preview() abort "{{{ if b:unite.preview_candidate !=# \ unite#helper#get_current_candidate() call unite#view#_do_auto_preview() else call unite#view#_close_preview_window() endif call unite#view#_resize_window() endfunction"}}} function! s:toggle_transpose_window() abort "{{{ " Toggle vertical/horizontal view. let context = unite#get_context() let direction = context.vertical ? \ (context.direction ==# 'topleft' ? 'K' : 'J') : \ (context.direction ==# 'topleft' ? 'H' : 'L') execute 'silent wincmd ' . direction let context.vertical = !context.vertical endfunction"}}} function! s:toggle_auto_preview() abort "{{{ let unite = unite#get_current_unite() let context = unite#get_context() let context.auto_preview = !context.auto_preview let unite.preview_candidate = {} if context.auto_preview call unite#view#_do_auto_preview() elseif !context.auto_preview \ && !unite#get_current_unite().has_preview_window " Close preview window. call unite#view#_close_preview_window() endif call unite#view#_resize_window() endfunction"}}} function! s:toggle_auto_highlight() abort "{{{ let context = unite#get_context() let context.auto_highlight = !context.auto_highlight endfunction"}}} function! s:disable_max_candidates() abort "{{{ let unite = unite#get_current_unite() let unite.disabled_max_candidates = 1 call unite#force_redraw() call unite#view#_redraw_all_candidates() endfunction"}}} function! s:narrowing_input_history() abort "{{{ call unite#start_temporary( \ [unite#sources#history_input#define()], \ { 'old_source_names_string' : unite#loaded_source_names_string() }, \ 'history/input') endfunction"}}} function! s:narrowing_dot() abort "{{{ call unite#mappings#narrowing(unite#helper#get_input().'.') endfunction"}}} function! s:get_quick_match_table() abort "{{{ let unite = unite#get_current_unite() let offset = unite.context.prompt_direction ==# 'below' ? \ (unite.prompt_linenr == 0 ? \ line('$') - line('.') : \ unite.prompt_linenr - line('.') - 1) : \ line('.') if line('.') == unite.prompt_linenr let offset = (unite.context.prompt_direction ==# 'below' ? \ 0 : 2) elseif unite.context.prompt_direction ==# 'below' let offset = offset * -1 endif let table = deepcopy(g:unite_quick_match_table) if unite.context.prompt_direction ==# 'below' let max = len(unite.current_candidates) call map(table, 'max - v:val + offset') else for key in keys(table) let table[key] = unite#helper#get_current_candidate_linenr( \ table[key]+offset-1) endfor endif return table endfunction"}}} function! s:complete() abort "{{{ let unite = unite#get_current_unite() let input = matchstr(unite#get_input(), '\h\w*$') let cur_text = unite#get_input()[: -len(input)-1] if !has_key(unite, 'complete_cur_text') \ || cur_text !=# unite.complete_cur_text \ || index(unite.complete_candidates, input) < 0 " Recache let start = reltime() let unite.complete_candidates = \ unite#complete#gather(unite.current_candidates, input) echomsg string(reltimestr(reltime(start))) let unite.complete_candidate_num = 0 let unite.complete_cur_text = cur_text let unite.complete_input = input endif call unite#view#_redraw_echo(printf('match %d of %d : %s', \ unite.complete_candidate_num+1, len(unite.complete_candidates), \ join(unite.complete_candidates[unite.complete_candidate_num+1 : \ unite.complete_candidate_num + 10]))) let candidate = get(unite.complete_candidates, \ unite.complete_candidate_num, input) let unite.complete_candidate_num += 1 if unite.complete_candidate_num >= len(unite.complete_candidates) " Cycle let unite.complete_candidate_num = 0 endif return repeat("\", unite#util#strchars(input)) . candidate endfunction"}}} function! s:clear_complete() abort "{{{ let unite = unite#get_current_unite() if has_key(unite, 'complete_cur_text') call remove(unite, 'complete_cur_text') redraw echo '' endif return '' endfunction"}}} "}}} let &cpo = s:save_cpo unlet s:save_cpo " vim: foldmethod=marker