Last active
August 29, 2015 14:11
-
-
Save haya14busa/095db3036d6553c4a591 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
" call s:eval({expr}, {type}, {cmdline}) | |
function! s:eval(expr, type, cmdline) abort | |
return a:type is '/' | |
\ ? s:_eval_search(a:expr, a:cmdline) | |
\ : s:_eval_ex_cmd(a:expr, a:cmdline) | |
endfunction | |
function! s:_eval_ex_cmd(expr, cmdline) abort | |
exec printf( | |
\ "normal! :%s\<C-\>e%s\<CR>" . | |
\ "\<C-\>eescape(getcmdline(), '\"')\<CR>" . | |
\ "\<Home>let r = \"\<End>\"\<CR>" | |
\ , a:cmdline, a:expr) | |
return r | |
endfunction | |
function! s:_eval_search(expr, cmdline) abort | |
let save_pattern = @/ | |
let w = winsaveview() | |
try | |
exec printf("keepjumps normal! /%s\<C-\>e%s\<CR>\<CR>", a:cmdline, a:expr) | |
catch /E486/ | |
finally | |
nohlsearch | |
let @/ = save_pattern | |
call winrestview(w) | |
endtry | |
return s:hist_pop('/') | |
endfunction | |
function! s:hist_pop(type) abort | |
let r = histget(a:type, -1) | |
call histdel(a:type, -1) | |
return r | |
endfunction | |
function! EditCmdline() abort | |
return 'works? : ' . getcmdline() . ' | and type: ' . getcmdtype() | |
endfunction | |
let r = s:eval('EditCmdline()', '/', 'command line') | |
let s = s:eval('EditCmdline()', ':', 'command line') | |
let t = s:eval('"hi ''vim'' vim"', ':', 'command line') | |
let u = s:eval("'hi \"vim\" vim'", ':', 'command line') | |
echo '===' | |
echo r | " works? : command line | and type: / | |
echo s | " works? : command line | and type: : | |
echo t | " hi vim vim |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment