Skip to content

Commit 9cfa605

Browse files
committed
Simplify gf maps
Since we now force ".rb" into filenames in the common cases, we can go back to using :find without worrying about it opening a directory.
1 parent 2322c36 commit 9cfa605

1 file changed

Lines changed: 5 additions & 20 deletions

File tree

ftplugin/ruby.vim

Lines changed: 5 additions & 20 deletions
Original file line numberDiff line numberDiff line change
@@ -218,12 +218,11 @@ if !exists("g:no_plugin_maps") && !exists("g:no_ruby_maps")
218218
call s:map('c', '', '<C-R><C-W> <Plug><cword>')
219219
call s:map('c', '', '<C-R><C-F> <Plug><cfile>')
220220

221-
" By using findfile() rather than gf's normal behavior, we prevent
222-
" erroneously editing a directory.
223-
call s:silmap('n', 'gf :<C-U>exe <SID>gf(v:count1,"gf","edit")<CR>')
224-
call s:silmap('n', '<C-W>f :<C-U>exe <SID>gf(v:count1,"\<Lt>C-W>f","split")<CR>')
225-
call s:silmap('n', '<C-W><C-F> :<C-U>exe <SID>gf(v:count1,"\<Lt>C-W>\<Lt>C-F>","split")<CR>')
226-
call s:silmap('n', '<C-W>gf :<C-U>exe <SID>gf(v:count1,"\<Lt>C-W>gf","tabedit")<CR>')
221+
nmap <buffer><script> <SID>: :<C-U><C-R>=v:count ? v:count : ''<CR>
222+
call s:map('n', '<silent>', 'gf <SID>:find <Plug><cfile><CR>')
223+
call s:map('n', '<silent>', '<C-W>f <SID>:sfind <Plug><cfile><CR>')
224+
call s:map('n', '<silent>', '<C-W><C-F> <SID>:sfind <Plug><cfile><CR>')
225+
call s:map('n', '<silent>', '<C-W>gf <SID>:tabfind <Plug><cfile><CR>')
227226
endif
228227

229228
let &cpo = s:cpo_save
@@ -379,20 +378,6 @@ function! RubyCursorFile() abort
379378
return fnameescape(cfile)
380379
endfunction
381380

382-
function! s:gf(count,map,edit) abort
383-
let target = expand(RubyCursorFile())
384-
if target =~# '/$'
385-
let found = finddir(target, &path, a:count)
386-
else
387-
let found = findfile(target, &path, a:count)
388-
endif
389-
if found ==# ''
390-
return 'norm! '.a:count.a:map
391-
else
392-
return a:edit.' '.fnameescape(found)
393-
endif
394-
endfunction
395-
396381
"
397382
" Instructions for enabling "matchit" support:
398383
"

0 commit comments

Comments
 (0)