From d91315da8a22658d0a38a8d196dc57c60536e406 Mon Sep 17 00:00:00 2001 From: wsdjeg Date: Tue, 27 Dec 2016 22:52:31 +0800 Subject: [PATCH] Add mapping for gf --- autoload/zvim.vim | 69 +++++++++++++++++++++++++++++++++++++ config/mappings.vim | 1 + config/plugins/deoplete.vim | 1 + 3 files changed, 71 insertions(+) diff --git a/autoload/zvim.vim b/autoload/zvim.vim index 4ada5cf65..84635a564 100644 --- a/autoload/zvim.vim +++ b/autoload/zvim.vim @@ -36,3 +36,72 @@ function! zvim#format() abort normal! gg=G call setpos('.', save_cursor) endfunction + +function! zvim#gf() abort + if &filetype isnot# 'vim' + return 0 + endif + let isk = &l:iskeyword + setlocal iskeyword+=:,<,>,# + try + let line = getline('.') + let start = s:find_start(line, col('.')) + if line[start :] =~? '\%(s:\|\|\)' + let line = substitute(line, '<\%(SNR\|SID\)>', 's:', '') + let path = expand('%') + else + for base_dir in [getcwd()] + split(finddir('autoload', expand('%:p:h') . ';')) + [&runtimepath] + let path = s:autoload_path(base_dir, line[start : ]) + if !empty(path) + break + endif + endfor + endif + if !empty(path) + let line = s:search_line(path, matchstr(line[start :], '\k\+')) + let col = start + exe 'e ' . path + call cursor(line, col) + endif + finally + let &l:iskeyword = isk + endtry +endfunction + + +if has('patch-7.4.279') + function! s:globpath(path, expr) abort "{{{ + return globpath(a:path, a:expr, 1, 1) + endfunction "}}} +else + function! s:globpath(path, expr) abort "{{{ + return split(globpath(a:path, a:expr), '\n') + endfunction "}}} +endif + + +function! s:autoload_path(base_dir, function_name) abort "{{{ + let match = matchstr(a:function_name, '\k\+\ze#') + let fname = expand('autoload/' . substitute(match, '#', '/', 'g') . '.vim') + let paths = s:globpath(a:base_dir, fname) + return len(paths) > 0 ? paths[0] : '' +endfunction "}}} + + +function! s:find_start(line, cursor_index) abort "{{{ + for i in range(a:cursor_index, 0, -1) + if a:line[i] !~# '\k' + return i+1 + endif + endfor + return 0 +endfunction "}}} + + +function! s:search_line(path, term) abort "{{{ + let line = match(readfile(a:path), '\s*fu\%[nction]!\?\s*' . a:term . '\>') + if line >= 0 + return line+1 + endif + return 0 +endfunction "}}} diff --git a/config/mappings.vim b/config/mappings.vim index 8c25933c2..170d5b26b 100644 --- a/config/mappings.vim +++ b/config/mappings.vim @@ -237,3 +237,4 @@ call zvim#util#defineMap('nnoremap ', 'sv', ':split:wincmd p \'Open previous buffer in split window' , 'split|wincmd p|e#') call zvim#util#defineMap('nnoremap ', 'sg', ':vsplit:wincmd p:e#', \'Open previous buffer in vsplit window' , 'vsplit|wincmd p|e#') +call zvim#util#defineMap('nnoremap ', 'gf', ':call zvim#gf()', 'Jump to a file under cursor', '') diff --git a/config/plugins/deoplete.vim b/config/plugins/deoplete.vim index c514240e0..70bfa5afc 100644 --- a/config/plugins/deoplete.vim +++ b/config/plugins/deoplete.vim @@ -22,6 +22,7 @@ else call deoplete#custom#set('omni', 'mark', '') endif call deoplete#custom#set('_', 'matchers', ['matcher_full_fuzzy']) +let g:deoplete#ignore_sources._ = ['around'] "call deoplete#custom#set('omni', 'min_pattern_length', 0) inoremap deoplete#mappings#smart_close_popup()."\" inoremap deoplete#mappings#smart_close_popup()."\"