Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add an option to open commands in different ways (:Helptags, :Manpages) #1520

Open
wants to merge 2 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -85,6 +85,7 @@ Commands
| `:Commands` | Commands |
| `:Maps` | Normal mode mappings |
| `:Helptags` | Help tags <sup id="a1">[1](#helptags)</sup> |
| `:Manpages` | Man pages |
| `:Filetypes` | File types

- Most commands support `CTRL-T` / `CTRL-X` / `CTRL-V` key
Expand Down
42 changes: 38 additions & 4 deletions autoload/fzf/vim.vim
Original file line number Diff line number Diff line change
Expand Up @@ -379,6 +379,16 @@ function! s:action_for(key, ...)
endif
endfunction

let s:default_cmd_mod = {
\ 'ctrl-t': 'tab',
\ 'ctrl-x': 'horizontal',
\ 'ctrl-v': 'vertical' }

function! s:cmd_mod_for(key)
let mod = get(get(g:, 'fzf_cmd_mod', s:default_cmd_mod), a:key, '')
return type(mod) == s:TYPE.string ? mod : ''
endfunction

function! s:open(target)
if fnamemodify(a:target, ':p') ==# expand('%:p')
return
Expand Down Expand Up @@ -1330,13 +1340,16 @@ endfunction
" ------------------------------------------------------------------
" Help tags
" ------------------------------------------------------------------
function! s:helptag_sink(line)
let [tag, file, path] = split(a:line, "\t")[0:2]
function! s:helptag_sink(lines)
if len(a:lines) < 2
return
endif
let [tag, file, path] = split(a:lines[1], "\t")[0:2]
let rtp = fnamemodify(path, ':p:h:h')
if stridx(&rtp, rtp) < 0
execute 'set rtp+='.s:escape(rtp)
endif
execute 'help' tag
execute s:cmd_mod_for(a:lines[0]) 'help' tag
endfunction

function! fzf#vim#helptags(...)
Expand All @@ -1354,10 +1367,31 @@ function! fzf#vim#helptags(...)
call writefile(['for my $filename (@ARGV) { open(my $file,q(<),$filename) or die; while (<$file>) { /(.*?)\t(.*?)\t(.*)/; push @lines, sprintf(qq('.s:green('%-40s', 'Label').'\t%s\t%s\t%s\n), $1, $2, $filename, $3); } close($file) or die; } print for sort @lines;'], s:helptags_script)
return s:fzf('helptags', {
\ 'source': 'perl '.fzf#shellescape(s:helptags_script).' '.join(map(tags, 'fzf#shellescape(v:val)')),
\ 'sink': s:function('s:helptag_sink'),
\ 'sink*': s:function('s:helptag_sink'),
\ 'options': ['--ansi', '+m', '--tiebreak=begin', '--with-nth', '..3']}, a:000)
endfunction

" ------------------------------------------------------------------
" Man pages
" ------------------------------------------------------------------
function! s:manpage_sink(lines)
if len(a:lines) < 2
return
endif
let [page, section] = split(a:lines[1])[0:1]
if exists(":Man") != 2
runtime ftplugin/man.vim
endif
execute s:cmd_mod_for(a:lines[0]) 'Man' section[1:-2] page
endfunction

function! fzf#vim#manpages(...)
return s:fzf('manpages', {
\ 'source': 'man --apropos .',
\ 'sink*': s:function('s:manpage_sink'),
\ 'options': ['--preview', 'man {1}', '--prompt=Man>']}, a:000)
endfunction

" ------------------------------------------------------------------
" File types
" ------------------------------------------------------------------
Expand Down
1 change: 1 addition & 0 deletions doc/fzf-vim.txt
Original file line number Diff line number Diff line change
Expand Up @@ -136,6 +136,7 @@ COMMANDS *fzf-vim-commands*
`:Commands` | Commands
`:Maps` | Normal mode mappings
`:Helptags` | Help tags [1]
`:Manpages` | Man pages
`:Filetypes` | File types
-----------------------+--------------------------------------------------------------------------------------

Expand Down
1 change: 1 addition & 0 deletions plugin/fzf.vim
Original file line number Diff line number Diff line change
Expand Up @@ -70,6 +70,7 @@ call s:defs([
\'command! -bar -bang Marks call fzf#vim#marks(<bang>0)',
\'command! -bar -bang Changes call fzf#vim#changes(<bang>0)',
\'command! -bar -bang Helptags call fzf#vim#helptags(fzf#vim#with_preview({ "placeholder": "--tag {2}:{3}:{4}" }), <bang>0)',
\'command! -bar -bang Manpages call fzf#vim#manpages(<bang>0)',
\'command! -bar -bang Windows call fzf#vim#windows(fzf#vim#with_preview({ "placeholder": "{2}" }), <bang>0)',
\'command! -bar -bang -nargs=* -range=% -complete=file Commits let b:fzf_winview = winsaveview() | <line1>,<line2>call fzf#vim#commits(<q-args>, fzf#vim#with_preview({ "placeholder": "" }), <bang>0)',
\'command! -bar -bang -nargs=* -range=% BCommits let b:fzf_winview = winsaveview() | <line1>,<line2>call fzf#vim#buffer_commits(<q-args>, fzf#vim#with_preview({ "placeholder": "" }), <bang>0)',
Expand Down