├── .gitignore ├── Makefile ├── ftplugin ├── css_viewdoc.vim ├── man_viewdoc.vim ├── perl_viewdoc.vim ├── ri_rdoc_viewdoc.vim ├── tex_viewdoc.vim ├── perldoc_text_viewdoc.vim ├── ri_markdown_viewdoc.vim ├── vim_viewdoc.vim ├── help_viewdoc.vim ├── make_viewdoc.vim ├── pman_viewdoc.vim ├── infman_viewdoc.vim ├── ri_ansi_viewdoc.vim └── perldoc_ansi_viewdoc.vim ├── plugin ├── viewdoc_bashhelp.vim ├── viewdoc_ri.vim ├── viewdoc_pydoc.vim ├── viewdoc_infman.vim ├── viewdoc_man.vim ├── viewdoc_pman.vim ├── viewdoc_help.vim ├── viewdoc_godoc.vim ├── viewdoc_perldoc.vim ├── viewdoc_info.vim └── viewdoc.vim ├── syntax └── info.vim ├── README.asciidoc └── doc └── viewdoc.txt /.gitignore: -------------------------------------------------------------------------------- 1 | *.vba 2 | *.vmb 3 | *.zip 4 | -------------------------------------------------------------------------------- /Makefile: -------------------------------------------------------------------------------- 1 | 2 | all: dist 3 | 4 | dist: clean 5 | find */ -type f -not -name tags > files.lst 6 | vim -c "%MkVimball! $$(basename $$(pwd)) ." -c 'q!' files.lst 7 | 7z a $$(basename $$(pwd)).zip @files.lst 8 | rm -f files.lst 9 | 10 | clean: 11 | rm -f $$(basename $$(pwd)).{vba,vmb,zip} 12 | -------------------------------------------------------------------------------- /ftplugin/css_viewdoc.vim: -------------------------------------------------------------------------------- 1 | if exists('b:did_ftplugin_viewdoc') 2 | finish 3 | endif 4 | let b:did_ftplugin_viewdoc = 1 5 | 6 | 7 | setlocal iskeyword+=- 8 | 9 | 10 | let b:undo_ftplugin = exists('b:undo_ftplugin') ? b:undo_ftplugin . '|' : '' 11 | let b:undo_ftplugin .= 'setlocal iskeyword<' 12 | \ . '|unlet b:did_ftplugin_viewdoc' 13 | -------------------------------------------------------------------------------- /ftplugin/man_viewdoc.vim: -------------------------------------------------------------------------------- 1 | if exists('b:did_ftplugin_viewdoc') 2 | finish 3 | endif 4 | let b:did_ftplugin_viewdoc = 1 5 | 6 | 7 | setlocal iskeyword+=(,) 8 | 9 | 10 | let b:undo_ftplugin = exists('b:undo_ftplugin') ? b:undo_ftplugin . '|' : '' 11 | let b:undo_ftplugin .= 'setlocal iskeyword<' 12 | \ . '|unlet b:did_ftplugin_viewdoc' 13 | -------------------------------------------------------------------------------- /ftplugin/perl_viewdoc.vim: -------------------------------------------------------------------------------- 1 | if exists('b:did_ftplugin_viewdoc') 2 | finish 3 | endif 4 | let b:did_ftplugin_viewdoc = 1 5 | 6 | 7 | setlocal iskeyword+=: 8 | 9 | 10 | let b:undo_ftplugin = exists('b:undo_ftplugin') ? b:undo_ftplugin . '|' : '' 11 | let b:undo_ftplugin .= 'setlocal iskeyword<' 12 | \ . '|unlet b:did_ftplugin_viewdoc' 13 | -------------------------------------------------------------------------------- /ftplugin/ri_rdoc_viewdoc.vim: -------------------------------------------------------------------------------- 1 | if exists('b:did_ftplugin_viewdoc') 2 | finish 3 | endif 4 | let b:did_ftplugin_viewdoc = 1 5 | 6 | 7 | setlocal syntax=rdoc 8 | 9 | 10 | let b:undo_ftplugin = exists('b:undo_ftplugin') ? b:undo_ftplugin . '|' : '' 11 | let b:undo_ftplugin .= 'setlocal syntax<' 12 | \ . '|unlet b:did_ftplugin_viewdoc' 13 | -------------------------------------------------------------------------------- /ftplugin/tex_viewdoc.vim: -------------------------------------------------------------------------------- 1 | if exists('b:did_ftplugin_viewdoc') 2 | finish 3 | endif 4 | let b:did_ftplugin_viewdoc = 1 5 | 6 | 7 | setlocal iskeyword+=\\ 8 | 9 | 10 | let b:undo_ftplugin = exists('b:undo_ftplugin') ? b:undo_ftplugin . '|' : '' 11 | let b:undo_ftplugin .= 'setlocal iskeyword<' 12 | \ . '|unlet b:did_ftplugin_viewdoc' 13 | -------------------------------------------------------------------------------- /ftplugin/perldoc_text_viewdoc.vim: -------------------------------------------------------------------------------- 1 | if exists('b:did_ftplugin_viewdoc') 2 | finish 3 | endif 4 | let b:did_ftplugin_viewdoc = 1 5 | 6 | 7 | setlocal iskeyword+=: 8 | 9 | 10 | let b:undo_ftplugin = exists('b:undo_ftplugin') ? b:undo_ftplugin . '|' : '' 11 | let b:undo_ftplugin .= 'setlocal iskeyword<' 12 | \ . '|unlet b:did_ftplugin_viewdoc' 13 | -------------------------------------------------------------------------------- /ftplugin/ri_markdown_viewdoc.vim: -------------------------------------------------------------------------------- 1 | if exists('b:did_ftplugin_viewdoc') 2 | finish 3 | endif 4 | let b:did_ftplugin_viewdoc = 1 5 | 6 | 7 | setlocal syntax=markdown 8 | 9 | 10 | let b:undo_ftplugin = exists('b:undo_ftplugin') ? b:undo_ftplugin . '|' : '' 11 | let b:undo_ftplugin .= 'setlocal syntax<' 12 | \ . '|unlet b:did_ftplugin_viewdoc' 13 | -------------------------------------------------------------------------------- /ftplugin/vim_viewdoc.vim: -------------------------------------------------------------------------------- 1 | if exists('b:did_ftplugin_viewdoc') 2 | finish 3 | endif 4 | let b:did_ftplugin_viewdoc = 1 5 | 6 | 7 | setlocal iskeyword+=:,\<,\>,- 8 | 9 | 10 | let b:undo_ftplugin = exists('b:undo_ftplugin') ? b:undo_ftplugin . '|' : '' 11 | let b:undo_ftplugin .= 'setlocal iskeyword<' 12 | \ . '|unlet b:did_ftplugin_viewdoc' 13 | -------------------------------------------------------------------------------- /ftplugin/help_viewdoc.vim: -------------------------------------------------------------------------------- 1 | if exists('b:did_ftplugin_viewdoc') 2 | finish 3 | endif 4 | let b:did_ftplugin_viewdoc = 1 5 | 6 | 7 | setlocal iskeyword=!-~,^*,^\|,^\",192-255 8 | 9 | 10 | let b:undo_ftplugin = exists('b:undo_ftplugin') ? b:undo_ftplugin . '|' : '' 11 | let b:undo_ftplugin .= 'setlocal iskeyword<' 12 | \ . '|unlet b:did_ftplugin_viewdoc' 13 | -------------------------------------------------------------------------------- /ftplugin/make_viewdoc.vim: -------------------------------------------------------------------------------- 1 | if exists('b:did_ftplugin_viewdoc') 2 | finish 3 | endif 4 | let b:did_ftplugin_viewdoc = 1 5 | 6 | 7 | setlocal iskeyword+=.,@-@,%,<,?,+,\|,*,^ 8 | 9 | 10 | let b:undo_ftplugin = exists('b:undo_ftplugin') ? b:undo_ftplugin . '|' : '' 11 | let b:undo_ftplugin .= 'setlocal iskeyword<' 12 | \ . '|unlet b:did_ftplugin_viewdoc' 13 | -------------------------------------------------------------------------------- /ftplugin/pman_viewdoc.vim: -------------------------------------------------------------------------------- 1 | if exists('b:did_ftplugin_viewdoc') 2 | finish 3 | endif 4 | let b:did_ftplugin_viewdoc = 1 5 | 6 | 7 | setlocal iskeyword+=(,) 8 | setlocal syntax=man 9 | 10 | 11 | let b:undo_ftplugin = exists('b:undo_ftplugin') ? b:undo_ftplugin . '|' : '' 12 | let b:undo_ftplugin .= 'setlocal iskeyword< syntax<' 13 | \ . '|unlet b:did_ftplugin_viewdoc' 14 | -------------------------------------------------------------------------------- /ftplugin/infman_viewdoc.vim: -------------------------------------------------------------------------------- 1 | if exists('b:did_ftplugin_viewdoc') 2 | finish 3 | endif 4 | let b:did_ftplugin_viewdoc = 1 5 | 6 | 7 | setlocal iskeyword+=(,) 8 | setlocal syntax=man 9 | 10 | 11 | let b:undo_ftplugin = exists('b:undo_ftplugin') ? b:undo_ftplugin . '|' : '' 12 | let b:undo_ftplugin .= 'setlocal iskeyword< syntax<' 13 | \ . '|unlet b:did_ftplugin_viewdoc' 14 | -------------------------------------------------------------------------------- /ftplugin/ri_ansi_viewdoc.vim: -------------------------------------------------------------------------------- 1 | if exists('b:did_ftplugin_viewdoc') 2 | finish 3 | endif 4 | let b:did_ftplugin_viewdoc = 1 5 | 6 | 7 | if exists(':AnsiEsc') 8 | if exists('b:ansiesc') 9 | AnsiEsc 10 | endif 11 | AnsiEsc 12 | let b:ansiesc = 1 13 | else 14 | echomsg 'Require Improved AnsiEsc http://www.vim.org/scripts/script.php?script_id=4979' 15 | endif 16 | 17 | 18 | let b:undo_ftplugin = exists('b:undo_ftplugin') ? b:undo_ftplugin . '|' : '' 19 | let b:undo_ftplugin .= '' 20 | \ . '|unlet b:did_ftplugin_viewdoc' 21 | -------------------------------------------------------------------------------- /ftplugin/perldoc_ansi_viewdoc.vim: -------------------------------------------------------------------------------- 1 | if exists('b:did_ftplugin_viewdoc') 2 | finish 3 | endif 4 | let b:did_ftplugin_viewdoc = 1 5 | 6 | 7 | setlocal iskeyword+=: 8 | if exists(':AnsiEsc') 9 | if exists('b:ansiesc') 10 | AnsiEsc 11 | endif 12 | AnsiEsc 13 | let b:ansiesc = 1 14 | else 15 | echomsg 'Require Improved AnsiEsc http://www.vim.org/scripts/script.php?script_id=4979' 16 | endif 17 | 18 | 19 | let b:undo_ftplugin = exists('b:undo_ftplugin') ? b:undo_ftplugin . '|' : '' 20 | let b:undo_ftplugin .= 'setlocal iskeyword<' 21 | \ . '|unlet b:did_ftplugin_viewdoc' 22 | -------------------------------------------------------------------------------- /plugin/viewdoc_bashhelp.vim: -------------------------------------------------------------------------------- 1 | " Maintainer: see in viewdoc.vim 2 | " Version: see in viewdoc.vim 3 | " Last Modified: see in viewdoc.vim 4 | " License: see in viewdoc.vim 5 | " URL: see in viewdoc.vim 6 | " Description: ViewDoc handler for shell scripts 7 | 8 | if exists('g:loaded_viewdoc_bash') || &cp || v:version < 700 9 | finish 10 | endif 11 | let g:loaded_viewdoc_bash = 1 12 | 13 | """ Interface 14 | " - command 15 | command -bar -bang -nargs=1 ViewDocBashHelp 16 | \ call ViewDoc(''=='' ? 'new' : 'doc', , 'bashhelp') 17 | " - abbrev 18 | if !exists('g:no_plugin_abbrev') && !exists('g:no_viewdoc_abbrev') 19 | cnoreabbrev bashhelp getcmdtype()==':' && getcmdline()=='bashhelp' ? 'ViewDocBashHelp' : 'bashhelp' 20 | cnoreabbrev bashhelp! getcmdtype()==':' && getcmdline()=='bashhelp!' ? 'ViewDocBashHelp' : 'bashhelp!' 21 | endif 22 | 23 | """ Handlers 24 | 25 | " let h = ViewDoc_bashhelp('echo') 26 | function s:ViewDoc_bashhelp(topic, ...) 27 | return { 'cmd': printf('bash -c "help -m %s" 2>/dev/null', shellescape(a:topic,1)), 28 | \ 'ft': 'man', 29 | \ } 30 | endfunction 31 | 32 | " use function(s:SID().'Foo') instead of function('s:Foo') for 33 | " compatibility with Vim-7.3.x (7.3.762 at least) 34 | function s:SID() 35 | return matchstr(expand(''), '\zs\d\+_\zeSID$') 36 | endfunction 37 | let g:ViewDoc_bashhelp = function(s:SID().'ViewDoc_bashhelp') 38 | let g:ViewDoc_sh = [ g:ViewDoc_bashhelp, 'ViewDoc_man' ] 39 | 40 | -------------------------------------------------------------------------------- /syntax/info.vim: -------------------------------------------------------------------------------- 1 | " Syntax file for output of GNU info, inspired by 2 | " http://www.vim.org/scripts/script.php?script_id=21 3 | " 4 | " Author: pawel.wiecek@tieto.com 5 | 6 | " For version 5.x: Clear all syntax items 7 | " For version 6.x: Quit when a syntax file was already loaded 8 | if version < 600 9 | syntax clear 10 | elseif exists("b:current_syntax") 11 | finish 12 | endif 13 | 14 | syn case match 15 | syn match infoTopNav /^File: .*\.info, Node: [^,]*,.*$/ contains=infoNavLink 16 | syn match infoMenuTitle /^\* Menu:/hs=s+2,he=e-1 17 | syn match infoTitle /^[A-Z][0-9A-Za-z `',/&]\{,43}\([a-z']\|[A-Z]\{2}\)$/ 18 | syn match infoTitle /^[-=*]\{,45}$/ 19 | syn match infoString /`[^`']*'/ 20 | syn match infoLinkMenu /^\* [^:]*::/hs=s+2 21 | syn match infoLinkDir /^\* [^:]*: ([^)]*)[^.]*\./hs=s+2,he=e-1 contains=infoDirTarget 22 | syn match infoLinkIndex /^\* [^:]*:\s*[^.]*\.[ \t\n]*(line\s\+[0-9]\+)$/hs=s+2 contains=infoIndexTarget,infoIndexLine 23 | syn region infoLinkNote start=/\*[Nn]ote/ end=/\(::\|[.,]\)/ contains=infoNoteNote 24 | syn match infoNavLink contained /\(Prev\|Next\|Up\): \zs[^,]*/ 25 | syn match infoDirTarget contained /: ([^)]*)[^.]*\./hs=s+1,he=e-1 26 | syn match infoIndexTarget contained /:\s*.\+\./hs=s+1,he=e-1 27 | syn region infoIndexLine contained start=/(line/ end=/)$/ 28 | syn match infoNoteNote contained /\*[Nn]ote/hs=s+1 29 | 30 | hi def link infoMenuTitle Title 31 | hi def link infoTitle Comment 32 | hi def link infoNavLink Directory 33 | hi def link infoLinkMenu Directory 34 | hi def link infoLinkDir Directory 35 | hi def link infoLinkIndex Directory 36 | hi def link infoLinkNote Directory 37 | hi def link infoString String 38 | hi def link infoDirTarget Keyword 39 | hi def link infoIndexTarget Keyword 40 | hi def link infoIndexLine Identifier 41 | hi def link infoNoteNote Keyword 42 | 43 | let b:current_syntax = "info" 44 | -------------------------------------------------------------------------------- /plugin/viewdoc_ri.vim: -------------------------------------------------------------------------------- 1 | " Maintainer: see in viewdoc.vim 2 | " Version: see in viewdoc.vim 3 | " Last Modified: see in viewdoc.vim 4 | " License: see in viewdoc.vim 5 | " URL: see in viewdoc.vim 6 | " Description: ViewDoc handler for ri 7 | 8 | if exists('g:loaded_viewdoc_ri') || &cp || v:version < 700 9 | finish 10 | endif 11 | let g:loaded_viewdoc_ri = 1 12 | 13 | 14 | """ Options 15 | if !exists('g:viewdoc_ri_cmd') 16 | let g:viewdoc_ri_cmd='ri' " user may want 'ri20' 17 | endif 18 | if !exists('g:viewdoc_ri_format') 19 | let g:viewdoc_ri_format='markdown' " user may want 'rdoc' 20 | endif 21 | 22 | """ Interface 23 | " - command 24 | command -bar -bang -nargs=1 ViewDocRi 25 | \ call ViewDoc(''=='' ? 'new' : 'doc', , 'ri') 26 | " - abbrev 27 | if !exists('g:no_plugin_abbrev') && !exists('g:no_viewdoc_abbrev') 28 | cnoreabbrev rdoc getcmdtype()==':' && getcmdline()=='rdoc' ? 'ViewDocRi' : 'rdoc' 29 | cnoreabbrev rdoc! getcmdtype()==':' && getcmdline()=='rdoc!' ? 'ViewDocRi' : 'rdoc!' 30 | endif 31 | 32 | """ Handlers 33 | 34 | function s:ViewDoc_ri(topic, ...) 35 | return { 'cmd': printf('%s --format=%s %s | grep -v "Nothing known about"', g:viewdoc_ri_cmd, g:viewdoc_ri_format, shellescape(a:topic,1)), 36 | \ 'ft': 'ri_'.g:viewdoc_ri_format, 37 | \ } 38 | endfunction 39 | 40 | " use function(s:SID().'Foo') instead of function('s:Foo') for 41 | " compatibility with Vim-7.3.x (7.3.762 at least) 42 | function s:SID() 43 | return matchstr(expand(''), '\zs\d\+_\zeSID$') 44 | endfunction 45 | let g:ViewDoc_ri = function(s:SID().'ViewDoc_ri') 46 | let g:ViewDoc_ruby = function(s:SID().'ViewDoc_ri') 47 | let g:ViewDoc_ri_bs = function(s:SID().'ViewDoc_ri') 48 | let g:ViewDoc_ri_ansi = function(s:SID().'ViewDoc_ri') 49 | let g:ViewDoc_ri_rdoc = function(s:SID().'ViewDoc_ri') 50 | let g:ViewDoc_ri_markdown = function(s:SID().'ViewDoc_ri') 51 | -------------------------------------------------------------------------------- /README.asciidoc: -------------------------------------------------------------------------------- 1 | viewdoc 2 | ======= 3 | 4 | == Description 5 | 6 | Flexible viewer for any documentation source (help/man/perldoc/etc.) for 7 | any file type inside Vim in easy to use, consistent, smart and 8 | configurable way. 9 | 10 | * You can configure how (keys/commands) documentation will be open. By default it will replace standard mapping for key `K` and command `:help` plus add mapping for `` key and new commands `:man`, `:doc`, etc. 11 | * You can configure where (buffer/window/tab) documentation will be open. Can open new docs in one dedicated (`K`) or new (``) buffer/window/tab. Support all work styles: 12 | - full screen (no tabs, one window, open files/docs are in hidden buffers), 13 | - windowed (no tabs, many windows with open files/docs), 14 | - tabbed full screen (many tabs, each with one window, open files/docs are in different tabs), 15 | - tabbed (many tabs with many windows inside tabs). 16 | * You can easily navigate to next/previous topic while viewing documentation using `` and `` (or alternative keys `` and ``), just like you use tags for navigation within source code and Vim's help. 17 | * Even closing documentation buffer/window/tab is easier, smarter and more configurable than ever before. :) 18 | * Smart detection of documentation source and topic when opening documentation for `` (word under cursor) - can use current syntax highlight (to find topic's context) and surrounding text (when topic doesn't include important special symbols because of 'iskeyword' value). 19 | * Smart completion for available documentation topics when opening documentation using command (just like Vim's :help command works). (Some documentation sources may not support this.) 20 | * Supported documentation sources: 21 | - man pages 22 | - Vim's help 23 | - custom documentation in vim help format: (CSS 2.1, CMake, LaTeX, …) 24 | - perldoc 25 | - godoc 26 | - pydoc (python) 27 | - pman (php) 28 | - OS Inferno man pages 29 | - ri (ruby) 30 | - bash's help 31 | - GNU info (smart support for: awk, make, m4, automake) 32 | * Support for new documentation sources and file types can be easily added by external plugins or within ~/.vimrc file. 33 | * You can have several documentation sources for same file type, and choose which one should be used on-the-fly. 34 | * Can be used as console man page viewer instead of `/usr/bin/man`. 35 | 36 | Tested only in Linux, but should work in any `*NIX`. 37 | 38 | Download .zip/.vmb from http://www.vim.org/scripts/script.php?script_id=3893 39 | -------------------------------------------------------------------------------- /plugin/viewdoc_pydoc.vim: -------------------------------------------------------------------------------- 1 | " Maintainer: see in viewdoc.vim 2 | " Version: see in viewdoc.vim 3 | " Last Modified: see in viewdoc.vim 4 | " License: see in viewdoc.vim 5 | " URL: see in viewdoc.vim 6 | " Description: ViewDoc handler for pydoc 7 | 8 | if exists('g:loaded_viewdoc_pydoc') || &cp || v:version < 700 9 | finish 10 | endif 11 | let g:loaded_viewdoc_pydoc = 1 12 | 13 | 14 | """ Options 15 | if !exists('g:viewdoc_pydoc_cmd') 16 | let g:viewdoc_pydoc_cmd='pydoc' " user may want 'pydoc3.2' 17 | endif 18 | 19 | """ Interface 20 | " - command 21 | command -bar -bang -nargs=1 -complete=custom,s:CompletePydoc ViewDocPydoc 22 | \ call ViewDoc(''=='' ? 'new' : 'doc', , 'pydoc') 23 | " - abbrev 24 | if !exists('g:no_plugin_abbrev') && !exists('g:no_viewdoc_abbrev') 25 | cnoreabbrev pydoc getcmdtype()==':' && getcmdline()=='pydoc' ? 'ViewDocPydoc' : 'pydoc' 26 | cnoreabbrev pydoc! getcmdtype()==':' && getcmdline()=='pydoc!' ? 'ViewDocPydoc' : 'pydoc!' 27 | endif 28 | 29 | """ Handlers 30 | 31 | function s:ViewDoc_pydoc(topic, filetype, synid, ctx) 32 | if a:ctx 33 | let oldiskeyword = &iskeyword 34 | setlocal iskeyword+=. 35 | let topic = printf('%s %s', shellescape(a:topic,1), shellescape(expand(''),1)) 36 | let &iskeyword = oldiskeyword 37 | else 38 | let topic = shellescape(a:topic,1) 39 | endif 40 | " FIXME: remove duplicates from topic 41 | " TODO: make topic an array 42 | " TODO: implement better guessing for topic: 43 | " aaaa.bbbb.ccc|ccc 44 | " try: pydoc cccccc 45 | " if failed: try: pydoc bbbb.ccccc 46 | " if failed: try: pydoc aaaa.bbbb.ccccc 47 | " d|ddd 48 | " try: pydoc dddd 49 | " if failed: if some 'import dddd from mmmm' exists, try: pydoc mmmm.dddd 50 | " if failed: if some 'from mmmm import eeee as dddd' exists: try: pydoc mmmm.eeee 51 | return { 'cmd': printf('bash -c ''for topic in "$@" ; do if \! %s "$topic" | grep -q "no Python documentation found" ; then %s "$topic"; break; fi; done'' -- %s', g:viewdoc_pydoc_cmd, g:viewdoc_pydoc_cmd, topic), 52 | \ 'ft': 'pydoc', 53 | \ } 54 | endfunction 55 | 56 | " use function(s:SID().'Foo') instead of function('s:Foo') for 57 | " compatibility with Vim-7.3.x (7.3.762 at least) 58 | function s:SID() 59 | return matchstr(expand(''), '\zs\d\+_\zeSID$') 60 | endfunction 61 | let g:ViewDoc_pydoc = function(s:SID().'ViewDoc_pydoc') 62 | let g:ViewDoc_python = function(s:SID().'ViewDoc_pydoc') 63 | 64 | 65 | """ Internal 66 | 67 | " Autocomplete topics, keywords and modules. 68 | function s:CompletePydoc(ArgLead, CmdLine, CursorPos) 69 | if(!exists('s:complete_cache')) 70 | call ViewDoc_SetShellToBash() 71 | let s:complete_cache = system('echo $(for x in topics keywords modules; do echo $(pydoc $x 2>/dev/null | sed ''s/^$/\a/'') | cut -d $''\a'' -f 3; done) | sed ''s/ /\n/g''') 72 | call ViewDoc_RestoreShell() 73 | endif 74 | return s:complete_cache 75 | endfunction 76 | 77 | -------------------------------------------------------------------------------- /plugin/viewdoc_infman.vim: -------------------------------------------------------------------------------- 1 | " Maintainer: see in viewdoc.vim 2 | " Version: see in viewdoc.vim 3 | " Last Modified: see in viewdoc.vim 4 | " License: see in viewdoc.vim 5 | " URL: see in viewdoc.vim 6 | " Description: ViewDoc handler for OS Inferno man pages 7 | 8 | if exists('g:loaded_viewdoc_infman') || &cp || v:version < 700 9 | finish 10 | endif 11 | let g:loaded_viewdoc_infman = 1 12 | 13 | """ Constants 14 | let s:re_mansect = '\([1-9]\|10\)' 15 | 16 | """ Options 17 | if !exists('g:viewdoc_infman_cmd') 18 | let g:viewdoc_infman_cmd='bash -c ''emu-g sh -c "run /lib/sh/profile; $*; shutdown -h"'' --' 19 | endif 20 | 21 | """ Interface 22 | " - command 23 | command -bar -bang -nargs=1 -complete=custom,s:CompleteInfman ViewDocInfman 24 | \ call ViewDoc(''=='' ? 'new' : 'doc', , 'infman') 25 | " - abbrev 26 | if !exists('g:no_plugin_abbrev') && !exists('g:no_viewdoc_abbrev') 27 | cnoreabbrev infman getcmdtype()==':' && getcmdline()=='infman' ? 'ViewDocInfman' : 'infman' 28 | cnoreabbrev infman! getcmdtype()==':' && getcmdline()=='infman!' ? 'ViewDocInfman' : 'infman!' 29 | endif 30 | 31 | """ Handlers 32 | 33 | " let h = ViewDoc_infman('time') 34 | " let h = ViewDoc_infman('time(2)') 35 | " let h = ViewDoc_infman('2 time') 36 | function s:ViewDoc_infman(topic, ...) 37 | let sect = '' 38 | let name = a:topic 39 | let m = matchlist(name, '('.s:re_mansect.')\.\?$') 40 | if (len(m)) 41 | let sect = m[1] 42 | let name = substitute(name, '('.s:re_mansect.')\.\?$', '', '') 43 | endif 44 | let m = matchlist(name, '^'.s:re_mansect.'\s\+') 45 | if (len(m)) 46 | let sect = m[1] 47 | let name = substitute(name, '^'.s:re_mansect.'\s\+', '', '') 48 | endif 49 | return { 'cmd': printf('%s man %s %s', 50 | \ g:viewdoc_infman_cmd, sect, shellescape(name,1)), 51 | \ 'ft': 'infman', 52 | \ } 53 | endfunction 54 | 55 | " use function(s:SID().'Foo') instead of function('s:Foo') for 56 | " compatibility with Vim-7.3.x (7.3.762 at least) 57 | function s:SID() 58 | return matchstr(expand(''), '\zs\d\+_\zeSID$') 59 | endfunction 60 | let g:ViewDoc_infman = function(s:SID().'ViewDoc_infman') 61 | let g:ViewDoc_limbo = function(s:SID().'ViewDoc_infman') 62 | 63 | 64 | """ Internal 65 | 66 | " Autocomplete section: time( ti.*( 67 | " Autocomplete command: tim ti.*e 68 | " Autocomplete command in section: 2 tim 2 ti.*e 69 | function s:CompleteInfman(ArgLead, CmdLine, CursorPos) 70 | call ViewDoc_SetShellToBash() 71 | if strpart(a:CmdLine, a:CursorPos - 1) ==# '(' 72 | let m = matchlist(a:CmdLine, '\s\(\S\+\)($') 73 | if !len(m) 74 | call ViewDoc_RestoreShell() 75 | return '' 76 | endif 77 | let res = system(printf('%s man -w %s | sed ''s/\/man\/\([0-9]\+\)\/\(.*\)/\2(\1)/''', 78 | \ g:viewdoc_infman_cmd, shellescape(m[1],1))) 79 | else 80 | let m = matchlist(a:CmdLine, '\s'.s:re_mansect.'\s') 81 | let sect = len(m) ? m[1] : '*' 82 | let res = system(printf('%s cat /man/%s/INDEX | sed "s/ .*//" | sort -u', 83 | \ g:viewdoc_infman_cmd, sect)) 84 | endif 85 | call ViewDoc_RestoreShell() 86 | return res 87 | endfunction 88 | 89 | -------------------------------------------------------------------------------- /plugin/viewdoc_man.vim: -------------------------------------------------------------------------------- 1 | " Maintainer: see in viewdoc.vim 2 | " Version: see in viewdoc.vim 3 | " Last Modified: see in viewdoc.vim 4 | " License: see in viewdoc.vim 5 | " URL: see in viewdoc.vim 6 | " Description: ViewDoc handler for man pages (default handler) 7 | 8 | if exists('g:loaded_viewdoc_man') || &cp || v:version < 700 9 | finish 10 | endif 11 | let g:loaded_viewdoc_man = 1 12 | 13 | """ Constants 14 | let s:re_mansect = '\([0-9a-z]\+\)' 15 | 16 | """ Options 17 | if !exists('g:viewdoc_man_cmd') 18 | let g:viewdoc_man_cmd='man' " user may want 'LANG=en man' 19 | endif 20 | 21 | """ Interface 22 | " - command 23 | command -bar -bang -nargs=1 -complete=custom,s:CompleteMan ViewDocMan 24 | \ call ViewDoc(''=='' ? 'new' : 'doc', , 'man') 25 | " - abbrev 26 | if !exists('g:no_plugin_abbrev') && !exists('g:no_viewdoc_abbrev') 27 | cnoreabbrev man getcmdtype()==':' && getcmdline()=='man' ? 'ViewDocMan' : 'man' 28 | cnoreabbrev man! getcmdtype()==':' && getcmdline()=='man!' ? 'ViewDocMan' : 'man!' 29 | endif 30 | 31 | """ Handlers 32 | 33 | " let h = ViewDoc_man('time') 34 | " let h = ViewDoc_man('time(2)') 35 | " let h = ViewDoc_man('2 time') 36 | function s:ViewDoc_man(topic, ...) 37 | let sect = '' 38 | let name = a:topic 39 | let m = matchlist(name, '('.s:re_mansect.')\.\?$') 40 | if (len(m)) 41 | let sect = '-S '.m[1] 42 | let name = substitute(name, '('.s:re_mansect.')\.\?$', '', '') 43 | endif 44 | let m = matchlist(name, '^'.s:re_mansect.'\s\+') 45 | if (len(m)) 46 | let sect = '-S '.m[1] 47 | let name = substitute(name, '^'.s:re_mansect.'\s\+', '', '') 48 | endif 49 | return { 'cmd': printf('MANWIDTH={{winwidth}} %s %s %s | sed "s/ \xB7 / * /" | col -b', g:viewdoc_man_cmd, sect, shellescape(name,1)), 50 | \ 'ft': 'man', 51 | \ } 52 | endfunction 53 | 54 | " use function(s:SID().'Foo') instead of function('s:Foo') for 55 | " compatibility with Vim-7.3.x (7.3.762 at least) 56 | function s:SID() 57 | return matchstr(expand(''), '\zs\d\+_\zeSID$') 58 | endfunction 59 | let g:ViewDoc_man = function(s:SID().'ViewDoc_man') 60 | if !exists('g:ViewDoc_DEFAULT') 61 | let g:ViewDoc_DEFAULT = g:ViewDoc_man 62 | endif 63 | 64 | 65 | """ Internal 66 | 67 | " Autocomplete section: time( ti.*( 68 | " Autocomplete command: tim ti.*e 69 | " Autocomplete command in section: 2 tim 2 ti.*e 70 | function s:CompleteMan(ArgLead, CmdLine, CursorPos) 71 | call ViewDoc_SetShellToBash() 72 | if strpart(a:CmdLine, a:CursorPos - 1) ==# '(' 73 | let m = matchlist(a:CmdLine, '\s\(\S\+\)($') 74 | if !len(m) 75 | call ViewDoc_RestoreShell() 76 | return '' 77 | endif 78 | let res = system(printf('find $(manpath 2>/dev/null | sed "s/:/ /g") -type f -iregex ".*/man[0-9a-z][0-9a-z]*/"%s"\..*" 2>/dev/null | sed "s/.*\/man\([^/]*\/\)/\1/; s/\.bz2$//; s/\.gz$//; s/\(.*\)\/\(.*\)\.[^.]*$/\2(\1)/" | sort -u', shellescape(m[1],1))) 79 | else 80 | let m = matchlist(a:CmdLine, '\s'.s:re_mansect.'\s') 81 | let sect = len(m) ? m[1] : '*' 82 | let res = system(printf('find $(manpath 2>/dev/null | sed "s/:/ /g") -type f -path "*/man%s/*" 2>/dev/null | sed "s/.*\///; s/\.bz2$//; s/\.gz$//; s/\.[^.]*$//" | sort -u', sect)) 83 | endif 84 | call ViewDoc_RestoreShell() 85 | return res 86 | endfunction 87 | 88 | -------------------------------------------------------------------------------- /plugin/viewdoc_pman.vim: -------------------------------------------------------------------------------- 1 | " Maintainer: see in viewdoc.vim 2 | " Version: see in viewdoc.vim 3 | " Last Modified: see in viewdoc.vim 4 | " License: see in viewdoc.vim 5 | " URL: see in viewdoc.vim 6 | " Description: ViewDoc handler for php man pages 7 | 8 | if exists('g:loaded_viewdoc_pman') || &cp || v:version < 700 9 | finish 10 | endif 11 | let g:loaded_viewdoc_pman = 1 12 | 13 | """ Constants 14 | let s:re_mansect = '\([0-9]\)' 15 | 16 | """ Options 17 | if !exists('g:viewdoc_pman_cmd') 18 | let g:viewdoc_pman_cmd='pman' 19 | endif 20 | 21 | """ Interface 22 | " - command 23 | command -bar -bang -nargs=1 -complete=custom,s:CompleteMan ViewDocPman 24 | \ call ViewDoc(''=='' ? 'new' : 'doc', , 'pman') 25 | " - abbrev 26 | if !exists('g:no_plugin_abbrev') && !exists('g:no_viewdoc_abbrev') 27 | cnoreabbrev pman getcmdtype()==':' && getcmdline()=='pman' ? 'ViewDocPman' : 'pman' 28 | cnoreabbrev pman! getcmdtype()==':' && getcmdline()=='pman!' ? 'ViewDocPman' : 'pman!' 29 | endif 30 | 31 | """ Handlers 32 | 33 | " let h = ViewDoc_pman('error_reporting') 34 | " let h = ViewDoc_pman('error_reporting(3)') 35 | " let h = ViewDoc_pman('2 error_reporting') 36 | function s:ViewDoc_pman(topic, ...) 37 | let sect = '' 38 | let name = a:topic 39 | let m = matchlist(name, '('.s:re_mansect.')\.\?$') 40 | if (len(m)) 41 | let sect = m[1] 42 | let name = substitute(name, '('.s:re_mansect.')\.\?$', '', '') 43 | endif 44 | let m = matchlist(name, '^'.s:re_mansect.'\s\+') 45 | if (len(m)) 46 | let sect = m[1] 47 | let name = substitute(name, '^'.s:re_mansect.'\s\+', '', '') 48 | endif 49 | return { 'cmd': printf('%s %s %s | sed "s/ \xB7 / * /" | col -b', g:viewdoc_pman_cmd, sect, shellescape(name,1)), 50 | \ 'ft': 'pman', 51 | \ } 52 | endfunction 53 | 54 | " use function(s:SID().'Foo') instead of function('s:Foo') for 55 | " compatibility with Vim-7.3.x (7.3.762 at least) 56 | function s:SID() 57 | return matchstr(expand(''), '\zs\d\+_\zeSID$') 58 | endfunction 59 | let g:ViewDoc_pman = function(s:SID().'ViewDoc_pman') 60 | let g:ViewDoc_php = function(s:SID().'ViewDoc_pman') 61 | 62 | 63 | """ Internal 64 | 65 | " Autocomplete section: time( ti.*( 66 | " Autocomplete command: tim ti.*e 67 | " Autocomplete command in section: 2 tim 2 ti.*e 68 | function s:CompleteMan(ArgLead, CmdLine, CursorPos) 69 | call ViewDoc_SetShellToBash() 70 | let manpath = substitute(system(printf('%s --path', g:viewdoc_pman_cmd)),'\n$','','') 71 | if manpath =~# ':' 72 | let manpath = '{'.join(map(split(manpath,':'),'shellescape(v:val,1)'),',').'}' 73 | else 74 | let manpath = shellescape(manpath,1) 75 | endif 76 | if strpart(a:CmdLine, a:CursorPos - 1) ==# '(' 77 | let m = matchlist(a:CmdLine, '\s\(\S\+\)($') 78 | if !len(m) 79 | call ViewDoc_RestoreShell() 80 | return '' 81 | endif 82 | let res = system(printf('find %s/man* -type f -regex ".*/"%s"\.[0-9]\(\.bz2\|\.gz\)?" -printf "%%f\n" 2>/dev/null | sed "s/\.bz2$\|\.gz$//;s/.*\///;s/\.\([^.]\+\)$/(\1)/"', 83 | \ manpath, shellescape(m[1],1))) 84 | else 85 | let m = matchlist(a:CmdLine, '\s'.s:re_mansect.'\s') 86 | let sect = len(m) ? m[1] : '*' 87 | let res = system(printf('find %s/man%s -type f -printf "%%f\n" 2>/dev/null | sed "s/\.bz2$\|\.gz$//;s/\.[^.]*$//" | sort -u', 88 | \ manpath, sect)) 89 | endif 90 | call ViewDoc_RestoreShell() 91 | return res 92 | endfunction 93 | 94 | -------------------------------------------------------------------------------- /plugin/viewdoc_help.vim: -------------------------------------------------------------------------------- 1 | " Maintainer: see in viewdoc.vim 2 | " Version: see in viewdoc.vim 3 | " Last Modified: see in viewdoc.vim 4 | " License: see in viewdoc.vim 5 | " URL: see in viewdoc.vim 6 | " Description: ViewDoc handler for vim help files 7 | 8 | if exists('g:loaded_viewdoc_help') || &cp || v:version < 700 9 | finish 10 | endif 11 | let g:loaded_viewdoc_help = 1 12 | 13 | 14 | """ Interface 15 | " - command 16 | command -bar -bang -nargs=? -complete=help ViewDocHelp 17 | \ call ViewDoc(''=='' ? 'new' : 'doc', , 'help') 18 | " - abbrev 19 | if !exists('g:no_plugin_abbrev') && !exists('g:no_viewdoc_abbrev') 20 | cnoreabbrev h getcmdtype()==':' && getcmdline()=='h' ? 'ViewDocHelp' : 'h' 21 | cnoreabbrev h! getcmdtype()==':' && getcmdline()=='h!' ? 'ViewDocHelp' : 'h!' 22 | cnoreabbrev help getcmdtype()==':' && getcmdline()=='help' ? 'ViewDocHelp' : 'help' 23 | cnoreabbrev help! getcmdtype()==':' && getcmdline()=='help!' ? 'ViewDocHelp' : 'help!' 24 | endif 25 | 26 | """ Handlers 27 | 28 | function s:ViewDoc_help(topic, filetype, synid, ctx) 29 | let h = { 'ft': 'help', 30 | \ 'topic': a:topic, 31 | \ } 32 | if a:ctx 33 | if h.topic !~# "^'.*'$" && (synIDattr(a:synid,'name') =~# 'Option' || search('&\k*\%#','n')) 34 | " auto-detect: 'option' 35 | let matched = matchstr(h.topic, "'\\k\\+'") 36 | if len(matched) 37 | let h.topic = matched 38 | else 39 | let h.topic = "'" . h.topic . "'" 40 | endif 41 | elseif synIDattr(a:synid,'name') =~# 'Command' 42 | let h.topic = ':' . h.topic " auto-detect: :command 43 | endif 44 | endif 45 | try 46 | let savetabnr = tabpagenr() 47 | execute 'noautocmd tab help ' . h.topic 48 | let helpfile = expand('%:p') 49 | let cat = helpfile =~? 'gz$' ? 'zcat' : 'cat' 50 | let h.cmd = printf('%s %s', cat, shellescape(helpfile,1)) 51 | let h.line = line('.') 52 | let h.col = col('.') 53 | let h.tags = substitute(helpfile, '/[^/]*$', '/tags', '') 54 | let h.tags = substitute( h.tags, ' ', '\\ ', "g" ) 55 | noautocmd tabclose 56 | execute 'noautocmd tabnext ' . savetabnr 57 | catch 58 | endtry 59 | return h 60 | endfunction 61 | 62 | " use function(s:SID().'Foo') instead of function('s:Foo') for 63 | " compatibility with Vim-7.3.x (7.3.762 at least) 64 | function s:SID() 65 | return matchstr(expand(''), '\zs\d\+_\zeSID$') 66 | endfunction 67 | let g:ViewDoc_help = function(s:SID().'ViewDoc_help') 68 | let g:ViewDoc_vim = function(s:SID().'ViewDoc_help') 69 | 70 | function s:ViewDoc_help_custom(topic, ft, ...) 71 | let h = { 'ft': 'help', 72 | \ 'docft': a:ft, 73 | \ } 74 | let savetabnr = tabpagenr() 75 | for helpfile in split(globpath(&runtimepath, 'ftdoc/'.a:ft.'/*.txt'),"\") 76 | let tagsfile = substitute(helpfile, '/[^/]*$', '/tags', '') 77 | execute 'tabedit ' . helpfile 78 | execute 'setlocal tags^=' . tagsfile 79 | for tag_guess in [a:topic, "'".a:topic."'", a:ft.'-'.a:topic] 80 | try 81 | execute 'tag ' . tag_guess 82 | catch 83 | continue 84 | endtry 85 | let h.cmd = printf('cat %s', shellescape(helpfile,1)) 86 | let h.line = line('.') 87 | let h.col = col('.') 88 | let h.tags = substitute( tagsfile, ' ', '\\ ', "g" ) 89 | break 90 | endfor 91 | setlocal bufhidden=delete 92 | tabclose 93 | if exists('h.cmd') 94 | break 95 | endif 96 | endfor 97 | execute 'tabnext ' . savetabnr 98 | return h 99 | endfunction 100 | 101 | let g:ViewDoc_help_custom = function(s:SID().'ViewDoc_help_custom') 102 | 103 | -------------------------------------------------------------------------------- /plugin/viewdoc_godoc.vim: -------------------------------------------------------------------------------- 1 | " Maintainer: see in viewdoc.vim 2 | " Version: see in viewdoc.vim 3 | " Last Modified: see in viewdoc.vim 4 | " License: see in viewdoc.vim 5 | " URL: see in viewdoc.vim 6 | " Description: ViewDoc handler for godoc 7 | 8 | if exists('g:loaded_viewdoc_godoc') || &cp || v:version < 700 9 | finish 10 | endif 11 | let g:loaded_viewdoc_godoc = 1 12 | 13 | 14 | """ Options 15 | if !exists('g:viewdoc_godoc_cmd') 16 | let g:viewdoc_godoc_cmd='go doc -cmd -all' 17 | endif 18 | 19 | """ Interface 20 | " - command 21 | command -bar -bang -nargs=1 -complete=customlist,go#package#Complete ViewDocGo 22 | \ call ViewDoc(''=='' ? 'new' : 'doc', , 'go') 23 | " - abbrev 24 | if !exists('g:no_plugin_abbrev') && !exists('g:no_viewdoc_abbrev') 25 | cnoreabbrev godoc getcmdtype()==':' && getcmdline()=='godoc' ? 'ViewDocGo' : 'godoc' 26 | cnoreabbrev godoc! getcmdtype()==':' && getcmdline()=='godoc!' ? 'ViewDocGo' : 'godoc!' 27 | endif 28 | 29 | """ Handlers 30 | 31 | " let h = ViewDoc_go('fmt') 32 | " let h = ViewDoc_go('fmt Println') 33 | function s:ViewDoc_go(topic, filetype, synid, ctx) 34 | let h = { 'ft': 'godoc', 35 | \ } 36 | 37 | " This implementation based on code from vim-go plugin: Copyright 2011 The Go Authors. 38 | if a:ctx 39 | let oldiskeyword = &iskeyword 40 | setlocal iskeyword+=.,/ 41 | let word = expand('') 42 | let &iskeyword = oldiskeyword 43 | let word = substitute(word, '^\.\.\.', '', '') 44 | let word = substitute(word, '[^a-zA-Z0-9\\/._~-]', '', 'g') 45 | let words = split(word, '^[a-z][^.]*\zs\.\ze[A-Z]') 46 | if len(words) == 1 && match(words[0], '^[a-z]') == 0 47 | let synname = synIDattr(a:synid,'name') 48 | if synname =~# 'goBoolean\|goBuiltins\|goType\|goSignedInts\|goUnsignedInts\|goFloats\|goComplexes' 49 | let words = ['builtin', words[0]] 50 | endif 51 | endif 52 | else 53 | let words = split(a:topic, '\s\+') 54 | if len(words) == 1 55 | let words = split(words[0], '^[a-z][^.]*\zs\.\ze[A-Z]') 56 | endif 57 | endif 58 | if len(words) == 1 && match(words[0], '^[a-z]') == -1 59 | if exists('b:topic') 60 | let words = [b:topic, words[0]] 61 | else 62 | silent! let current_pkg = systemlist(printf('cd %s && go list -find -e 2>/dev/null', shellescape(expand('%:p:h'),1))) 63 | if len(current_pkg) != 0 64 | let words = [current_pkg[0], words[0]] 65 | endif 66 | endif 67 | endif 68 | 69 | if !len(words) 70 | let pkg = '' 71 | let sym = '' 72 | elseif len(words) == 1 73 | let pkg = words[0] 74 | let sym = '' 75 | else 76 | let pkg = words[0] 77 | let sym = words[1] 78 | endif 79 | 80 | silent! let packages = go#tool#Imports() 81 | if has_key(packages, pkg) 82 | let pkg = packages[pkg] 83 | endif 84 | 85 | if sym !=# '' 86 | let h.search = '^func '.sym.'[[(]\|^type '.sym.'\|\%(const\|var\|type\|\s\+\) '.pkg.'\s\+=\s' 87 | else 88 | let h.search = '\%(const\|var\|type\|\s\+\) '.pkg.'\s\+=\s' 89 | endif 90 | let h.topic = pkg 91 | let h.cmd = printf('%s %s', g:viewdoc_godoc_cmd, shellescape(pkg,1)) 92 | return h 93 | endfunction 94 | 95 | function s:ViewDoc_godoc(topic, filetype, synid, ctx) 96 | return { 'ft': 'go', 97 | \ 'topic': b:topic, 98 | \ 'cmd': printf('%s -src %s', g:viewdoc_godoc_cmd, shellescape(b:topic,1)), 99 | \ 'search': '^func '.a:topic.'(\|^type '.a:topic.'\|\%(const\|var\|type\|\s\+\) '.a:topic.'\s\+=\s', 100 | \ } 101 | endfunction 102 | 103 | " use function(s:SID().'Foo') instead of function('s:Foo') for 104 | " compatibility with Vim-7.3.x (7.3.762 at least) 105 | function s:SID() 106 | return matchstr(expand(''), '\zs\d\+_\zeSID$') 107 | endfunction 108 | let g:ViewDoc_go = function(s:SID().'ViewDoc_go') 109 | let g:ViewDoc_godoc = function(s:SID().'ViewDoc_godoc') 110 | -------------------------------------------------------------------------------- /plugin/viewdoc_perldoc.vim: -------------------------------------------------------------------------------- 1 | " Maintainer: see in viewdoc.vim 2 | " Version: see in viewdoc.vim 3 | " Last Modified: see in viewdoc.vim 4 | " License: see in viewdoc.vim 5 | " URL: see in viewdoc.vim 6 | " Description: ViewDoc handler for perldoc 7 | 8 | if exists('g:loaded_viewdoc_perldoc') || &cp || v:version < 700 9 | finish 10 | endif 11 | let g:loaded_viewdoc_perldoc = 1 12 | 13 | 14 | """ Options 15 | if !exists('g:viewdoc_perldoc_format') 16 | let g:viewdoc_perldoc_format='text' " user may want 'ansi' 17 | endif 18 | 19 | """ Interface 20 | " - command 21 | command -bar -bang -nargs=1 -complete=custom,s:CompletePerl ViewDocPerl 22 | \ call ViewDoc(''=='' ? 'new' : 'doc', , 'perl') 23 | " - abbrev 24 | if !exists('g:no_plugin_abbrev') && !exists('g:no_viewdoc_abbrev') 25 | cnoreabbrev perldoc getcmdtype()==':' && getcmdline()=='perldoc' ? 'ViewDocPerl' : 'perldoc' 26 | cnoreabbrev perldoc! getcmdtype()==':' && getcmdline()=='perldoc!' ? 'ViewDocPerl' : 'perldoc!' 27 | endif 28 | 29 | """ Handlers 30 | 31 | function s:ViewDoc_perldoc(topic, filetype, synid, ctx) 32 | let h = { 'ft': 'perldoc_' . g:viewdoc_perldoc_format, 33 | \ 'topic': a:topic, 34 | \ } 35 | if a:ctx && a:filetype ==# 'perldoc_ansi' 36 | " remove tail of concealed ANSI sequence before 37 | let h.topic = substitute(h.topic, '^[0-9]\+m', '', '') 38 | endif 39 | let synname = a:ctx ? synIDattr(a:synid,'name') : '' 40 | if synname =~# 'SharpBang' 41 | let h.topic = 'perlrun' 42 | elseif synname =~# 'StatementFiles' && len(h.topic) == 1 43 | let h.topic = '-X' 44 | elseif synname =~# 'Conditional\|Repeat\|Label' 45 | let h.topic = 'perlsyn' 46 | elseif synname =~# 'SubPrototype\|SubAttribute' 47 | let h.topic = 'perlsub' 48 | elseif h.topic ==# 'AUTOLOAD' 49 | let h.topic = 'perlsub' 50 | let h.search= '^\s*Autoloading\>' 51 | elseif h.topic ==# 'DESTROY' 52 | let h.topic = 'perlobj' 53 | let h.search= '^\s*Destructors\>' 54 | elseif h.topic =~# '^__[A-Z]\+__$' 55 | let h.topic = 'perldata' 56 | let h.search= '^\s*Special\s\+Literals' 57 | elseif h.topic ==# 'tr' || h.topic ==# 'y' 58 | let h.topic = 'perlop' 59 | let h.search= '^\s*tr\/' 60 | elseif h.topic =~# '^q[qxw]\?$' 61 | let h.search= '^\s*' . h.topic . '\/' 62 | let h.topic = 'perlop' 63 | elseif synname =~# 'StringStartEnd\|perlQQ' 64 | let h.topic = 'perlop' 65 | let h.search= '^\s*Quote\s\+and\s\+Quote-[Ll]ike\s\+Operators\s*$' 66 | elseif h.topic =~# '^\(BEGIN\|UNITCHECK\|CHECK\|INIT\|END\)$' 67 | let h.topic = 'perlmod' 68 | let h.search= '^\s*BEGIN,' 69 | elseif synname =~# '^pod[A-Z]\|POD' || h.topic =~# '^=[a-z]' || h.topic =~# '^[A-Z]<' 70 | let h.topic = 'perlpod' 71 | elseif synname =~# 'Match' 72 | let h.topic = 'perlre' 73 | elseif synname =~# 'Var' 74 | " search for position where current var's name begin (starting with [$@%]) 75 | let col = searchpos('[$@%]{\?\^\?\k*\%#\|\%#[$@%]', 'n')[1] 76 | " from that position took full var name (plus extra [ or { after it, if any) 77 | let var = col == 0 ? '' : matchstr(getline('.'), '^[$@%]{\?^\?.\k*}\?[{\[]\?', col-1) 78 | " $a[ -> @a, $a{ -> %a, @a{ -> %a, drop [ or { at end 79 | let var = substitute(var, '^$\(.*\)\[$', '@\1', '') 80 | let var = substitute(var, '^$\(.*\){$', '%\1', '') 81 | let var = substitute(var, '^@\(.*\){$', '%\1', '') 82 | let var = substitute(var, '[\[{]$', '', '') 83 | " ${a} -> $a, ${^a} -> $^a, but not ${^aa} 84 | let var = substitute(var, '^\([$@%]\){\([^^].*\|\^.\)}$', '\1\2', '') 85 | let h.topic = var ==# '' ? h.topic : var 86 | endif 87 | let t = shellescape(h.topic,1) 88 | let h.cmd = printf('perldoc -o %s -w width={{winwidth}} -- %s || perldoc -o %s -w width={{winwidth}} -f %s || perldoc -o %s -w width={{winwidth}} -v %s', 89 | \ g:viewdoc_perldoc_format, t, g:viewdoc_perldoc_format, t, g:viewdoc_perldoc_format, t) 90 | return h 91 | endfunction 92 | 93 | " use function(s:SID().'Foo') instead of function('s:Foo') for 94 | " compatibility with Vim-7.3.x (7.3.762 at least) 95 | function s:SID() 96 | return matchstr(expand(''), '\zs\d\+_\zeSID$') 97 | endfunction 98 | let g:ViewDoc_perl = function(s:SID().'ViewDoc_perldoc') 99 | let g:ViewDoc_perldoc = function(s:SID().'ViewDoc_perldoc') 100 | let g:ViewDoc_perldoc_text = function(s:SID().'ViewDoc_perldoc') 101 | let g:ViewDoc_perldoc_ansi = function(s:SID().'ViewDoc_perldoc') 102 | 103 | 104 | """ Internal 105 | 106 | function s:CompletePerl(ArgLead, CmdLine, CursorPos) 107 | if exists('s:complete') 108 | return s:complete 109 | endif 110 | call ViewDoc_SetShellToBash() 111 | let data= "__FILE__\n__LINE__\n__PACKAGE__\n__DATA__\n__END__\n" 112 | let mod = "BEGIN\nUNITCHECK\nCHECK\nINIT\nEND\n" 113 | let pod = system('grep "^=item C<[=A-Z]" $(perl -e "print for grep{-f}map{qq{\$_/pod/perlpod.pod}}@INC") | sed "s/^=item C].*//;s//" | sort -u') 114 | let var = system('grep -E "^=item [\$@%][^ ]*\$|=item [A-Z]+\$" $(perl -e "print for grep{-f}map{qq{\$_/pod/perlvar.pod}}@INC") | sed "s/^=item //" | sort -u') 115 | let func= "-X\n".system('grep "^=item [[:lower:]]" $(perl -e "print for grep{-f}map{qq{\$_/pod/perlfunc.pod}}@INC") | sed "s/^=item //" | grep -v " [[:lower:]]" | sed "s/ .*//;s/(\$//" | sort -u') 116 | let pkg = system('find $(perl -le "\$s{q{.}}=1;print for grep{(\$a=\$_)=~s{/[^/]*\z}{};-d && !\$s{\$_}++ && !\$s{\$a}}sort@INC") -name "*.pm" -printf "%P\n" | sed "s,^[0-9.]\+/,,;s,^"$(perl -MConfig -e "print \$Config{myarchname}")"/,,;s,.pm$,,;s,/,::,g" | sort -u') 117 | let s:complete = data.mod.pod.var.func.pkg 118 | call ViewDoc_RestoreShell() 119 | return s:complete 120 | endfunction 121 | 122 | -------------------------------------------------------------------------------- /plugin/viewdoc_info.vim: -------------------------------------------------------------------------------- 1 | " Author: pawel.wiecek@tieto.com 2 | " Maintainer: john.ch.fr@gmail.com 3 | " Version: see in viewdoc.vim 4 | " Last Modified: see in viewdoc.vim 5 | " License: see in viewdoc.vim 6 | " URL: see in viewdoc.vim 7 | " Description: ViewDoc handler for GNU info 8 | 9 | if exists('g:loaded_viewdoc_info') || &cp || v:version < 700 10 | finish 11 | endif 12 | let g:loaded_viewdoc_info = 1 13 | 14 | """ Options 15 | " path of "info" program (original standalone info viewer) 16 | if !exists('g:viewdoc_info_cmd') 17 | let g:viewdoc_info_cmd = 'info' 18 | endif 19 | " directories containing info files 20 | if !exists('g:viewdoc_info_path') 21 | let g:viewdoc_info_path = '/usr/share/info' 22 | endif 23 | 24 | """ Interface 25 | " - command 26 | " Can be called: 27 | " - with no parameters, will load info directory 28 | " - with one or more parameters, should behave identically to GNU Info. 29 | command -bar -bang -nargs=* -complete=customlist,s:CompleteInfo ViewDocInfo 30 | \ call ViewDoc(''=='' ? 'new' : 'doc', s:ParamsToNode(), 'infocmd') 31 | " - abbrev 32 | if !exists('g:no_plugin_abbrev') && !exists('g:no_viewdoc_abbrev') 33 | cnoreabbrev info getcmdtype()==':' && getcmdline()=='info' ? 'ViewDocInfo' : 'info' 34 | cnoreabbrev info! getcmdtype()==':' && getcmdline()=='info!' ? 'ViewDocInfo' : 'info!' 35 | endif 36 | 37 | """ Handlers 38 | 39 | " Handler for navigation inside info file. 40 | " Parsing logic does draw some inspiration from 41 | " http://www.vim.org/scripts/script.php?script_id=21 42 | " (especially in "note" links handling) 43 | function s:ViewDoc_info(topic, filetype, synid, ctx) 44 | let h = { 'ft': 'info' } 45 | let nothing = { 'ft': 'info', 'cmd': 'false' } 46 | if a:ctx 47 | let current_line = getline('.') 48 | let same_file = matchstr(b:topic, '(.*)') 49 | " patterns below contain some empty groups \(\), this is intentional, 50 | " because we want to have link parts in the same groups, no matte whet 51 | " format the link has 52 | if synIDattr(a:synid, 'name') ==# 'infoNavLink' 53 | " links in the top navigation line 54 | let nav_match = matchlist(getline('.')[:col('.')], '^File:.*\(Prev\|Next\|Up\): \(.\)') 55 | let nav = nav_match[1] 56 | if nav_match[2] ==# '(' 57 | let pattern = '^File: .*' . nav . ': \([^,]*\)\(\)\(\)' 58 | else 59 | let pattern = '^File: .*' . nav . ': \(\)\([^,]*\)\(\)' 60 | endif 61 | elseif synIDattr(a:synid, 'name') ==# 'infoLinkDir' || 62 | \ synIDattr(a:synid, 'name') ==# 'infoDirTarget' 63 | " links in main directory 64 | let pattern = '^\* [^:]\+: \(([^)]\+)\)\([^.]*\)\.\(\)' 65 | elseif synIDattr(a:synid, 'name') ==# 'infoLinkMenu' 66 | " links in standard menu 67 | let pattern = '^\* \(\)\([^:]*\)::\(\)' 68 | elseif synIDattr(a:synid, 'name') ==# 'infoLinkIndex' || 69 | \ synIDattr(a:synid, 'name') ==# 'infoIndexTarget' || 70 | \ synIDattr(a:synid, 'name') ==# 'infoIndexLine' 71 | " links in index page -- sometimes line number is wrapped to next line, 72 | " so we concatenate it if current line alone doesn't match 73 | let pattern = '^\* [^:]\+:\s*\(\)\([^.]\+\)\.\s*(line\s\+\([0-9]\+\))$' 74 | if matchstr(current_line, pattern) ==# '' 75 | let current_line = current_line.' '.getline(line('.') + 1) 76 | endif 77 | elseif synIDattr(a:synid, 'name') ==# 'infoLinkNote' 78 | " "note" links inside pages, these can span multiple lines 79 | if match(current_line, '\*[Nn]ote') < 0 80 | let prev_line = getline(line('.') - 1) 81 | let current_line = prev_line[match(prev_line, '.*\zs\*[Nn]ote'):].' '.current_line 82 | else 83 | let current_line = current_line.' '.getline(line('.') + 1) 84 | endif 85 | let pattern = '\*[Nn]ote [^:.]\+: \([^.,]\+\)\%([,.]\|$\)' 86 | let link = matchlist(current_line, pattern) 87 | if link == [] 88 | let pattern = '\*[Nn]ote \([^:]\+\)\%(::\)' 89 | let link = matchlist(current_line, pattern) 90 | endif 91 | let current_line = link[1] 92 | let pattern = '^\(([^)]\+)\)\=\s*\(.*\)\(\)' 93 | else 94 | " not inside a link -- not supported 95 | return nothing 96 | endif 97 | let link = matchlist(current_line, pattern) 98 | let file = same_file 99 | if link[1] !=# '' 100 | let file = s:FixNodeName(link[1]) 101 | endif 102 | let node = link[2] !=# '' ? link[2] : 'Top' 103 | let h.topic = file . node 104 | if link[3] !=# '' 105 | let h.line = str2nr(link[3]) 106 | endif 107 | else 108 | " not inside a link -- not supported 109 | return nothing 110 | endif 111 | let h.cmd = printf('%s %s -o-', g:viewdoc_info_cmd, shellescape(h.topic, 1)) 112 | return h 113 | endfunction 114 | 115 | " Handler for keyword searching (needs to have g:ViewDocInfoIndex_{ft} 116 | " defined, pointing to info node name (or list of names) of index 117 | function s:ViewDoc_info_search(topic, filetype, synid, ctx) 118 | let nothing = { 'ft': 'info', 'cmd': 'false' } 119 | if exists('g:ViewDocInfoIndex_{a:filetype}') 120 | if type(g:ViewDocInfoIndex_{a:filetype}) == type([]) 121 | let indices = g:ViewDocInfoIndex_{a:filetype} 122 | else 123 | let indices = [g:ViewDocInfoIndex_{a:filetype}] 124 | endif 125 | else 126 | return nothing 127 | endif 128 | let pattern = '^\* [^:]\+:\s*\(\)\([^.]\+\)\.\s*(line\s\+\([0-9]\+\))$' 129 | " open a temporary buffer and load indices 130 | let savetabnr = tabpagenr() 131 | silent noautocmd tabnew 132 | setlocal bufhidden=delete 133 | setlocal buftype=nofile 134 | setlocal noswapfile 135 | setlocal nobuflisted 136 | for idx in indices 137 | execute 'silent $r !' . g:viewdoc_info_cmd . ' ' . shellescape(s:FixNodeName(idx), 1) 138 | endfor 139 | " search for a first matching index entry 140 | if search('^\* ' . a:topic . '\W') 141 | let current_line = getline('.') 142 | if matchstr(current_line, pattern) ==# '' 143 | let current_line = current_line.' '.getline(line('.') + 1) 144 | endif 145 | else 146 | let current_line = '' 147 | endif 148 | noautocmd tabclose! 149 | execute 'noautocmd tabnext ' . savetabnr 150 | if current_line ==# '' 151 | " not found 152 | return nothing 153 | endif 154 | " parse found link 155 | let link = matchlist(current_line, pattern) 156 | let file = link[1] !=# '' ? link[1] : matchstr(s:FixNodeName(indices[0]), '(.*)') 157 | let node = link[2] !=# '' ? link[2] : 'Top' 158 | let h = { 'ft': 'info', 159 | \ 'topic': file . node } 160 | if link[3] !=# '' 161 | let h.line = str2nr(link[3]) 162 | endif 163 | let h.cmd = printf('%s %s -o-', g:viewdoc_info_cmd, shellescape(h.topic, 1)) 164 | return h 165 | endfunction 166 | 167 | " Handler for command line commands 168 | function s:ViewDoc_info_cmd(topic, ...) 169 | let nothing = { 'ft': 'info', 'cmd': 'false', 'topic': a:topic } 170 | let h = { 'ft': 'info', 171 | \ 'topic': s:FixNodeName(a:topic) } 172 | let h.cmd = printf('%s %s -o-', g:viewdoc_info_cmd, shellescape(h.topic, 1)) 173 | if h.topic ==# '' 174 | return nothing 175 | endif 176 | return h 177 | endfunction 178 | 179 | 180 | """ Internal 181 | 182 | " Converts :ViewDocInfo parameters to info node name to pass to ViewInfo as a 183 | " topic 184 | function s:ParamsToNode(...) 185 | if a:0 == 0 186 | return '(dir)Top' 187 | else 188 | let args = copy(a:000) 189 | if args[0][0] ==# '(' 190 | let args[0] = s:FixNodeName(args[0]) 191 | endif 192 | let sh_args = join(map(args, 'shellescape(v:val)'), ' ') 193 | return system(printf('%s %s -o- | head -n 2', g:viewdoc_info_cmd, sh_args) . 194 | \ ' | sed -n ''s/^File: \(.*\)\.info.*, Node: \([^,]*\),.*/(\1)\2/p''') 195 | endif 196 | endfunction 197 | 198 | " Helper to fix (file) parts where manuals have versioned filenames 199 | function s:FixNodeName(node) 200 | let file = substitute(a:node, '^(\([^)]\+\)).*', '\1', '') 201 | if globpath(g:viewdoc_info_path, file.'.info*') ==# '' 202 | let filenames = split(globpath(g:viewdoc_info_path, file.'-*.info*')) 203 | let candidates = [] 204 | for fn in filenames 205 | call add(candidates, substitute(fn, '^.*/\([^/]\+\)\.info.*$', '\1', '')) 206 | endfor 207 | if candidates != [] 208 | return substitute(a:node, '('.file.')', '('.sort(candidates)[-1].')', '') 209 | endif 210 | endif 211 | return a:node 212 | endfunction 213 | 214 | " Completion generator 215 | " Completes: manual names when invoked for 1st parameter, 216 | " node names from manual, whose name is param1 when invoked for any other 217 | " parameter 218 | function s:CompleteInfo(ArgLead, CmdLine, CursorPos) 219 | let line = join(split(a:CmdLine[0:a:CursorPos])[1:], ' ') 220 | let lead = substitute(a:ArgLead, '\\', '', 'g') 221 | let trail = split(line[:-len(a:ArgLead)-1], '[^\\]\zs ') 222 | let base_cmd = g:viewdoc_info_cmd . " '(dir)Top' -o- 2>/dev/null" 223 | let keys_pipe = ' | sed -n ''s/\* \([^:]*\): (.*/\1/p''' 224 | if len(trail) == 0 225 | if len(lead) == 0 226 | return split(escape(system(base_cmd . keys_pipe), ' '), "\n") 227 | endif 228 | let pipe = keys_pipe 229 | if lead[0] ==# '(' 230 | let pipe = ' | sed -n ''s/\* [^:]*: \(([^.]*\)\..*/\1/p'' | sort | uniq' 231 | endif 232 | else 233 | let pipe = ' | sed -e ''/^\* Menu:/,$ !d'' -n -e ''s/^\* \([^:]*\)::.*/\1/ p''' 234 | let args = join(map(trail, 'shellescape(v:val)'), ' ') 235 | let base_cmd = substitute(base_cmd, "'(dir)Top'", args, '') 236 | endif 237 | return split(escape(system(base_cmd . pipe . ' | sed -n ' . shellescape('/^' . lead . '/Ip')), ' '), "\n") 238 | endfunction 239 | 240 | 241 | """ Per-type public settings 242 | 243 | " per type exported configuration for (main) viewdoc 244 | function s:SID() 245 | return matchstr(expand(''), '\zs\d\+_\zeSID$') 246 | endfunction 247 | let g:ViewDoc_info = function(s:SID().'ViewDoc_info') 248 | let g:ViewDoc_infocmd = function(s:SID().'ViewDoc_info_cmd') 249 | let g:ViewDoc_search = function(s:SID().'ViewDoc_info_search') 250 | let g:ViewDoc_awk = function(s:SID().'ViewDoc_info_search') 251 | let g:ViewDoc_make = function(s:SID().'ViewDoc_info_search') 252 | let g:ViewDoc_m4 = function(s:SID().'ViewDoc_info_search') 253 | let g:ViewDoc_automake = function(s:SID().'ViewDoc_info_search') 254 | 255 | " per type index node configuration 256 | let g:ViewDocInfoIndex_awk = '(gawk)Index' 257 | let g:ViewDocInfoIndex_make = '(make)Name Index' 258 | let g:ViewDocInfoIndex_m4 = '(m4)Macro index' 259 | let g:ViewDocInfoIndex_automake = ['(automake)Macro Index', '(automake)Variable Index'] 260 | 261 | -------------------------------------------------------------------------------- /plugin/viewdoc.vim: -------------------------------------------------------------------------------- 1 | " Maintainer: Alex Efros 2 | " Version: 1.14 3 | " Last Modified: Dec 20, 2020 4 | " License: This file is placed in the public domain. 5 | " URL: http://www.vim.org/scripts/script.php?script_id=3893 6 | " Description: Flexible viewer for any documentation (help/man/perldoc/etc.) 7 | 8 | if exists('g:loaded_viewdoc') || &cp || v:version < 700 9 | finish 10 | endif 11 | let g:loaded_viewdoc = 1 12 | 13 | 14 | """ Constants 15 | let s:bufname = '[Doc]' 16 | 17 | """ Variables 18 | let s:bufid = 0 19 | 20 | """ Options 21 | if !exists('g:viewdoc_open') 22 | let g:viewdoc_open='tabnew' 23 | endif 24 | if !exists('g:viewdoc_only') 25 | let g:viewdoc_only=0 26 | endif 27 | if !exists('g:viewdoc_prevtabonclose') 28 | let g:viewdoc_prevtabonclose=1 29 | endif 30 | if !exists('g:viewdoc_openempty') 31 | let g:viewdoc_openempty=1 32 | endif 33 | if !exists('g:viewdoc_dontswitch') 34 | let g:viewdoc_dontswitch=0 35 | endif 36 | if !exists('g:viewdoc_copy_to_search_reg') 37 | let g:viewdoc_copy_to_search_reg=0 38 | endif 39 | if !exists('g:viewdoc_winwidth_max') 40 | let g:viewdoc_winwidth_max=0 41 | endif 42 | 43 | """ Interface 44 | " - command 45 | command -bar -bang -nargs=+ ViewDoc 46 | \ call ViewDoc(''=='' ? 'new' : 'doc', ) 47 | " - abbrev 48 | if !exists('g:no_plugin_abbrev') && !exists('g:no_viewdoc_abbrev') 49 | cnoreabbrev doc getcmdtype()==':' && getcmdline()=='doc' ? 'ViewDoc' : 'doc' 50 | cnoreabbrev doc! getcmdtype()==':' && getcmdline()=='doc!' ? 'ViewDoc!' : 'doc!' 51 | endif 52 | " - map 53 | if !exists('g:no_plugin_maps') && !exists('g:no_viewdoc_maps') 54 | if g:viewdoc_copy_to_search_reg 55 | inoremap :let @/ = '\<'.expand('').'\>':call ViewDoc('new', '') 56 | nnoremap :let @/ = '\<'.expand('').'\>':call ViewDoc('new', '') 57 | nnoremap K :let @/ = '\<'.expand('').'\>':call ViewDoc('doc', '') 58 | else 59 | inoremap :call ViewDoc('new', '') 60 | nnoremap :call ViewDoc('new', '') 61 | nnoremap K :call ViewDoc('doc', '') 62 | endif 63 | endif 64 | " - function 65 | " call ViewDoc('new', '') auto-detect context/syntax and file type 66 | " call ViewDoc('doc', 'bash') auto-detect only file type 67 | " call ViewDoc('new', ':execute', 'help') no auto-detect 68 | function ViewDoc(target, topic, ...) 69 | let hh = s:GetHandles(a:topic, a:0 > 0 ? a:1 : &ft) 70 | 71 | if a:target !=# 'inplace' 72 | let prev_tabpagenr = tabpagenr() 73 | call s:OpenBuf(a:target) 74 | let b:stack = 0 75 | endif 76 | 77 | " Force same settings as :help does 78 | " https://bitbucket.org/ZyX_I/vim/src/8d8a30a648f05a91c3c433f0e01343649449ca3c/src/ex_cmds.c#cl-3523 79 | setlocal tabstop=8 80 | setlocal nolist 81 | setlocal nobinary 82 | setlocal nonumber 83 | if exists('&relativenumber') 84 | setlocal norelativenumber 85 | endif 86 | if has('arabic') 87 | setlocal noarabic 88 | endif 89 | if has('rightleft') 90 | setlocal norightleft 91 | endif 92 | if has('folding') 93 | setlocal nofoldenable 94 | endif 95 | if has('diff') 96 | setlocal nodiff 97 | endif 98 | if has('spell') 99 | setlocal nospell 100 | endif 101 | 102 | setlocal modifiable 103 | silent 1,$d 104 | for h in hh 105 | if exists('h.cmd') 106 | call ViewDoc_SetShellToBash() 107 | let winwidth = g:viewdoc_winwidth_max > 0 ? min([winwidth('.'), g:viewdoc_winwidth_max]) : winwidth('.') 108 | let h.cmd = substitute(h.cmd, '{{winwidth}}', winwidth, 'g') 109 | if !has('win16') && !has('win32') && !has('win64') 110 | execute 'silent 0r ! ( ' . h.cmd . ' ) 2>/dev/null' 111 | else 112 | execute 'silent 0r ! ( ' . h.cmd . ' ) 2> nul' 113 | endif 114 | call ViewDoc_RestoreShell() 115 | silent $d 116 | execute 'normal! ' . (exists('h.line') ? h.line : 1) . 'G' 117 | execute 'normal! ' . (exists('h.col') ? h.col : 1) . '|' 118 | if exists('h.search') 119 | call search(h.search) 120 | endif 121 | normal! zt 122 | endif 123 | 124 | let is_empty = line('$') == 1 && col('$') == 1 125 | if !is_empty 126 | break 127 | endif 128 | endfor 129 | " https://github.com/powerman/vim-plugin-viewdoc/issues/47 130 | execute 'setlocal ft=' . h.ft 131 | setlocal nomodifiable nomodified 132 | 133 | let b:topic = h.topic 134 | if exists('h.tags') 135 | execute 'setlocal tags^=' . h.tags 136 | endif 137 | if exists('h.docft') 138 | let b:docft = h.docft 139 | endif 140 | 141 | inoremap q :call CloseBuf() 142 | nnoremap q :call CloseBuf() 143 | vnoremap q :call CloseBuf() 144 | inoremap :call Next() 145 | inoremap :call Prev() 146 | nnoremap :call Next() 147 | nnoremap :call Prev() 148 | imap 149 | imap 150 | nmap 151 | nmap 152 | 153 | if is_empty && !g:viewdoc_openempty 154 | if a:target ==# 'inplace' 155 | call s:Prev() 156 | else 157 | call s:CloseBuf() 158 | unlet! prev_tabpagenr 159 | endif 160 | endif 161 | 162 | if g:viewdoc_dontswitch && exists('prev_tabpagenr') 163 | if prev_tabpagenr != tabpagenr() 164 | execute 'tabnext ' . prev_tabpagenr 165 | elseif winnr('$') > 1 166 | wincmd p 167 | else 168 | execute "normal! \" 169 | endif 170 | endif 171 | 172 | if is_empty 173 | redraw | echohl ErrorMsg | echo 'Sorry, no doc for' h.topic | echohl None 174 | endif 175 | endfunction 176 | 177 | function ViewDoc_SetShellToBash() 178 | let s:_shell=&shell 179 | let s:_shellcmdflag=&shellcmdflag 180 | let s:_shellpipe=&shellpipe 181 | let s:_shellredir=&shellredir 182 | if !has('win16') && !has('win32') && !has('win64') 183 | setlocal shell=/bin/sh 184 | setlocal shellcmdflag=-c 185 | setlocal shellpipe=2>&1\|\ tee 186 | setlocal shellredir=>%s\ 2>&1 187 | endif 188 | endfunction 189 | 190 | function ViewDoc_RestoreShell() 191 | execute 'setlocal shell='.escape(s:_shell,'| ') 192 | execute 'setlocal shellcmdflag='.escape(s:_shellcmdflag,'| ') 193 | execute 'setlocal shellpipe='.escape(s:_shellpipe,'| ') 194 | execute 'setlocal shellredir='.escape(s:_shellredir,'| ') 195 | endfunction 196 | 197 | """ Internal 198 | 199 | " let hh = s:GetHandles('', 'perl') auto-detect syntax 200 | " let hh = s:GetHandles('query', 'perl') no auto-detect 201 | " Return: [{ 202 | " 'topic': 'query', ALWAYS 203 | " 'ft': 'perldoc', ALWAYS 204 | " 'cmd': 'cat /path/to/file', OPTIONAL 205 | " 'line': 1, OPTIONAL 206 | " 'col': 1, OPTIONAL 207 | " 'tags': '/path/to/tags', OPTIONAL 208 | " 'search': 'regex', OPTIONAL 209 | " 'docft': 'perl', OPTIONAL 210 | " },...] 211 | function s:GetHandles(topic, ft) 212 | let cword = a:topic ==# '' 213 | let topic = cword ? expand('') : a:topic 214 | let synid = cword ? synID(line('.'),col('.'),1) : 0 215 | 216 | let h_type = exists('g:ViewDoc_{a:ft}') ? a:ft : 'DEFAULT' 217 | if type(g:ViewDoc_{h_type}) == type([]) 218 | if len(g:ViewDoc_{h_type}) == 0 219 | let handlers = [ g:ViewDoc_DEFAULT ] 220 | else 221 | let handlers = g:ViewDoc_{h_type} 222 | endif 223 | else 224 | let handlers = [ g:ViewDoc_{h_type} ] 225 | endif 226 | 227 | let hh = [] 228 | for Handler in handlers 229 | if type(Handler) == type('') 230 | let name = Handler 231 | if name !~# '^g:' 232 | let name = 'g:' . name 233 | endif 234 | unlet Handler 235 | if exists('{name}') && type({name}) == type(function('tr')) 236 | let Handler = {name} 237 | else 238 | echohl ErrorMsg | echo 'No such function:' name | echohl None | sleep 2 239 | endif 240 | endif 241 | let h = exists('Handler') ? Handler(topic, a:ft, synid, cword) : {} 242 | let h.topic = exists('h.topic') ? h.topic : topic 243 | let h.ft = exists('h.ft') ? h.ft : a:ft 244 | call add(hh, h) 245 | unlet Handler 246 | endfor 247 | return hh 248 | endfunction 249 | 250 | " Emulate doc stack a-la tag stack ( and ) 251 | function s:Next() 252 | let b:stack = exists('b:stack') ? b:stack + 1 : 1 253 | let docft = exists('b:docft') ? b:docft : &ft 254 | if !exists('b:topic_stack') 255 | let b:topic_stack = [] 256 | endif 257 | call add(b:topic_stack, b:topic) 258 | if !exists('b:docft_stack') 259 | let b:docft_stack = [] 260 | endif 261 | call add(b:docft_stack, docft) 262 | normal! msHmt`s 263 | call ViewDoc('inplace', '', docft) 264 | endfunction 265 | 266 | function s:Prev() 267 | if exists('b:stack') && b:stack 268 | let b:stack -= 1 269 | let b:topic = remove(b:topic_stack, -1) 270 | let docft = remove(b:docft_stack, -1) 271 | setlocal modifiable 272 | undo 273 | execute 'setlocal ft=' . docft 274 | setlocal nomodifiable 275 | normal! 'tzt`s 276 | endif 277 | endfunction 278 | 279 | " call s:OpenBuf('doc') open existing '[Doc]' buffer (create if not exists) 280 | " call s:OpenBuf('new') create and open new '[DocN]' buffer 281 | function s:OpenBuf(target) 282 | let bufname = escape(s:bufname, '[]\') 283 | let [tabnr, winnr, bufnr] = s:FindBuf(bufname) 284 | 285 | if a:target ==# 'new' 286 | let s:bufid = s:bufid + 1 287 | let bufname = substitute(bufname, '\(\]\?\)$', s:bufid . '\1', '') 288 | execute g:viewdoc_open . ' ' . bufname 289 | elseif tabnr == -1 290 | execute g:viewdoc_open . ' ' . bufname 291 | else 292 | execute 'tabnext ' . tabnr 293 | execute winnr . 'wincmd w' 294 | endif 295 | if g:viewdoc_only 296 | only! 297 | endif 298 | setlocal noswapfile buflisted buftype=nofile bufhidden=hide 299 | endfunction 300 | 301 | " Close buffer with doc, and optionally move to previous tab. 302 | " Quit if closing last buffer. 303 | function s:CloseBuf() 304 | let cond = g:viewdoc_only ? 'buflisted(v:val)' : 'buflisted(v:val) && bufloaded(v:val)' 305 | if len(filter( range(1,bufnr('$')), cond )) == 1 306 | q 307 | elseif winnr('$') > 1 || !g:viewdoc_prevtabonclose 308 | bwipeout 309 | else 310 | let tabnr = tabpagenr() 311 | bwipeout 312 | if tabnr == tabpagenr() 313 | tabprevious 314 | endif 315 | endif 316 | endfunction 317 | 318 | " let [tabnr, winnr, bufnr] = s:FindBuf(bufname) 319 | " Return: 320 | " [-1, -1, -1] if buf not exists 321 | " [-1, -1, Z] if buf not visible 322 | " [ X, Y, Z] if buf visible 323 | function s:FindBuf(bufname) 324 | let bufnr = bufnr('^' . a:bufname . '$') 325 | if bufnr == -1 326 | return [-1, -1, -1] 327 | endif 328 | 329 | let tabnr = -1 330 | for t in range(1, tabpagenr('$')) 331 | for nr in tabpagebuflist(t) 332 | if nr == bufnr 333 | let tabnr = t 334 | break 335 | endif 336 | endfor 337 | if tabnr != -1 338 | break 339 | endif 340 | endfor 341 | if tabnr == -1 342 | return [-1, -1, bufnr] 343 | endif 344 | 345 | let savetabnr = tabpagenr() 346 | execute 'tabnext ' . tabnr 347 | let winnr = bufwinnr(bufnr) 348 | execute 'tabnext ' . savetabnr 349 | return [tabnr, winnr, bufnr] 350 | endfunction 351 | 352 | -------------------------------------------------------------------------------- /doc/viewdoc.txt: -------------------------------------------------------------------------------- 1 | *viewdoc.txt* Flexible viewer for any documentation (help/man/perldoc/etc.) 2 | 3 | Author: Alex Efros 4 | 5 | For Vim version 7.0 or later. 6 | This plugin only works if 'compatible' is not set. 7 | 8 | Contents: 9 | Description |viewdoc| 10 | Mappings |viewdoc-mappings| 11 | Commands |viewdoc-commands| 12 | Settings |viewdoc-settings| 13 | Functions |viewdoc-functions| 14 | Variables |viewdoc-variables| 15 | Handlers |viewdoc-handlers| 16 | DEFAULT |ViewDoc_DEFAULT| 17 | man |ViewDoc_man| 18 | help |ViewDoc_help| 19 | help_custom |ViewDoc_help_custom| 20 | perldoc |ViewDoc_perldoc| 21 | godoc |ViewDoc_godoc| 22 | pydoc |ViewDoc_pydoc| 23 | pman |ViewDoc_pman| 24 | infman |ViewDoc_infman| 25 | ri |ViewDoc_ri| 26 | bashhelp |ViewDoc_bashhelp| 27 | info |ViewDoc_info| 28 | Source and issue tracker |viewdoc-source| 29 | Contributors |viewdoc-contributors| 30 | License |viewdoc-license| 31 | 32 | ============================================================================== 33 | DESCRIPTION *viewdoc* 34 | 35 | Flexible viewer for any documentation source (help/man/perldoc/etc.) for any 36 | file type inside Vim in easy to use, consistent, smart and configurable way. 37 | 38 | * You can configure how (keys/commands) documentation will be open. 39 | By default it will replace standard mapping for key and commands |:help| 40 | and |:h| plus add mapping for key and new commands |:man|, |:doc|, etc. 41 | 42 | * You can configure where (buffer/window/tab) documentation will be open. 43 | Can open new docs in one dedicated () or new () buffer/window/tab. 44 | Support all work styles (see |viewdoc-settings-examples|): 45 | 46 | - full screen (no tabs, one window, open files/docs are in hidden buffers), 47 | - windowed (no tabs, many windows with open files/docs), 48 | - tabbed full screen (many tabs, each with one window, open files/docs are 49 | in different tabs), 50 | - tabbed (many tabs with many windows inside tabs). 51 | 52 | * You can easily navigate to next/previous topic while viewing documentation 53 | using and (or alternative keys and ), just 54 | like you use tags for navigation within source code and Vim's help. 55 | 56 | * Even closing documentation buffer/window/tab is easier, smarter and more 57 | configurable than ever before. :) 58 | 59 | * Smart detection of documentation source and topic when opening 60 | documentation for (word under cursor) - can use current syntax 61 | highlight (to find topic's context) and surrounding text (when topic 62 | doesn't include important special symbols because of 'iskeyword' value). 63 | 64 | * Smart completion for available documentation topics when opening 65 | documentation using command (just like Vim's |:help| command works). 66 | (Some documentation sources may not support this.) 67 | 68 | * Supported documentation sources: 69 | 70 | - man pages 71 | - Vim's help 72 | - custom documentation in vim help format 73 | - perldoc 74 | - godoc 75 | - pydoc (python) 76 | - pman (php) 77 | - OS Inferno man pages 78 | - ri (ruby) 79 | - bash's help 80 | - GNU info (smart support for: awk, make, m4, automake) 81 | 82 | * Support for new documentation sources and file types can be easily added by 83 | external plugins or within ~/.vimrc file. 84 | 85 | * You can have several documentation sources for same file type, and choose 86 | which one should be used on-the-fly. 87 | 88 | * Can be used as console man page viewer instead of /usr/bin/man. 89 | 90 | Tested only in Linux, but should work in any *NIX. 91 | 92 | ============================================================================== 93 | MAPPINGS *viewdoc-mappings* 94 | 95 | Global:~ 96 | 97 | Open doc for (word under cursor) in new "[DocN]" buffer. 98 | To disable use |g:no_viewdoc_maps|. 99 | 100 | K Open doc for in existing "[Doc]" buffer, replacing it current 101 | contents (will create "[Doc]" buffer if it doesn't exists yet). 102 | To disable use |g:no_viewdoc_maps|. 103 | 104 | Local to buffer with documentation:~ 105 | 106 | q Close this buffer/window/tab, |:quit| from Vim if it was the last one. 107 | 108 | or 109 | Open documentation for in same buffer. 110 | 111 | or 112 | Return to previous documentation in same buffer (after using ). 113 | 114 | ============================================================================== 115 | COMMANDS *viewdoc-commands* 116 | 117 | General:~ 118 | 119 | :doc[!] {topic} [{filetype}] *:doc* 120 | :doc[!] [{filetype}] 121 | Abbrev for |:ViewDoc|. 122 | To disable use |g:no_viewdoc_abbrev|. 123 | 124 | :ViewDoc[!] {topic} [{filetype}] *:ViewDoc* 125 | :ViewDoc[!] [{filetype}] 126 | Show documentation for word {topic} or for word under cursor (type 127 | literally as is, not as "" or as expand("")). 128 | 129 | Without {filetype} will use 'ft' of current buffer to detect which 130 | one of |viewdoc-handlers| (man/help/perldoc/etc.) should be used to 131 | show documentation for {topic}/. 132 | 133 | When used with handler may use smart detection of context 134 | when needed - check syntax highlight used for word under cursor or 135 | surrounding text (which wasn't included in expand("") because 136 | of 'iskeyword' value). 137 | 138 | By default will open documentation in new "[DocN]" buffer, but when 139 | [!] is added will open doc in existing "[Doc]" buffer (will create it if 140 | not exists yet). Will this buffer open in current window, new window 141 | or new tab depends on |viewdoc-settings|. 142 | 143 | Examples: > 144 | :doc substr perl 145 | :doc! " same as pressing 146 | 147 | Added by man handler:~ 148 | 149 | :man[!] {sect} {topic} *:man* 150 | :man[!] {topic}({sect}) 151 | :man[!] {topic} 152 | :man[!] {sect} 153 | :man[!] 154 | Abbrev for |:ViewDocMan|. 155 | To disable use |g:no_viewdoc_abbrev|. 156 | 157 | :ViewDocMan[!] {sect} {topic} *:ViewDocMan* 158 | :ViewDocMan[!] {topic}({sect}) 159 | :ViewDocMan[!] {topic} 160 | :ViewDocMan[!] {sect} 161 | :ViewDocMan[!] 162 | Show man page for given {topic} and (optional) {sect}. 163 | 164 | Works in same way as |:ViewDoc| with {filetype}=man, plus: 165 | * support {sect} as separate first param 166 | * provide auto-complete for {topic} and ({sect}): > 167 | :man tim " auto-complete {topic} 168 | :man 2 tim " auto-complete {topic} for section 2 only 169 | :man time( " auto-complete {sect} 170 | 171 | Added by help handler:~ 172 | 173 | :help[!] {topic} 174 | :help[!] 175 | :h[!] {topic} 176 | :h[!] 177 | Abbrev for |:ViewDocHelp|. 178 | To disable use |g:no_viewdoc_abbrev|. 179 | 180 | :ViewDocHelp[!] {topic} *:ViewDocHelp* 181 | :ViewDocHelp[!] 182 | Show Vim help for given {topic}. 183 | 184 | Works in same way as |:ViewDoc| with {filetype}=help, plus: 185 | * provide same auto-complete and other behaviour as standard |:help|, 186 | so it can be used as drop-in replacement 187 | 188 | Added by perldoc handler:~ 189 | 190 | :perldoc[!] {topic} *:perldoc* 191 | :perldoc[!] 192 | Abbrev for |:ViewDocPerl|. 193 | To disable use |g:no_viewdoc_abbrev|. 194 | 195 | :ViewDocPerl[!] {topic} *:ViewDocPerl* 196 | :ViewDocPerl[!] 197 | Show perl documentation for given {topic}. 198 | 199 | Works in same way as |:ViewDoc| with {filetype}=perl, plus: 200 | * provide auto-complete for variables/function/modules/POD/etc. 201 | 202 | Added by godoc handler:~ 203 | 204 | :godoc[!] {package} *:godoc* 205 | :godoc[!] {package} {identifier} 206 | :godoc[!] 207 | Abbrev for |:ViewDocGo|. 208 | To disable use |g:no_viewdoc_abbrev|. 209 | 210 | :ViewDocGo[!] {package} *:ViewDocGo* 211 | :ViewDocGo[!] {package} {identifier} 212 | :ViewDocGo[!] 213 | Show golang documentation for given {package}. 214 | 215 | Works in same way as |:ViewDoc| with {filetype}=go, plus: 216 | * provide auto-complete for packages and exported identifiers. 217 | 218 | Added by pydoc handler:~ 219 | 220 | :pydoc[!] {topic} *:pydoc* 221 | :pydoc[!] 222 | Abbrev for |:ViewDocPydoc|. 223 | To disable use |g:no_viewdoc_abbrev|. 224 | 225 | :ViewDocPydoc[!] {topic} *:ViewDocPydoc* 226 | :ViewDocPydoc[!] 227 | Show python documentation for given {topic}. 228 | 229 | Works in same way as |:ViewDoc| with {filetype}=python, plus: 230 | * provide auto-complete for topics, keywords and modules. 231 | 232 | Added by pman handler:~ 233 | 234 | :pman[!] {sect} {topic} *:pman* 235 | :pman[!] {topic}({sect}) 236 | :pman[!] {topic} 237 | :pman[!] {sect} 238 | :pman[!] 239 | Abbrev for |:ViewDocPman|. 240 | To disable use |g:no_viewdoc_abbrev|. 241 | 242 | :ViewDocPman[!] {sect} {topic} *:ViewDocPman* 243 | :ViewDocPman[!] {topic}({sect}) 244 | :ViewDocPman[!] {topic} 245 | :ViewDocPman[!] {sect} 246 | :ViewDocPman[!] 247 | Show php man page for given {topic} and (optional) {sect}. 248 | 249 | Works in same way as |:ViewDoc| with {filetype}=php, plus: 250 | * support {sect} as separate first param 251 | * provide auto-complete for {topic} and ({sect}): > 252 | :pman tim " auto-complete {topic} 253 | :pman 3 tim " auto-complete {topic} for section 3 only 254 | :pman time( " auto-complete {sect} 255 | 256 | Added by infman handler:~ 257 | 258 | :infman[!] {sect} {topic} *:infman* 259 | :infman[!] {topic}({sect}) 260 | :infman[!] {topic} 261 | :infman[!] {sect} 262 | :infman[!] 263 | Abbrev for |:ViewDocInfman|. 264 | To disable use |g:no_viewdoc_abbrev|. 265 | 266 | :ViewDocInfman[!] {sect} {topic} *:ViewDocInfman* 267 | :ViewDocInfman[!] {topic}({sect}) 268 | :ViewDocInfman[!] {topic} 269 | :ViewDocInfman[!] {sect} 270 | :ViewDocInfman[!] 271 | Show OS Inferno man page for given {topic} and (optional) {sect}. 272 | 273 | Works in same way as |:ViewDoc| with {filetype}=limbo, plus: 274 | * support {sect} as separate first param 275 | * provide auto-complete for {topic} and ({sect}): > 276 | :infman tim " auto-complete {topic} 277 | :infman 2 tim " auto-complete {topic} for section 2 only 278 | :infman time( " auto-complete {sect} 279 | 280 | Added by ri handler:~ 281 | 282 | :rdoc[!] {topic} *:rdoc* 283 | Abbrev for |:ViewDocRi|. 284 | To disable use |g:no_viewdoc_abbrev|. 285 | 286 | :ViewDocRi[!] {topic} *:ViewDocRi* 287 | Show Ruby documentation for given {topic}. 288 | 289 | Works in same way as |:ViewDoc| with {filetype}=ruby. 290 | 291 | Added by bashhelp handler:~ 292 | 293 | :bashhelp[!] {topic} *:bashhelp* 294 | Abbrev for |:ViewDocBashHelp|. 295 | To disable use |g:no_viewdoc_abbrev|. 296 | 297 | :ViewDocBashHelp[!] {topic} *:ViewDocBashHelp* 298 | Show bash's help for given {topic}. 299 | 300 | Works in same way as |:ViewDoc| with {filetype}=sh except it 301 | doesn't fallback to |:ViewDocMan|. 302 | 303 | Added by info handler:~ 304 | 305 | :info[!] *:info* 306 | :info[!] {topic} 307 | :info[!] ({file}){node} 308 | :info[!] {menu-item} ... 309 | Abbrev for |:ViewDocInfo|. 310 | To disable use |g:no_viewdoc_abbrev|. 311 | 312 | :ViewDocInfo[!] *:ViewDocInfo* 313 | :ViewDocInfo[!] {topic} 314 | :ViewDocInfo[!] ({file}){node} 315 | :ViewDocInfo[!] {menu-item} ... 316 | Show GNU info documentation. 317 | * with no parameters it will load info directory (dir)Top 318 | * with one or more parameters, it behaves identically to GNU Info. 319 | 320 | Example invocations are: > 321 | :ViewDocInfo 322 | :ViewDocInfo ls 323 | :ViewDocInfo (coreutils) 324 | :ViewDocInfo (coreutils)ls\ invocation 325 | :ViewDocInfo Bash Bash\ Features Aliases 326 | < 327 | Features auto-complete for {topic} and ({file}){node} separately: > 328 | :ViewDocInfo " auto-complete {topic} 329 | :ViewDocInfo Fil " auto-complete {topic} 330 | :ViewDocInfo (co " auto-complete ({file}){node} 331 | :ViewDocInfo Bash Bash\ Fe "auto-complete subtopic 332 | < 333 | 334 | ============================================================================== 335 | SETTINGS *viewdoc-settings* 336 | 337 | General:~ 338 | 339 | g:no_viewdoc_abbrev *g:no_viewdoc_abbrev* 340 | g:no_plugin_abbrev 341 | Set any of these variables to disable abbrev: 342 | |:doc|, |:man|, |:help|, |:h|, |:perldoc|, |:godoc|, |:pydoc|, |:pman|, 343 | |:infman|, |:rdoc|. 344 | 345 | g:no_viewdoc_maps *g:no_viewdoc_maps* 346 | g:no_plugin_maps 347 | Set any of these variables to disable mapping , . 348 | 349 | g:viewdoc_open ="tabnew" (default) *g:viewdoc_open* 350 | ="topleft new" 351 | ="belowright vnew" 352 | Control where documentation will be open by choosing Vim command used 353 | to open new window/tab. You can use any similar commands supported by 354 | Vim. New documentation buffer will be opened using: > 355 | execute g:viewdoc_open " to create new [DocN] buffer 356 | execute g:viewdoc_open [Doc] " to create new [Doc] buffer 357 | 358 | g:viewdoc_only =0 (default) *g:viewdoc_only* 359 | =1 360 | If you open documentation in window (|g:viewdoc_open|!="tabnew"), you 361 | can force this window to be the "only" window in current tab by 362 | changing this variable to True value. 363 | 364 | g:viewdoc_prevtabonclose=1 (default) *g:viewdoc_prevtabonclose* 365 | =0 366 | If you open documentation in new tab (|g:viewdoc_open|=="tabnew"), 367 | then when you close that tab Vim by default will move to next tab. 368 | This plugin by default change this behaviour to move to previous tab. 369 | If you like original behaviour set this variable to False. 370 | 371 | g:viewdoc_openempty =1 (default) *g:viewdoc_openempty* 372 | =0 373 | If documentation can't be found, empty window with error message will 374 | be opened. This is default behaviour to make consistent UI experience 375 | ( after will always return to where you was before ). 376 | Set this variable to False to avoid opening empty window when 377 | documentation can't be found (error message will be shown anyway). 378 | 379 | g:viewdoc_dontswitch =0 (default) *g:viewdoc_dontswitch* 380 | =1 381 | By default after opening documentation you'll be switched to 382 | buffer/window/tab with that documentation (except situation when 383 | documentation wasn't found and you've set |g:viewdoc_openempty|=0). 384 | If you prefer to don't change your current buffer/window/tab 385 | then set this variable to True. This may make sense in 386 | |viewdoc-windowed| or |viewdoc-tabbed| configurations and probably 387 | very bad idea in all other cases. 388 | 389 | g:viewdoc_copy_to_search_reg =0 (default) *g:viewdoc_copy_to_search_reg* 390 | =1 391 | If set to 1, the word which is looked up is also copied into the Vims 392 | search register which allows to easily search in the documentation for 393 | occurrences of this word. 394 | 395 | g:viewdoc_winwidth_max =0 (default) *g:viewdoc_winwidth_max* 396 | If set, limits the text width passed to doc formatters, so paragraphs 397 | width can be limited to |g:viewdoc_winwidth_max| characters rather than 398 | stretch across very wide windows. Some documentation is pre-formatted, 399 | and this will have no effect. 400 | 401 | Added by man handler:~ 402 | 403 | g:viewdoc_man_cmd ="man" (default) *g:viewdoc_man_cmd* 404 | Should contain command to run `man`. You may wanna change it, for ex. 405 | to force English manuals: > 406 | let g:viewdoc_man_cmd='LANG=en_US.UTF-8 man' 407 | < 408 | Added by perldoc handler:~ 409 | 410 | g:viewdoc_perldoc_format ="text" (default) *g:viewdoc_perldoc_format* 411 | Should contain value for `-o` option for `perldoc`. > 412 | let g:viewdoc_perldoc_format='ansi' 413 | < 414 | Added by godoc handler:~ 415 | 416 | g:viewdoc_godoc_cmd ="godoc" (default) *g:viewdoc_godoc_cmd* 417 | Should contain command to run `godoc`. > 418 | let g:viewdoc_godoc_cmd='/path/to/godoc' 419 | < 420 | Added by pydoc handler:~ 421 | 422 | g:viewdoc_pydoc_cmd ="pydoc" (default) *g:viewdoc_pydoc_cmd* 423 | Should contain command to run `pydoc`. You may wanna change it, for ex. 424 | to force different python version's doc: > 425 | let g:viewdoc_pydoc_cmd='pydoc3.2' 426 | < 427 | Added by pman handler:~ 428 | 429 | g:viewdoc_pman_cmd ="pman" (default) *g:viewdoc_pman_cmd* 430 | Should contain command to run `pman`. 431 | 432 | Added by infman handler:~ 433 | 434 | g:viewdoc_infman_cmd="emu-g" *g:viewdoc_infman_cmd* 435 | Should contain command able to run any OS Inferno commands (`emu-g`). 436 | 437 | Added by ri handler:~ 438 | 439 | g:viewdoc_ri_cmd ="ri" (default) *g:viewdoc_ri_cmd* 440 | Should contain command to run `ri`. You may wanna change it, for ex. 441 | to force different version of ri: > 442 | let g:viewdoc_ri_cmd='ri20' 443 | 444 | g:viewdoc_ri_format ="markdown" (default) *g:viewdoc_ri_format* 445 | Should contain value for `--format` option for `ri`. > 446 | let g:viewdoc_ri_format='rdoc' 447 | 448 | Added by info handler:~ 449 | 450 | g:viewdoc_info_cmd ="info" (default) *g:viewdoc_info_cmd* 451 | Should contain command to run `info`. 452 | 453 | g:viewdoc_info_path ="/usr/share/info" (default) *g:viewdoc_info_path* 454 | Should contain directories to search for info files. 455 | 456 | g:ViewDoc_info_search *g:ViewDoc_info_search* 457 | g:ViewDocInfoIndex_{filetype} ="{index node}" *g:ViewDocInfoIndex_{filetype}()* 458 | For keyword search one needs to set two variables per filetype: > 459 | let g:ViewDoc_{ft} = function('ViewDoc_info_search') 460 | let g:ViewDocInfoIndex_{ft} = '{index node}' 461 | < 462 | where {index node} can be either a string (name of index node of 463 | manual, eg. "(gawk)Index") or a list (if there are multiple indices 464 | that should be used). 465 | Settings for awk, make, m4 and automake already included. 466 | Example: > 467 | let g:ViewDoc_make = g:ViewDoc_info_search 468 | let g:ViewDocInfoIndex_make = '(make)Name Index' 469 | < 470 | 471 | *viewdoc-settings-examples* 472 | *viewdoc-fullscreen* 473 | 474 | Example configuration: full screen~ 475 | * no tabs 476 | * one window 477 | * other open files/docs are in hidden buffers 478 | * navigation between files/docs: |:bn| and |:bp|, close: |:bd| > 479 | let g:viewdoc_open='new' 480 | let g:viewdoc_only=1 481 | < *viewdoc-windowed* 482 | Example configuration: windowed~ 483 | * no tabs 484 | * many windows with open files/docs 485 | * navigation/close: CTRL-W something > 486 | let g:viewdoc_open='topleft new' 487 | < *viewdoc-tabbed-fullscreen* 488 | Example configuration: tabbed full screen~ 489 | * many tabs 490 | * each with one window 491 | * open files/docs are in different tabs > 492 | " this is default configuration 493 | < *viewdoc-tabbed* 494 | Example configuration: tabbed~ 495 | * many tabs with many windows inside tabs > 496 | " same as in windowed example above 497 | 498 | ============================================================================== 499 | FUNCTIONS *viewdoc-functions* 500 | 501 | This plugin provide global function ViewDoc() and many ViewDoc_{filetype}() 502 | functions, but only |ViewDoc()| function may be called by user (other 503 | functions are documentation handlers called internally by |ViewDoc()|). 504 | 505 | ViewDoc({target}, {topic}, {filetype}) *ViewDoc()* 506 | ViewDoc({target}, {topic}) 507 | ViewDoc({target}, '', {filetype}) 508 | ViewDoc({target}, '') 509 | This function handle all |viewdoc-commands|. 510 | 511 | {target} can be "new" or "doc". 512 | If it "new", then documentation will be open in new "[DocN]" buffer. 513 | If it "doc", then documentation will be open in existing "[Doc]" buffer 514 | (new "[Doc]" buffer will be created if it doesn't exists yet). 515 | Using {target}=="doc" is same as using |viewdoc-commands| with [!]. 516 | 517 | Other parameters documented in |:ViewDoc|. 518 | 519 | ============================================================================== 520 | VARIABLES *viewdoc-variables* 521 | 522 | May be useful for interaction with other plugins or user setup:~ 523 | 524 | b:topic *b:topic* 525 | Contain current documentation's topic. 526 | 527 | ============================================================================== 528 | HANDLERS *viewdoc-handlers* 529 | 530 | *ViewDoc_{filetype}()* 531 | To add documentation handler for new {filetype} it's enough to create one 532 | global function (or global variable with same name assigned to Funcref or 533 | List of Funcrefs) in ~/.vimrc (or some plugin): > 534 | 535 | ViewDoc_{filetype}(topic, filetype, synid, have_context) 536 | < 537 | This function will receive 4 parameters: 538 | 539 | topic Requested documentation topic ({topic} or param for 540 | |:ViewDoc|, if it was then it will be replaced with 541 | expand("") before calling this function). 542 | 543 | filetype Requested documentation type ({filetype} param for 544 | |:ViewDoc| or 'ft' if {filetype} param wasn't used). 545 | Usually will be same as in this function's name, unless you've 546 | used same function for several file type, like: > 547 | function s:ViewDoc_sh(topic, ...) | ... | endfunction 548 | let g:ViewDoc_sh = function('s:ViewDoc_sh') 549 | let g:ViewDoc_tcsh = function('s:ViewDoc_sh') 550 | 551 | synid Syntax id for requested topic as returned by |synID()|. 552 | Can be non-zero only if |:ViewDoc| was called with . 553 | 554 | have_context True if we've context (|:ViewDoc| was called with ). 555 | If true, then this function may try to analyse topic context, 556 | like surrounding symbols which wasn't included in topic param. 557 | 558 | Examples of calling documentation handler functions: 559 | 1) User press on word "test" in file "script.sh": > 560 | call ViewDoc_man('test', 'sh', 353, 1) 561 | < 2) User run command ":help local-additions" > 562 | call ViewDoc_help('local-additions', 'help', 0, 0) 563 | 564 | This function must return Dictionary with these keys (all optional): > 565 | 566 | 'topic': String modified topic, needed if your altered original topic 567 | 'cmd': String shell command which should output doc for topic 568 | 'ft': String file type for command output 569 | 'line': Number position to move cursor after opening doc 570 | 'col': Number position to move cursor after opening doc 571 | 'search': String regexp to search (to move cursor) after opening doc 572 | 'tags': String path to file with tags for this doc 573 | 'docft': String file type for navigating with inside this doc 574 | 575 | For example, here is implementation of |ViewDoc_pydoc| handler: > 576 | 577 | function s:ViewDoc_pydoc(topic, ...) 578 | return { 'cmd': printf('pydoc %s', shellescape(a:topic,1)), 579 | \ 'ft': 'pydoc', 580 | \ } 581 | endfunction 582 | let g:ViewDoc_pydoc = function('s:ViewDoc_pydoc') 583 | let g:ViewDoc_python = function('s:ViewDoc_pydoc') 584 | 585 | The `cmd` value may contain substring `{{winwidth}}` - it will be replaced 586 | with Doc's window width. 587 | 588 | Support for multiple documentation providers per filetype~ 589 | 590 | You can set ViewDoc_{filetype} variable to List of Funcrefs (or names of 591 | global variables containing Funcref) - in this case each Funcref will be tried 592 | in order until one of them will return non-empty documentation. 593 | 594 | For example, here is value of |ViewDoc_sh| variable: > 595 | 596 | let g:ViewDoc_sh = [ g:ViewDoc_bashhelp, 'ViewDoc_man' ] 597 | 598 | ------------------------------------------------------------------------------ 599 | Handler: DEFAULT *ViewDoc_DEFAULT* 600 | 601 | If there is no handler for current filetype then |ViewDoc_man| will be used. 602 | To change default handler to, for ex., |ViewDoc_help|, add to ~/.vimrc: > 603 | 604 | let g:ViewDoc_DEFAULT = 'ViewDoc_help' 605 | 606 | Or you can use function reference instead of function name, but this may 607 | require delaying until this function will be loaded (if it isn't defined 608 | in ~/.vimrc): > 609 | 610 | autocmd VimEnter * let g:ViewDoc_DEFAULT = g:ViewDoc_help 611 | 612 | ------------------------------------------------------------------------------ 613 | Handler: man *ViewDoc_man* 614 | 615 | Show doc using |g:viewdoc_man_cmd| command when {filetype} is "man". 616 | Also used as default handler, see |ViewDoc_DEFAULT|. 617 | 618 | Added commands: |:man| |:ViewDocMan|. 619 | Added settings: |g:viewdoc_man_cmd|. 620 | 621 | To view man pages in Vim from console add this script to ~/bin/man: > 622 | 623 | #!/bin/bash 624 | if [ ${1:0:1} == "-" ]; then 625 | exec /usr/bin/man $* 626 | else 627 | exec vim -c "ViewDocMan $*" -c tabonly 628 | fi 629 | 630 | NOTE For compatibility with autosess plugin (vimscript 3883) change last 631 | exec line in above script to: > 632 | 633 | exec vim --cmd 'let g:loaded_autosess=1' -c "ViewDocMan $*" -c tabonly 634 | 635 | ------------------------------------------------------------------------------ 636 | Handler: help *ViewDoc_help* 637 | 638 | Show standard Vim help when {filetype} is "vim" or "help". 639 | 640 | Viewing Vim help using this plugin have some advantages: 641 | 642 | * much better control how and where help window will be opened 643 | * smart detection ( on "&opt" will show help for 'opt', etc.) 644 | * and, of course, using to close help 645 | 646 | Added commands: |:help| |:h| |:ViewDocHelp|. 647 | 648 | ------------------------------------------------------------------------------ 649 | Handler: help_custom *ViewDoc_help_custom* 650 | 651 | Show doc for any {filetype} using separate .txt files written in Vim help 652 | format and stored in directory 'runtimepath'/ftdoc/{filetype}/ (no such help 653 | files provided with this plugin, you should download or write them yourself). 654 | 655 | Examples of external docs which can be used with this handler: 656 | 657 | * CSS 2.1, from http://www.vim.org/scripts/script.php?script_id=918 658 | Create directory ~/.vim/ftdoc/css: > 659 | :!mkdir -p ~/.vim/ftdoc/css/ 660 | < Copy .txt file from archive into ~/.vim/ftdoc/css/css21.txt, and run: > 661 | :helptags ~/.vim/ftdoc/css/ 662 | < Add to ~/.vimrc: > 663 | let g:ViewDoc_css = 'ViewDoc_help_custom' 664 | < 665 | * CMake, from http://www.vim.org/scripts/script.php?script_id=3045 666 | Create directory ~/.vim/ftdoc/cmake: > 667 | :!mkdir -p ~/.vim/ftdoc/cmake/ 668 | < Copy *.txt files from archive into ~/.vim/ftdoc/cmake/*.txt, and run: > 669 | :helptags ~/.vim/ftdoc/cmake/ 670 | < Add to ~/.vimrc: > 671 | let g:ViewDoc_cmake = 'ViewDoc_help_custom' 672 | < 673 | * LaTeX, from http://vim-latex.sourceforge.net/download/latexhelp.txt 674 | Create directory ~/.vim/ftdoc/tex: > 675 | :!mkdir -p ~/.vim/ftdoc/tex/ 676 | < Copy latexhelp.txt file into ~/.vim/ftdoc/tex/latexhelp.txt, and run: > 677 | :helptags ~/.vim/ftdoc/tex/ 678 | < Add to ~/.vimrc: > 679 | let g:ViewDoc_tex = 'ViewDoc_help_custom' 680 | 681 | ------------------------------------------------------------------------------ 682 | Handler: perldoc *ViewDoc_perldoc* 683 | 684 | Show doc using `perldoc` command when {filetype} is "perl" or "perldoc". 685 | 686 | Added commands: |:perldoc| |:ViewDocPerl|. 687 | 688 | ------------------------------------------------------------------------------ 689 | Handler: godoc *ViewDoc_godoc* 690 | 691 | Show doc using |g:viewdoc_godoc_cmd| command when {filetype} is "go". 692 | Show package source using |g:viewdoc_godoc_cmd| command when {filetype} is "godoc". 693 | 694 | Added commands: |:godoc| |:ViewDocGo|. 695 | Added settings: |g:viewdoc_godoc_cmd|. 696 | 697 | ------------------------------------------------------------------------------ 698 | Handler: pydoc *ViewDoc_pydoc* 699 | 700 | Show doc using |g:viewdoc_pydoc_cmd| command when {filetype} is "python" or "pydoc". 701 | 702 | Added commands: |:pydoc| |:ViewDocPydoc|. 703 | Added settings: |g:viewdoc_pydoc_cmd|. 704 | 705 | ------------------------------------------------------------------------------ 706 | Handler: pman *ViewDoc_pman* 707 | 708 | Show doc using |g:viewdoc_pman_cmd| command when {filetype} is "php" or "pman". 709 | 710 | Added commands: |:pman| |:ViewDocPman|. 711 | Added settings: |g:viewdoc_pman_cmd|. 712 | 713 | ------------------------------------------------------------------------------ 714 | Handler: infman *ViewDoc_infman* 715 | 716 | Show doc using |g:viewdoc_infman_cmd| command when {filetype} is "limbo" or 717 | "infman". 718 | 719 | Added commands: |:infman| |:ViewDocInfman|. 720 | Added settings: |g:viewdoc_infman_cmd|. 721 | 722 | ------------------------------------------------------------------------------ 723 | Handler: ri *ViewDoc_ri* 724 | 725 | Show doc using |g:viewdoc_ri_cmd| command when {filetype} is "ruby" or "rdoc". 726 | 727 | Added commands: |:rdoc| |:ViewDocRi|. 728 | Added settings: |g:viewdoc_ri_cmd|. 729 | 730 | ------------------------------------------------------------------------------ 731 | Handler: bashhelp *ViewDoc_bashhelp* 732 | 733 | Show doc using bash's `help` command when {filetype} is "sh", 734 | if not found then fallback to |:ViewDoc_man|. 735 | 736 | Added commands: |:bashhelp| |:ViewDocBashHelp|. 737 | 738 | ------------------------------------------------------------------------------ 739 | Handler: info *ViewDoc_info* 740 | 741 | Show doc using |g:viewdoc_info_cmd| command when {filetype} is "info" or "awk" 742 | or "make" or "m4" or "automake". 743 | 744 | Added commands: |:info| |:ViewDocInfo|. 745 | Added settings: |g:viewdoc_info_cmd|, |g:viewdoc_info_path|. 746 | 747 | ============================================================================== 748 | SOURCE AND ISSUE TRACKER *viewdoc-source* 749 | 750 | https://github.com/powerman/vim-plugin-viewdoc 751 | 752 | ============================================================================== 753 | CONTRIBUTORS *viewdoc-contributors* 754 | 755 | In alphabetical order:~ 756 | 757 | Artem Nezvigin (github: artnez) 758 | * Ruby (ri) support 759 | 760 | pawel.wiecek@tieto.com 761 | * Make viewdoc buffers easier to identify 762 | * LaTeX (help_custom) support 763 | * Add b:topic 764 | * Support for multiple documentation providers per filetype 765 | * Bash's help support 766 | * GNU info (smart support for: awk, make, m4, automake) 767 | 768 | Robin Schneider (github: ypid) 769 | * Add g:viewdoc_copy_to_search_reg 770 | 771 | ============================================================================== 772 | LICENSE *viewdoc-license* 773 | 774 | Public Domain. 775 | 776 | --------------------------------------------------------------------------------