"============================================================================= " FILE: term_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. " }}} "============================================================================= function! vimshell#term_mappings#define_default_mappings() abort "{{{ " Plugin key-mappings. "{{{ nnoremap (vimshell_term_interrupt) \ :call vimshell#interactive#hang_up(bufname('%')) nnoremap (vimshell_term_exit) \ :call vimshell#interactive#quit_buffer() nnoremap (vimshell_term_start_insert) \ :call start_insert() nnoremap (vimshell_term_execute_line) \ :call execute_line() inoremap (vimshell_term_send_escape) \ vimshell#term_mappings#send_key("\") inoremap (vimshell_term_send_input) \ :call vimshell#interactive#send_input() "}}} for lhs in [ \ 'a', 'b', 'c', 'd', 'e', 'f', 'g', 'h', 'i', 'j', 'k', 'l', 'm', 'n', \ 'o', 'p', 'q', 'r', 's', 't', 'u', 'v', 'w', 'x', 'y', 'z', \ 'A', 'B', 'C', 'D', 'E', 'F', 'G', 'H', 'I', 'J', 'K', 'L', 'M', 'N', \ 'O', 'P', 'Q', 'R', 'S', 'T', 'U', 'V', 'W', 'X', 'Y', 'Z', \ '1', '2', '3', '4', '5', '6', '7', '8', '9', '0', \ '!', '@', '#', '$', '^', '&', '*', '(', ')', \ '-', '_', '=', '+', '\', '`', '~', \ '[', ']', '{', '}', ':', ';', '''', '"', ',', '<', '.', '>', '/', '?', \ ] execute 'inoremap ' lhs \ 'vimshell#term_mappings#send_key('. string(lhs) .')' "execute 'inoremap ' lhs printf(':call vimshell#interactive#send_char(%s)', char2nr(lhs)) endfor for [key, value] in items({ \ '' : "\", '' : "\", '' : "\", \ '' : "\", '' : "\", '' : "\", \ '' : "\", '' : "\", '' : "\", \ '' : "\", '' : "\", '' : "\", \ '' : "\", '' : "\", '' : "\", \ '' : "\", '' : "\", '' : "\", \ '' : "\", '' : "\", '' : "\", \ '' : "\", '' : "\", '' : "\", \ '' : "\", '' : "\", \ '' : "\", '' : "\", '' : "\", \ '' : '|', '' : ' ', \ }) execute 'inoremap ' key \ printf(':call vimshell#interactive#send_char(%s)', char2nr(value)) endfor for [key, value] in items({ \ '' : "\OH", '' : "\OF", \ '' : "\[3~", '' : "\", \ '' : "\[A", '' : "\[B", \ '' : "\[D", '' : "\[C", \ '' : "\[5~", '' : "\[6~", \ '' : "\[11~", '' : "\[12~", \ '' : "\[13~", '' : "\[14~", \ '' : "\[15~", '' : "\[17~", \ '' : "\[18~", '' : "\[19~", \ '' : "\[20~", '' : "\[21~", \ '' : "\[23~", '' : "\[24~", \ '' : "\[2~", \ }) execute 'inoremap ' key \ printf(':call vimshell#interactive#send_char(%s)', \ string(map(split(value, '\zs'), 'char2nr(v:val)'))) endfor if exists('g:vimshell_no_default_keymappings') \ && g:vimshell_no_default_keymappings return endif " Normal mode key-mappings. nmap (vimshell_term_interrupt) nmap q (vimshell_term_exit) nmap i (vimshell_term_start_insert) nmap I (vimshell_term_start_insert) nmap a (vimshell_term_start_insert) nmap A (vimshell_term_start_insert) nmap (vimshell_term_execute_line) " Insert mode key-mappings. imap (vimshell_term_send_escape) imap imap (vimshell_term_send_input) endfunction"}}} function! vimshell#term_mappings#send_key(key) abort "{{{ return printf("\:call vimshell#interactive#send_char(%s)\", char2nr(a:key)) endfunction"}}} function! vimshell#term_mappings#send_keys(keys) abort "{{{ return printf("\:call vimshell#interactive#send_char(%s)\", string(map(split(a:keys, '\zs'), 'char2nr(v:val)'))) endfunction"}}} " vimshell interactive key-mappings functions. function! s:start_insert() abort "{{{ setlocal modifiable startinsert endfunction "}}} function! s:execute_line() abort "{{{ " Search cursor file. let filename = unite#util#substitute_path_separator(substitute( \ expand(''), ' ', '\\ ', 'g')) " Convert encoding. let filename = vimproc#util#iconv(filename, &encoding, 'char') " Execute cursor file. if filename =~ '^\%(https\?\|ftp\)://' " Open uri. call vimshell#open(filename) return endif endfunction"}}} " vim: foldmethod=marker