" Vimball Archiver by Charles E. Campbell, Jr., Ph.D. UseVimball finish doc/viewdoc.txt [[[1 773 *viewdoc.txt* Flexible viewer for any documentation (help/man/perldoc/etc.) Author: Alex Efros For Vim version 7.0 or later. This plugin only works if 'compatible' is not set. Contents: Description |viewdoc| Mappings |viewdoc-mappings| Commands |viewdoc-commands| Settings |viewdoc-settings| Functions |viewdoc-functions| Variables |viewdoc-variables| Handlers |viewdoc-handlers| DEFAULT |ViewDoc_DEFAULT| man |ViewDoc_man| help |ViewDoc_help| help_custom |ViewDoc_help_custom| perldoc |ViewDoc_perldoc| godoc |ViewDoc_godoc| pydoc |ViewDoc_pydoc| pman |ViewDoc_pman| infman |ViewDoc_infman| ri |ViewDoc_ri| bashhelp |ViewDoc_bashhelp| info |ViewDoc_info| Source and issue tracker |viewdoc-source| Contributors |viewdoc-contributors| License |viewdoc-license| ============================================================================== DESCRIPTION *viewdoc* Flexible viewer for any documentation source (help/man/perldoc/etc.) for any file type inside Vim in easy to use, consistent, smart and configurable way. * You can configure how (keys/commands) documentation will be open. By default it will replace standard mapping for key and commands |:help| and |:h| plus add mapping for key and new commands |:man|, |:doc|, etc. * You can configure where (buffer/window/tab) documentation will be open. Can open new docs in one dedicated () or new () buffer/window/tab. Support all work styles (see |viewdoc-settings-examples|): - full screen (no tabs, one window, open files/docs are in hidden buffers), - windowed (no tabs, many windows with open files/docs), - tabbed full screen (many tabs, each with one window, open files/docs are in different tabs), - tabbed (many tabs with many windows inside tabs). * 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. * Even closing documentation buffer/window/tab is easier, smarter and more configurable than ever before. :) * 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). * 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.) * Supported documentation sources: - man pages - Vim's help - custom documentation in vim help format - perldoc - godoc - pydoc (python) - pman (php) - OS Inferno man pages - ri (ruby) - bash's help - GNU info (smart support for: awk, make, m4, automake) * Support for new documentation sources and file types can be easily added by external plugins or within ~/.vimrc file. * You can have several documentation sources for same file type, and choose which one should be used on-the-fly. * Can be used as console man page viewer instead of /usr/bin/man. Tested only in Linux, but should work in any *NIX. ============================================================================== MAPPINGS *viewdoc-mappings* Global:~ Open doc for (word under cursor) in new "[DocN]" buffer. To disable use |g:no_viewdoc_maps|. K Open doc for in existing "[Doc]" buffer, replacing it current contents (will create "[Doc]" buffer if it doesn't exists yet). To disable use |g:no_viewdoc_maps|. Local to buffer with documentation:~ q Close this buffer/window/tab, |:quit| from Vim if it was the last one. or Open documentation for in same buffer. or Return to previous documentation in same buffer (after using ). ============================================================================== COMMANDS *viewdoc-commands* General:~ :doc[!] {topic} [{filetype}] *:doc* :doc[!] [{filetype}] Abbrev for |:ViewDoc|. To disable use |g:no_viewdoc_abbrev|. :ViewDoc[!] {topic} [{filetype}] *:ViewDoc* :ViewDoc[!] [{filetype}] Show documentation for word {topic} or for word under cursor (type literally as is, not as "" or as expand("")). Without {filetype} will use 'ft' of current buffer to detect which one of |viewdoc-handlers| (man/help/perldoc/etc.) should be used to show documentation for {topic}/. When used with handler may use smart detection of context when needed - check syntax highlight used for word under cursor or surrounding text (which wasn't included in expand("") because of 'iskeyword' value). By default will open documentation in new "[DocN]" buffer, but when [!] is added will open doc in existing "[Doc]" buffer (will create it if not exists yet). Will this buffer open in current window, new window or new tab depends on |viewdoc-settings|. Examples: > :doc substr perl :doc! " same as pressing Added by man handler:~ :man[!] {sect} {topic} *:man* :man[!] {topic}({sect}) :man[!] {topic} :man[!] {sect} :man[!] Abbrev for |:ViewDocMan|. To disable use |g:no_viewdoc_abbrev|. :ViewDocMan[!] {sect} {topic} *:ViewDocMan* :ViewDocMan[!] {topic}({sect}) :ViewDocMan[!] {topic} :ViewDocMan[!] {sect} :ViewDocMan[!] Show man page for given {topic} and (optional) {sect}. Works in same way as |:ViewDoc| with {filetype}=man, plus: * support {sect} as separate first param * provide auto-complete for {topic} and ({sect}): > :man tim " auto-complete {topic} :man 2 tim " auto-complete {topic} for section 2 only :man time( " auto-complete {sect} Added by help handler:~ :help[!] {topic} :help[!] :h[!] {topic} :h[!] Abbrev for |:ViewDocHelp|. To disable use |g:no_viewdoc_abbrev|. :ViewDocHelp[!] {topic} *:ViewDocHelp* :ViewDocHelp[!] Show Vim help for given {topic}. Works in same way as |:ViewDoc| with {filetype}=help, plus: * provide same auto-complete and other behaviour as standard |:help|, so it can be used as drop-in replacement Added by perldoc handler:~ :perldoc[!] {topic} *:perldoc* :perldoc[!] Abbrev for |:ViewDocPerl|. To disable use |g:no_viewdoc_abbrev|. :ViewDocPerl[!] {topic} *:ViewDocPerl* :ViewDocPerl[!] Show perl documentation for given {topic}. Works in same way as |:ViewDoc| with {filetype}=perl, plus: * provide auto-complete for variables/function/modules/POD/etc. Added by godoc handler:~ :godoc[!] {package} *:godoc* :godoc[!] {package} {identifier} :godoc[!] Abbrev for |:ViewDocGo|. To disable use |g:no_viewdoc_abbrev|. :ViewDocGo[!] {package} *:ViewDocGo* :ViewDocGo[!] {package} {identifier} :ViewDocGo[!] Show golang documentation for given {package}. Works in same way as |:ViewDoc| with {filetype}=go, plus: * provide auto-complete for packages and exported identifiers. Added by pydoc handler:~ :pydoc[!] {topic} *:pydoc* :pydoc[!] Abbrev for |:ViewDocPydoc|. To disable use |g:no_viewdoc_abbrev|. :ViewDocPydoc[!] {topic} *:ViewDocPydoc* :ViewDocPydoc[!] Show python documentation for given {topic}. Works in same way as |:ViewDoc| with {filetype}=python, plus: * provide auto-complete for topics, keywords and modules. Added by pman handler:~ :pman[!] {sect} {topic} *:pman* :pman[!] {topic}({sect}) :pman[!] {topic} :pman[!] {sect} :pman[!] Abbrev for |:ViewDocPman|. To disable use |g:no_viewdoc_abbrev|. :ViewDocPman[!] {sect} {topic} *:ViewDocPman* :ViewDocPman[!] {topic}({sect}) :ViewDocPman[!] {topic} :ViewDocPman[!] {sect} :ViewDocPman[!] Show php man page for given {topic} and (optional) {sect}. Works in same way as |:ViewDoc| with {filetype}=php, plus: * support {sect} as separate first param * provide auto-complete for {topic} and ({sect}): > :pman tim " auto-complete {topic} :pman 3 tim " auto-complete {topic} for section 3 only :pman time( " auto-complete {sect} Added by infman handler:~ :infman[!] {sect} {topic} *:infman* :infman[!] {topic}({sect}) :infman[!] {topic} :infman[!] {sect} :infman[!] Abbrev for |:ViewDocInfman|. To disable use |g:no_viewdoc_abbrev|. :ViewDocInfman[!] {sect} {topic} *:ViewDocInfman* :ViewDocInfman[!] {topic}({sect}) :ViewDocInfman[!] {topic} :ViewDocInfman[!] {sect} :ViewDocInfman[!] Show OS Inferno man page for given {topic} and (optional) {sect}. Works in same way as |:ViewDoc| with {filetype}=limbo, plus: * support {sect} as separate first param * provide auto-complete for {topic} and ({sect}): > :infman tim " auto-complete {topic} :infman 2 tim " auto-complete {topic} for section 2 only :infman time( " auto-complete {sect} Added by ri handler:~ :rdoc[!] {topic} *:rdoc* Abbrev for |:ViewDocRi|. To disable use |g:no_viewdoc_abbrev|. :ViewDocRi[!] {topic} *:ViewDocRi* Show Ruby documentation for given {topic}. Works in same way as |:ViewDoc| with {filetype}=ruby. Added by bashhelp handler:~ :bashhelp[!] {topic} *:bashhelp* Abbrev for |:ViewDocBashHelp|. To disable use |g:no_viewdoc_abbrev|. :ViewDocBashHelp[!] {topic} *:ViewDocBashHelp* Show bash's help for given {topic}. Works in same way as |:ViewDoc| with {filetype}=sh except it doesn't fallback to |:ViewDocMan|. Added by info handler:~ :info[!] *:info* :info[!] {file} :info[!] ({file}){node} :info[!] {file} {node} Abbrev for |:ViewDocInfo|. To disable use |g:no_viewdoc_abbrev|. :ViewDocInfo[!] *:ViewDocInfo* :ViewDocInfo[!] {file} :ViewDocInfo[!] ({file}){node} :ViewDocInfo[!] {file} {node} Show GNU info documentation. * with no parameters it will load info directory (dir)Top * with one parameter it will load a named node (if parameter is in (file)node format) or top node of named manual * with two or more parameters it will load specified node, 1st parameter is used as manual name, the rest are used as node name Example invocations are: > :ViewDocInfo :ViewDocInfo gawk :ViewDocInfo (gawk)Functions :ViewDocInfo gawk Functions :ViewDocInfo gawk Getting Started < Works in same way as |:ViewDoc| with {filetype}=info, plus: * use (dir)Top as default without params * support {file} as separate first param * support {file} {node} as separate params * provide auto-complete for {file} and {node}: > :info ga " auto-complete {file} :info gawk Ex " auto-complete {node} for gawk ============================================================================== SETTINGS *viewdoc-settings* General:~ g:no_viewdoc_abbrev *g:no_viewdoc_abbrev* g:no_plugin_abbrev Set any of these variables to disable abbrev: |:doc|, |:man|, |:help|, |:h|, |:perldoc|, |:godoc|, |:pydoc|, |:pman|, |:infman|, |:rdoc|. g:no_viewdoc_maps *g:no_viewdoc_maps* g:no_plugin_maps Set any of these variables to disable mapping , . g:viewdoc_open ="tabnew" (default) *g:viewdoc_open* ="topleft new" ="belowright vnew" Control where documentation will be open by choosing Vim command used to open new window/tab. You can use any similar commands supported by Vim. New documentation buffer will be opened using: > execute g:viewdoc_open " to create new [DocN] buffer execute g:viewdoc_open [Doc] " to create new [Doc] buffer g:viewdoc_only =0 (default) *g:viewdoc_only* =1 If you open documentation in window (|g:viewdoc_open|!="tabnew"), you can force this window to be the "only" window in current tab by changing this variable to True value. g:viewdoc_prevtabonclose=1 (default) *g:viewdoc_prevtabonclose* =0 If you open documentation in new tab (|g:viewdoc_open|=="tabnew"), then when you close that tab Vim by default will move to next tab. This plugin by default change this behaviour to move to previous tab. If you like original behaviour set this variable to False. g:viewdoc_openempty =1 (default) *g:viewdoc_openempty* =0 If documentation can't be found, empty window with error message will be opened. This is default behaviour to make consistent UI experience ( after will always return to where you was before ). Set this variable to False to avoid opening empty window when documentation can't be found (error message will be shown anyway). g:viewdoc_dontswitch =0 (default) *g:viewdoc_dontswitch* =1 By default after opening documentation you'll be switched to buffer/window/tab with that documentation (except situation when documentation wasn't found and you've set |g:viewdoc_openempty|=0). If you prefer to don't change your current buffer/window/tab then set this variable to True. This may make sense in |viewdoc-windowed| or |viewdoc-tabbed| configurations and probably very bad idea in all other cases. g:viewdoc_copy_to_search_reg =0 (default) *g:viewdoc_copy_to_search_reg* =1 If set to 1, the word which is looked up is also copied into the Vims search register which allows to easily search in the documentation for occurrences of this word. Added by man handler:~ g:viewdoc_man_cmd ="man" (default) *g:viewdoc_man_cmd* Should contain command to run `man`. You may wanna change it, for ex. to force English manuals: > let g:viewdoc_man_cmd='LANG=en_US.UTF-8 man' < Added by perldoc handler:~ g:viewdoc_perldoc_format ="text" (default) *g:viewdoc_perldoc_format* Should contain value for `-o` option for `perldoc`. > let g:viewdoc_perldoc_format='ansi' < Added by godoc handler:~ g:viewdoc_godoc_cmd ="godoc" (default) *g:viewdoc_godoc_cmd* Should contain command to run `godoc`. > let g:viewdoc_godoc_cmd='/path/to/godoc' < Added by pydoc handler:~ g:viewdoc_pydoc_cmd ="pydoc" (default) *g:viewdoc_pydoc_cmd* Should contain command to run `pydoc`. You may wanna change it, for ex. to force different python version's doc: > let g:viewdoc_pydoc_cmd='pydoc3.2' < Added by pman handler:~ g:viewdoc_pman_cmd ="pman" (default) *g:viewdoc_pman_cmd* Should contain command to run `pman`. Added by infman handler:~ g:viewdoc_infman_cmd="emu-g" *g:viewdoc_infman_cmd* Should contain command able to run any OS Inferno commands (`emu-g`). Added by ri handler:~ g:viewdoc_ri_cmd ="ri" (default) *g:viewdoc_ri_cmd* Should contain command to run `ri`. You may wanna change it, for ex. to force different version of ri: > let g:viewdoc_ri_cmd='ri20' g:viewdoc_ri_format ="markdown" (default) *g:viewdoc_ri_format* Should contain value for `--format` option for `ri`. > let g:viewdoc_ri_format='rdoc' Added by info handler:~ g:viewdoc_info_cmd ="info" (default) *g:viewdoc_info_cmd* Should contain command to run `info`. g:viewdoc_info_path ="/usr/share/info" (default) *g:viewdoc_info_path* Should contain directories to search for info files. g:ViewDoc_info_search *g:ViewDoc_info_search* g:ViewDocInfoIndex_{filetype} ="{index node}" *g:ViewDocInfoIndex_{filetype}()* For keyword search one needs to set two variables per filetype: > let g:ViewDoc_{ft} = function('ViewDoc_info_search') let g:ViewDocInfoIndex_{ft} = '{index node}' < where {index node} can be either a string (name of index node of manual, eg. "(gawk)Index") or a list (if there are multiple indices that should be used). Settings for awk, make, m4 and automake already included. Example: > let g:ViewDoc_make = g:ViewDoc_info_search let g:ViewDocInfoIndex_make = '(make)Name Index' < *viewdoc-settings-examples* *viewdoc-fullscreen* Example configuration: full screen~ * no tabs * one window * other open files/docs are in hidden buffers * navigation between files/docs: |:bn| and |:bp|, close: |:bd| > let g:viewdoc_open='new' let g:viewdoc_only=1 < *viewdoc-windowed* Example configuration: windowed~ * no tabs * many windows with open files/docs * navigation/close: CTRL-W something > let g:viewdoc_open='topleft new' < *viewdoc-tabbed-fullscreen* Example configuration: tabbed full screen~ * many tabs * each with one window * open files/docs are in different tabs > " this is default configuration < *viewdoc-tabbed* Example configuration: tabbed~ * many tabs with many windows inside tabs > " same as in windowed example above ============================================================================== FUNCTIONS *viewdoc-functions* This plugin provide global function ViewDoc() and many ViewDoc_{filetype}() functions, but only |ViewDoc()| function may be called by user (other functions are documentation handlers called internally by |ViewDoc()|). ViewDoc({target}, {topic}, {filetype}) *ViewDoc()* ViewDoc({target}, {topic}) ViewDoc({target}, '', {filetype}) ViewDoc({target}, '') This function handle all |viewdoc-commands|. {target} can be "new" or "doc". If it "new", then documentation will be open in new "[DocN]" buffer. If it "doc", then documentation will be open in existing "[Doc]" buffer (new "[Doc]" buffer will be created if it doesn't exists yet). Using {target}=="doc" is same as using |viewdoc-commands| with [!]. Other parameters documented in |:ViewDoc|. ============================================================================== VARIABLES *viewdoc-variables* May be useful for interaction with other plugins or user setup:~ b:topic *b:topic* Contain current documentation's topic. ============================================================================== HANDLERS *viewdoc-handlers* *ViewDoc_{filetype}()* To add documentation handler for new {filetype} it's enough to create one global function (or global variable with same name assigned to Funcref or List of Funcrefs) in ~/.vimrc (or some plugin): > ViewDoc_{filetype}(topic, filetype, synid, have_context) < This function will receive 4 parameters: topic Requested documentation topic ({topic} or param for |:ViewDoc|, if it was then it will be replaced with expand("") before calling this function). filetype Requested documentation type ({filetype} param for |:ViewDoc| or 'ft' if {filetype} param wasn't used). Usually will be same as in this function's name, unless you've used same function for several file type, like: > function s:ViewDoc_sh(topic, ...) | ... | endfunction let g:ViewDoc_sh = function('s:ViewDoc_sh') let g:ViewDoc_tcsh = function('s:ViewDoc_sh') synid Syntax id for requested topic as returned by |synID()|. Can be non-zero only if |:ViewDoc| was called with . have_context True if we've context (|:ViewDoc| was called with ). If true, then this function may try to analyse topic context, like surrounding symbols which wasn't included in topic param. Examples of calling documentation handler functions: 1) User press on word "test" in file "script.sh": > call ViewDoc_man('test', 'sh', 353, 1) < 2) User run command ":help local-additions" > call ViewDoc_help('local-additions', 'help', 0, 0) This function must return Dictionary with these keys (all optional): > 'topic': String modified topic, needed if your altered original topic 'cmd': String shell command which should output doc for topic 'ft': String file type for command output 'line': Number position to move cursor after opening doc 'col': Number position to move cursor after opening doc 'search': String regexp to search (to move cursor) after opening doc 'tags': String path to file with tags for this doc 'docft': String file type for navigating with inside this doc For example, here is implementation of |ViewDoc_pydoc| handler: > function s:ViewDoc_pydoc(topic, ...) return { 'cmd': printf('pydoc %s', shellescape(a:topic,1)), \ 'ft': 'pydoc', \ } endfunction let g:ViewDoc_pydoc = function('s:ViewDoc_pydoc') let g:ViewDoc_python = function('s:ViewDoc_pydoc') The `cmd` value may contain substring `{{winwidth}}` - it will be replaced with Doc's window width. Support for multiple documentation providers per filetype~ You can set ViewDoc_{filetype} variable to List of Funcrefs (or names of global variables containing Funcref) - in this case each Funcref will be tried in order until one of them will return non-empty documentation. For example, here is value of |ViewDoc_sh| variable: > let g:ViewDoc_sh = [ g:ViewDoc_bashhelp, 'ViewDoc_man' ] ------------------------------------------------------------------------------ Handler: DEFAULT *ViewDoc_DEFAULT* If there is no handler for current filetype then |ViewDoc_man| will be used. To change default handler to, for ex., |ViewDoc_help|, add to ~/.vimrc: > let g:ViewDoc_DEFAULT = 'ViewDoc_help' Or you can use function reference instead of function name, but this may require delaying until this function will be loaded (if it isn't defined in ~/.vimrc): > autocmd VimEnter * let g:ViewDoc_DEFAULT = g:ViewDoc_help ------------------------------------------------------------------------------ Handler: man *ViewDoc_man* Show doc using |g:viewdoc_man_cmd| command when {filetype} is "man". Also used as default handler, see |ViewDoc_DEFAULT|. Added commands: |:man| |:ViewDocMan|. Added settings: |g:viewdoc_man_cmd|. To view man pages in Vim from console add this script to ~/bin/man: > #!/bin/bash if [ ${1:0:1} == "-" ]; then exec /usr/bin/man $* else exec vim -c "ViewDocMan $*" -c tabonly fi NOTE For compatibility with autosess plugin (vimscript 3883) change last exec line in above script to: > exec vim --cmd 'let g:loaded_autosess=1' -c "ViewDocMan $*" -c tabonly ------------------------------------------------------------------------------ Handler: help *ViewDoc_help* Show standard Vim help when {filetype} is "vim" or "help". Viewing Vim help using this plugin have some advantages: * much better control how and where help window will be opened * smart detection ( on "&opt" will show help for 'opt', etc.) * and, of course, using to close help Added commands: |:help| |:h| |:ViewDocHelp|. ------------------------------------------------------------------------------ Handler: help_custom *ViewDoc_help_custom* Show doc for any {filetype} using separate .txt files written in Vim help format and stored in directory 'runtimepath'/ftdoc/{filetype}/ (no such help files provided with this plugin, you should download or write them yourself). Examples of external docs which can be used with this handler: * CSS 2.1, from http://www.vim.org/scripts/script.php?script_id=918 Create directory ~/.vim/ftdoc/css: > :!mkdir -p ~/.vim/ftdoc/css/ < Copy .txt file from archive into ~/.vim/ftdoc/css/css21.txt, and run: > :helptags ~/.vim/ftdoc/css/ < Add to ~/.vimrc: > let g:ViewDoc_css = 'ViewDoc_help_custom' < * CMake, from http://www.vim.org/scripts/script.php?script_id=3045 Create directory ~/.vim/ftdoc/cmake: > :!mkdir -p ~/.vim/ftdoc/cmake/ < Copy *.txt files from archive into ~/.vim/ftdoc/cmake/*.txt, and run: > :helptags ~/.vim/ftdoc/cmake/ < Add to ~/.vimrc: > let g:ViewDoc_cmake = 'ViewDoc_help_custom' < * LaTeX, from http://vim-latex.sourceforge.net/download/latexhelp.txt Create directory ~/.vim/ftdoc/tex: > :!mkdir -p ~/.vim/ftdoc/tex/ < Copy latexhelp.txt file into ~/.vim/ftdoc/tex/latexhelp.txt, and run: > :helptags ~/.vim/ftdoc/tex/ < Add to ~/.vimrc: > let g:ViewDoc_tex = 'ViewDoc_help_custom' ------------------------------------------------------------------------------ Handler: perldoc *ViewDoc_perldoc* Show doc using `perldoc` command when {filetype} is "perl" or "perldoc". Added commands: |:perldoc| |:ViewDocPerl|. ------------------------------------------------------------------------------ Handler: godoc *ViewDoc_godoc* Show doc using |g:viewdoc_godoc_cmd| command when {filetype} is "go". Show package source using |g:viewdoc_godoc_cmd| command when {filetype} is "godoc". Added commands: |:godoc| |:ViewDocGo|. Added settings: |g:viewdoc_godoc_cmd|. ------------------------------------------------------------------------------ Handler: pydoc *ViewDoc_pydoc* Show doc using |g:viewdoc_pydoc_cmd| command when {filetype} is "python" or "pydoc". Added commands: |:pydoc| |:ViewDocPydoc|. Added settings: |g:viewdoc_pydoc_cmd|. ------------------------------------------------------------------------------ Handler: pman *ViewDoc_pman* Show doc using |g:viewdoc_pman_cmd| command when {filetype} is "php" or "pman". Added commands: |:pman| |:ViewDocPman|. Added settings: |g:viewdoc_pman_cmd|. ------------------------------------------------------------------------------ Handler: infman *ViewDoc_infman* Show doc using |g:viewdoc_infman_cmd| command when {filetype} is "limbo" or "infman". Added commands: |:infman| |:ViewDocInfman|. Added settings: |g:viewdoc_infman_cmd|. ------------------------------------------------------------------------------ Handler: ri *ViewDoc_ri* Show doc using |g:viewdoc_ri_cmd| command when {filetype} is "ruby" or "rdoc". Added commands: |:rdoc| |:ViewDocRi|. Added settings: |g:viewdoc_ri_cmd|. ------------------------------------------------------------------------------ Handler: bashhelp *ViewDoc_bashhelp* Show doc using bash's `help` command when {filetype} is "sh", if not found then fallback to |:ViewDoc_man|. Added commands: |:bashhelp| |:ViewDocBashHelp|. ------------------------------------------------------------------------------ Handler: info *ViewDoc_info* Show doc using |g:viewdoc_info_cmd| command when {filetype} is "info" or "awk" or "make" or "m4" or "automake". Added commands: |:info| |:ViewDocInfo|. Added settings: |g:viewdoc_info_cmd|, |g:viewdoc_info_path|. ============================================================================== SOURCE AND ISSUE TRACKER *viewdoc-source* https://github.com/powerman/vim-plugin-viewdoc ============================================================================== CONTRIBUTORS *viewdoc-contributors* In alphabetical order:~ Artem Nezvigin (github: artnez) * Ruby (ri) support pawel.wiecek@tieto.com * Make viewdoc buffers easier to identify * LaTeX (help_custom) support * Add b:topic * Support for multiple documentation providers per filetype * Bash's help support * GNU info (smart support for: awk, make, m4, automake) Robin Schneider (github: ypid) * Add g:viewdoc_copy_to_search_reg ============================================================================== LICENSE *viewdoc-license* Public Domain. ftplugin/perldoc_ansi_viewdoc.vim [[[1 21 if exists('b:did_ftplugin_viewdoc') finish endif let b:did_ftplugin_viewdoc = 1 setlocal iskeyword+=: if exists(':AnsiEsc') if exists('b:ansiesc') AnsiEsc endif AnsiEsc let b:ansiesc = 1 else echomsg 'Require Improved AnsiEsc http://www.vim.org/scripts/script.php?script_id=4979' endif let b:undo_ftplugin = exists('b:undo_ftplugin') ? b:undo_ftplugin . '|' : '' let b:undo_ftplugin .= 'setlocal iskeyword<' \ . '|unlet b:did_ftplugin_viewdoc' ftplugin/make_viewdoc.vim [[[1 12 if exists('b:did_ftplugin_viewdoc') finish endif let b:did_ftplugin_viewdoc = 1 setlocal iskeyword+=.,@-@,%,<,?,+,\|,*,^ let b:undo_ftplugin = exists('b:undo_ftplugin') ? b:undo_ftplugin . '|' : '' let b:undo_ftplugin .= 'setlocal iskeyword<' \ . '|unlet b:did_ftplugin_viewdoc' ftplugin/man_viewdoc.vim [[[1 12 if exists('b:did_ftplugin_viewdoc') finish endif let b:did_ftplugin_viewdoc = 1 setlocal iskeyword+=(,) let b:undo_ftplugin = exists('b:undo_ftplugin') ? b:undo_ftplugin . '|' : '' let b:undo_ftplugin .= 'setlocal iskeyword<' \ . '|unlet b:did_ftplugin_viewdoc' ftplugin/ri_markdown_viewdoc.vim [[[1 12 if exists('b:did_ftplugin_viewdoc') finish endif let b:did_ftplugin_viewdoc = 1 setlocal syntax=markdown let b:undo_ftplugin = exists('b:undo_ftplugin') ? b:undo_ftplugin . '|' : '' let b:undo_ftplugin .= 'setlocal syntax<' \ . '|unlet b:did_ftplugin_viewdoc' ftplugin/pman_viewdoc.vim [[[1 13 if exists('b:did_ftplugin_viewdoc') finish endif let b:did_ftplugin_viewdoc = 1 setlocal iskeyword+=(,) setlocal syntax=man let b:undo_ftplugin = exists('b:undo_ftplugin') ? b:undo_ftplugin . '|' : '' let b:undo_ftplugin .= 'setlocal iskeyword< syntax<' \ . '|unlet b:did_ftplugin_viewdoc' ftplugin/vim_viewdoc.vim [[[1 12 if exists('b:did_ftplugin_viewdoc') finish endif let b:did_ftplugin_viewdoc = 1 setlocal iskeyword+=:,\<,\>,- let b:undo_ftplugin = exists('b:undo_ftplugin') ? b:undo_ftplugin . '|' : '' let b:undo_ftplugin .= 'setlocal iskeyword<' \ . '|unlet b:did_ftplugin_viewdoc' ftplugin/css_viewdoc.vim [[[1 12 if exists('b:did_ftplugin_viewdoc') finish endif let b:did_ftplugin_viewdoc = 1 setlocal iskeyword+=- let b:undo_ftplugin = exists('b:undo_ftplugin') ? b:undo_ftplugin . '|' : '' let b:undo_ftplugin .= 'setlocal iskeyword<' \ . '|unlet b:did_ftplugin_viewdoc' ftplugin/perldoc_text_viewdoc.vim [[[1 12 if exists('b:did_ftplugin_viewdoc') finish endif let b:did_ftplugin_viewdoc = 1 setlocal iskeyword+=: let b:undo_ftplugin = exists('b:undo_ftplugin') ? b:undo_ftplugin . '|' : '' let b:undo_ftplugin .= 'setlocal iskeyword<' \ . '|unlet b:did_ftplugin_viewdoc' ftplugin/ri_rdoc_viewdoc.vim [[[1 12 if exists('b:did_ftplugin_viewdoc') finish endif let b:did_ftplugin_viewdoc = 1 setlocal syntax=rdoc let b:undo_ftplugin = exists('b:undo_ftplugin') ? b:undo_ftplugin . '|' : '' let b:undo_ftplugin .= 'setlocal syntax<' \ . '|unlet b:did_ftplugin_viewdoc' ftplugin/tex_viewdoc.vim [[[1 12 if exists('b:did_ftplugin_viewdoc') finish endif let b:did_ftplugin_viewdoc = 1 setlocal iskeyword+=\\ let b:undo_ftplugin = exists('b:undo_ftplugin') ? b:undo_ftplugin . '|' : '' let b:undo_ftplugin .= 'setlocal iskeyword<' \ . '|unlet b:did_ftplugin_viewdoc' ftplugin/ri_ansi_viewdoc.vim [[[1 20 if exists('b:did_ftplugin_viewdoc') finish endif let b:did_ftplugin_viewdoc = 1 if exists(':AnsiEsc') if exists('b:ansiesc') AnsiEsc endif AnsiEsc let b:ansiesc = 1 else echomsg 'Require Improved AnsiEsc http://www.vim.org/scripts/script.php?script_id=4979' endif let b:undo_ftplugin = exists('b:undo_ftplugin') ? b:undo_ftplugin . '|' : '' let b:undo_ftplugin .= '' \ . '|unlet b:did_ftplugin_viewdoc' ftplugin/infman_viewdoc.vim [[[1 13 if exists('b:did_ftplugin_viewdoc') finish endif let b:did_ftplugin_viewdoc = 1 setlocal iskeyword+=(,) setlocal syntax=man let b:undo_ftplugin = exists('b:undo_ftplugin') ? b:undo_ftplugin . '|' : '' let b:undo_ftplugin .= 'setlocal iskeyword< syntax<' \ . '|unlet b:did_ftplugin_viewdoc' ftplugin/help_viewdoc.vim [[[1 12 if exists('b:did_ftplugin_viewdoc') finish endif let b:did_ftplugin_viewdoc = 1 setlocal iskeyword=!-~,^*,^\|,^\",192-255 let b:undo_ftplugin = exists('b:undo_ftplugin') ? b:undo_ftplugin . '|' : '' let b:undo_ftplugin .= 'setlocal iskeyword<' \ . '|unlet b:did_ftplugin_viewdoc' ftplugin/perl_viewdoc.vim [[[1 12 if exists('b:did_ftplugin_viewdoc') finish endif let b:did_ftplugin_viewdoc = 1 setlocal iskeyword+=: let b:undo_ftplugin = exists('b:undo_ftplugin') ? b:undo_ftplugin . '|' : '' let b:undo_ftplugin .= 'setlocal iskeyword<' \ . '|unlet b:did_ftplugin_viewdoc' plugin/viewdoc_bashhelp.vim [[[1 39 " Maintainer: see in viewdoc.vim " Version: see in viewdoc.vim " Last Modified: see in viewdoc.vim " License: see in viewdoc.vim " URL: see in viewdoc.vim " Description: ViewDoc handler for shell scripts if exists('g:loaded_viewdoc_bash') || &cp || version < 700 finish endif let g:loaded_viewdoc_bash = 1 """ Interface " - command command -bar -bang -nargs=1 ViewDocBashHelp \ call ViewDoc(''=='' ? 'new' : 'doc', , 'bashhelp') " - abbrev if !exists('g:no_plugin_abbrev') && !exists('g:no_viewdoc_abbrev') cnoreabbrev bashhelp getcmdtype()==':' && getcmdline()=='bashhelp' ? 'ViewDocBashHelp' : 'bashhelp' cnoreabbrev bashhelp! getcmdtype()==':' && getcmdline()=='bashhelp!' ? 'ViewDocBashHelp' : 'bashhelp!' endif """ Handlers " let h = ViewDoc_bashhelp('echo') function s:ViewDoc_bashhelp(topic, ...) return { 'cmd': printf('bash -c "help -m %s" 2>/dev/null', shellescape(a:topic,1)), \ 'ft': 'man', \ } endfunction " use function(s:SID().'Foo') instead of function('s:Foo') for " compatibility with Vim-7.3.x (7.3.762 at least) function s:SID() return matchstr(expand(''), '\zs\d\+_\zeSID$') endfunction let g:ViewDoc_bashhelp = function(s:SID().'ViewDoc_bashhelp') let g:ViewDoc_sh = [ g:ViewDoc_bashhelp, 'ViewDoc_man' ] plugin/viewdoc_help.vim [[[1 95 " Maintainer: see in viewdoc.vim " Version: see in viewdoc.vim " Last Modified: see in viewdoc.vim " License: see in viewdoc.vim " URL: see in viewdoc.vim " Description: ViewDoc handler for vim help files if exists('g:loaded_viewdoc_help') || &cp || version < 700 finish endif let g:loaded_viewdoc_help = 1 """ Interface " - command command -bar -bang -nargs=1 -complete=help ViewDocHelp \ call ViewDoc(''=='' ? 'new' : 'doc', , 'help') " - abbrev if !exists('g:no_plugin_abbrev') && !exists('g:no_viewdoc_abbrev') cnoreabbrev h getcmdtype()==':' && getcmdline()=='h' ? 'ViewDocHelp' : 'h' cnoreabbrev h! getcmdtype()==':' && getcmdline()=='h!' ? 'ViewDocHelp' : 'h!' cnoreabbrev help getcmdtype()==':' && getcmdline()=='help' ? 'ViewDocHelp' : 'help' cnoreabbrev help! getcmdtype()==':' && getcmdline()=='help!' ? 'ViewDocHelp' : 'help!' endif """ Handlers function s:ViewDoc_help(topic, filetype, synid, ctx) let h = { 'ft': 'help', \ 'topic': a:topic, \ } if a:ctx if h.topic !~ "^'.*'$" && (synIDattr(a:synid,'name') =~# 'Option' || search('&\k*\%#','n')) let h.topic = "'" . h.topic . "'" " auto-detect: 'option' elseif synIDattr(a:synid,'name') =~ 'Command' let h.topic = ':' . h.topic " auto-detect: :command endif endif try let savetabnr = tabpagenr() execute 'noautocmd tab help ' . h.topic let helpfile = expand('%:p') let cat = helpfile =~? 'gz$' ? 'zcat' : 'cat' let h.cmd = printf('%s %s', cat, shellescape(helpfile,1)) let h.line = line('.') let h.col = col('.') let h.tags = substitute(helpfile, '/[^/]*$', '/tags', '') noautocmd tabclose execute 'noautocmd tabnext ' . savetabnr catch endtry return h endfunction " use function(s:SID().'Foo') instead of function('s:Foo') for " compatibility with Vim-7.3.x (7.3.762 at least) function s:SID() return matchstr(expand(''), '\zs\d\+_\zeSID$') endfunction let g:ViewDoc_help = function(s:SID().'ViewDoc_help') let g:ViewDoc_vim = function(s:SID().'ViewDoc_help') function s:ViewDoc_help_custom(topic, ft, ...) let h = { 'ft': 'help', \ 'docft': a:ft, \ } let savetabnr = tabpagenr() for helpfile in split(globpath(&runtimepath, 'ftdoc/'.a:ft.'/*.txt'),"\") let tagsfile = substitute(helpfile, '/[^/]*$', '/tags', '') execute 'tabedit ' . helpfile execute 'setlocal tags^=' . tagsfile for tag_guess in [a:topic, "'".a:topic."'", a:ft.'-'.a:topic] try execute 'tag ' . tag_guess catch continue endtry let h.cmd = printf('cat %s', shellescape(helpfile,1)) let h.line = line('.') let h.col = col('.') let h.tags = tagsfile break endfor setlocal bufhidden=delete tabclose if exists('h.cmd') break endif endfor execute 'tabnext ' . savetabnr return h endfunction let g:ViewDoc_help_custom = function(s:SID().'ViewDoc_help_custom') plugin/viewdoc_info.vim [[[1 239 " Author: pawel.wiecek@tieto.com " Maintainer: pawel.wiecek@tieto.com " Version: see in viewdoc.vim " Last Modified: see in viewdoc.vim " License: see in viewdoc.vim " URL: see in viewdoc.vim " Description: ViewDoc handler for GNU info if exists('g:loaded_viewdoc_info') || &cp || version < 700 finish endif let g:loaded_viewdoc_info = 1 """ Options " path of "info" program (original standalone info viewer) if !exists('g:viewdoc_info_cmd') let g:viewdoc_info_cmd = 'info' endif " directories containing info files if !exists('g:viewdoc_info_path') let g:viewdoc_info_path = '/usr/share/info' endif """ Interface " - command " Can be called: " - with no parameters, will load info directory " - with one parameter, will load named node (if in (file)node format) or top " page for named manual " - with two or more parameters, will use first parameter as manual name " (parentheses are optional) and all other parameters as node name " eg. :ViewDocInfo gawk Getting Started will load "(gawk)Getting Started" command -bar -bang -nargs=* -complete=custom,s:CompleteInfo ViewDocInfo \ call ViewDoc(''=='' ? 'new' : 'doc', s:ParamsToNode(), 'infocmd') " - abbrev if !exists('g:no_plugin_abbrev') && !exists('g:no_viewdoc_abbrev') cnoreabbrev info getcmdtype()==':' && getcmdline()=='info' ? 'ViewDocInfo' : 'info' cnoreabbrev info! getcmdtype()==':' && getcmdline()=='info!' ? 'ViewDocInfo' : 'info!' endif """ Handlers " Handler for navigation inside info file. " Parsing logic does draw some inspiration from " http://www.vim.org/scripts/script.php?script_id=21 " (especially in "note" links handling) function s:ViewDoc_info(topic, filetype, synid, ctx) let h = { 'ft': 'info' } let nothing = { 'ft': 'info', 'cmd': 'false' } if a:ctx let current_line = getline('.') let same_file = matchstr(b:topic, '(.*)') " patterns below contain some empty groups \(\), this is intentional, " because we want to have link parts in the same groups, no matte whet " format the link has if synIDattr(a:synid, 'name') == 'infoLinkDir' || \ synIDattr(a:synid, 'name') == 'infoDirTarget' " links in main directory let pattern = '^\* [^:]\+: \(([^)]\+)\)\([^.]*\)\.\(\)' elseif synIDattr(a:synid, 'name') == 'infoLinkMenu' " links in standard menu let pattern = '^\* \(\)\([^:]*\)::\(\)' elseif synIDattr(a:synid, 'name') == 'infoLinkIndex' || \ synIDattr(a:synid, 'name') == 'infoIndexTarget' || \ synIDattr(a:synid, 'name') == 'infoIndexLine' " links in index page -- sometimes line number is wrapped to next line, " so we concatenate it if current line alone doesn't match let pattern = '^\* [^:]\+:\s*\(\)\([^.]\+\)\.\s*(line\s\+\([0-9]\+\))$' if matchstr(current_line, pattern) == '' let current_line = current_line.' '.getline(line('.') + 1) endif elseif synIDattr(a:synid, 'name') == 'infoLinkNote' " "note" links inside pages, these can span multiple lines let current_line = current_line.' '.getline(line('.') + 1) let pattern = '\*[Nn]ote [^:.]\+: \([^.,]\+\)\%([,.]\|$\)' let link = matchlist(current_line, pattern) if link == [] let pattern = '\*[Nn]ote \([^:]\+\)\%(::\)' let link = matchlist(current_line, pattern) endif let current_line = link[1] let pattern = '^\(([^)]\+)\)\=\s*\(.*\)\(\)' else " not inside a link -- not supported return nothing endif let link = matchlist(current_line, pattern) let file = link[1] !='' ? link[1] : same_file let node = link[2] !='' ? link[2] : 'Top' let h.topic = file . node if link[3] != '' let h.line = str2nr(link[3]) endif else " not inside a link -- not supported return nothing endif let h.cmd = printf('%s %s -o-', g:viewdoc_info_cmd, shellescape(h.topic, 1)) return h endfunction " Handler for keyword searching (needs to have g:ViewDocInfoIndex_{ft} " defined, pointing to info node name (or list of names) of index function s:ViewDoc_info_search(topic, filetype, synid, ctx) let nothing = { 'ft': 'info', 'cmd': 'false' } if exists('g:ViewDocInfoIndex_{a:filetype}') if type(g:ViewDocInfoIndex_{a:filetype}) == type([]) let indices = g:ViewDocInfoIndex_{a:filetype} else let indices = [g:ViewDocInfoIndex_{a:filetype}] endif else return nothing endif let pattern = '^\* [^:]\+:\s*\(\)\([^.]\+\)\.\s*(line\s\+\([0-9]\+\))$' " open a temporary buffer and load indices let savetabnr = tabpagenr() silent noautocmd tabnew setlocal bufhidden=delete setlocal buftype=nofile setlocal noswapfile setlocal nobuflisted for idx in indices execute 'silent $r !' . g:viewdoc_info_cmd . ' ' . shellescape(s:FixNodeName(idx), 1) endfor 1 " search for a first matching index entry if search('^\* ' . a:topic . '\W') let current_line = getline('.') if matchstr(current_line, pattern) == '' let current_line = current_line.' '.getline(line('.') + 1) endif else let current_line = '' endif noautocmd tabclose! execute 'noautocmd tabnext ' . savetabnr if current_line == '' " not found return nothing endif " parse found link let link = matchlist(current_line, pattern) let file = link[1] !='' ? link[1] : matchstr(s:FixNodeName(indices[0]), '(.*)') let node = link[2] !='' ? link[2] : 'Top' let h = { 'ft': 'info', \ 'topic': file . node } if link[3] != '' let h.line = str2nr(link[3]) endif let h.cmd = printf('%s %s -o-', g:viewdoc_info_cmd, shellescape(h.topic, 1)) return h endfunction " Handler for command line commands function s:ViewDoc_info_cmd(topic, ...) let h = { 'ft': 'info', \ 'topic': s:FixNodeName(a:topic) } let h.cmd = printf('%s %s -o-', g:viewdoc_info_cmd, shellescape(h.topic, 1)) return h endfunction """ Internal " Converts :ViewDocInfo parameters to info node name to pass to ViewInfo as a " topic function s:ParamsToNode(...) if a:0 == 0 return '(dir)Top' elseif a:0 == 1 if a:1 =~ '^(.\+)' return a:1 else return printf('(%s)Top', a:1) endif else if a:1 =~ '^(.\+)' return join(a:000, ' ') else return printf('(%s)%s', a:1, join(a:000[1:], ' ')) endif endif endfunction " Helper to fix (file) parts where manuals have versioned filenames function s:FixNodeName(node) let file = substitute(a:node, '^(\([^)]\+\)).*', '\1', '') if globpath('/usr/share/info', file.'.info*') == '' let filenames = split(globpath('/usr/share/info', file.'-*.info*')) let candidates = [] for fn in filenames call add(candidates, substitute(fn, '^.*/\([^/]\+\)\.info.*$', '\1', '')) endfor if candidates != [] return substitute(a:node, '('.file.')', '('.sort(candidates)[-1].')', '') endif endif return a:node endfunction " Completion generator " Completes: manual names when invoked for 1st parameter, " node names from manual, whose name is param1 when invoked for any other " parameter function s:CompleteInfo(ArgLead, CmdLine, CursorPos) let parts = split(strpart(a:CmdLine, 0, a:CursorPos).'|') if len(parts)>2 let heads = system(g:viewdoc_info_cmd . ' --subnodes ' . \ shellescape(parts[1], 1) . " 2>/dev/null | grep '^File: .*, Node:'") return substitute(heads, 'File: [^\n]*, Node: \([^,]*\), [^\n]*', '\1', 'g') else return substitute(substitute(globpath(g:viewdoc_info_path, '*.info*'), \ '[^\n]*/\([^/]\+\).info[^\n]*', '\1', 'g'), \ '\([^\n]*\n\)\1*', '\1', 'g') endif endfunction """ Per-type public settings " per type exported configuration for (main) viewdoc function s:SID() return matchstr(expand(''), '\zs\d\+_\zeSID$') endfunction let g:ViewDoc_info = function(s:SID().'ViewDoc_info') let g:ViewDoc_infocmd = function(s:SID().'ViewDoc_info_cmd') let g:ViewDoc_search = function(s:SID().'ViewDoc_info_search') let g:ViewDoc_awk = function(s:SID().'ViewDoc_info_search') let g:ViewDoc_make = function(s:SID().'ViewDoc_info_search') let g:ViewDoc_m4 = function(s:SID().'ViewDoc_info_search') let g:ViewDoc_automake = function(s:SID().'ViewDoc_info_search') " per type index node configuration let g:ViewDocInfoIndex_awk = '(gawk)Index' let g:ViewDocInfoIndex_make = '(make)Name Index' let g:ViewDocInfoIndex_m4 = '(m4)Macro index' let g:ViewDocInfoIndex_automake = ['(automake)Macro Index', '(automake)Variable Index'] plugin/viewdoc_pman.vim [[[1 93 " Maintainer: see in viewdoc.vim " Version: see in viewdoc.vim " Last Modified: see in viewdoc.vim " License: see in viewdoc.vim " URL: see in viewdoc.vim " Description: ViewDoc handler for php man pages if exists('g:loaded_viewdoc_pman') || &cp || version < 700 finish endif let g:loaded_viewdoc_pman = 1 """ Constants let s:re_mansect = '\([0-9]\)' """ Options if !exists('g:viewdoc_pman_cmd') let g:viewdoc_pman_cmd='pman' endif """ Interface " - command command -bar -bang -nargs=1 -complete=custom,s:CompleteMan ViewDocPman \ call ViewDoc(''=='' ? 'new' : 'doc', , 'pman') " - abbrev if !exists('g:no_plugin_abbrev') && !exists('g:no_viewdoc_abbrev') cnoreabbrev pman getcmdtype()==':' && getcmdline()=='pman' ? 'ViewDocPman' : 'pman' cnoreabbrev pman! getcmdtype()==':' && getcmdline()=='pman!' ? 'ViewDocPman' : 'pman!' endif """ Handlers " let h = ViewDoc_pman('error_reporting') " let h = ViewDoc_pman('error_reporting(3)') " let h = ViewDoc_pman('2 error_reporting') function s:ViewDoc_pman(topic, ...) let sect = '' let name = a:topic let m = matchlist(name, '('.s:re_mansect.')\.\?$') if (len(m)) let sect = m[1] let name = substitute(name, '('.s:re_mansect.')\.\?$', '', '') endif let m = matchlist(name, '^'.s:re_mansect.'\s\+') if (len(m)) let sect = m[1] let name = substitute(name, '^'.s:re_mansect.'\s\+', '', '') endif return { 'cmd': printf('%s %s %s | sed "s/ \xB7 / * /" | col -b', g:viewdoc_pman_cmd, sect, shellescape(name,1)), \ 'ft': 'pman', \ } endfunction " use function(s:SID().'Foo') instead of function('s:Foo') for " compatibility with Vim-7.3.x (7.3.762 at least) function s:SID() return matchstr(expand(''), '\zs\d\+_\zeSID$') endfunction let g:ViewDoc_pman = function(s:SID().'ViewDoc_pman') let g:ViewDoc_php = function(s:SID().'ViewDoc_pman') """ Internal " Autocomplete section: time( ti.*( " Autocomplete command: tim ti.*e " Autocomplete command in section: 2 tim 2 ti.*e function s:CompleteMan(ArgLead, CmdLine, CursorPos) call ViewDoc_SetShellToBash() let manpath = substitute(system(printf('%s --path', g:viewdoc_pman_cmd)),'\n$','','') if manpath =~ ':' let manpath = '{'.join(map(split(manpath,':'),'shellescape(v:val,1)'),',').'}' else let manpath = shellescape(manpath,1) endif if strpart(a:CmdLine, a:CursorPos - 1) == '(' let m = matchlist(a:CmdLine, '\s\(\S\+\)($') if !len(m) call ViewDoc_RestoreShell() return '' endif 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)/"', \ manpath, shellescape(m[1],1))) else let m = matchlist(a:CmdLine, '\s'.s:re_mansect.'\s') let sect = len(m) ? m[1] : '*' let res = system(printf('find %s/man%s -type f -printf "%%f\n" 2>/dev/null | sed "s/\.bz2$\|\.gz$//;s/\.[^.]*$//" | sort -u', \ manpath, sect)) endif call ViewDoc_RestoreShell() return res endfunction plugin/viewdoc_ri.vim [[[1 50 " Maintainer: see in viewdoc.vim " Version: see in viewdoc.vim " Last Modified: see in viewdoc.vim " License: see in viewdoc.vim " URL: see in viewdoc.vim " Description: ViewDoc handler for ri if exists('g:loaded_viewdoc_ri') || &cp || version < 700 finish endif let g:loaded_viewdoc_ri = 1 """ Options if !exists('g:viewdoc_ri_cmd') let g:viewdoc_ri_cmd='ri' " user may want 'ri20' endif if !exists('g:viewdoc_ri_format') let g:viewdoc_ri_format='markdown' " user may want 'rdoc' endif """ Interface " - command command -bar -bang -nargs=1 ViewDocRi \ call ViewDoc(''=='' ? 'new' : 'doc', , 'ri') " - abbrev if !exists('g:no_plugin_abbrev') && !exists('g:no_viewdoc_abbrev') cnoreabbrev rdoc getcmdtype()==':' && getcmdline()=='rdoc' ? 'ViewDocRi' : 'rdoc' cnoreabbrev rdoc! getcmdtype()==':' && getcmdline()=='rdoc!' ? 'ViewDocRi' : 'rdoc!' endif """ Handlers function s:ViewDoc_ri(topic, ...) return { 'cmd': printf('%s --format=%s %s | grep -v "Nothing known about"', g:viewdoc_ri_cmd, g:viewdoc_ri_format, shellescape(a:topic,1)), \ 'ft': 'ri_'.g:viewdoc_ri_format, \ } endfunction " use function(s:SID().'Foo') instead of function('s:Foo') for " compatibility with Vim-7.3.x (7.3.762 at least) function s:SID() return matchstr(expand(''), '\zs\d\+_\zeSID$') endfunction let g:ViewDoc_ri = function(s:SID().'ViewDoc_ri') let g:ViewDoc_ruby = function(s:SID().'ViewDoc_ri') let g:ViewDoc_ri_bs = function(s:SID().'ViewDoc_ri') let g:ViewDoc_ri_ansi = function(s:SID().'ViewDoc_ri') let g:ViewDoc_ri_rdoc = function(s:SID().'ViewDoc_ri') let g:ViewDoc_ri_markdown = function(s:SID().'ViewDoc_ri') plugin/viewdoc_perldoc.vim [[[1 121 " Maintainer: see in viewdoc.vim " Version: see in viewdoc.vim " Last Modified: see in viewdoc.vim " License: see in viewdoc.vim " URL: see in viewdoc.vim " Description: ViewDoc handler for perldoc if exists('g:loaded_viewdoc_perldoc') || &cp || version < 700 finish endif let g:loaded_viewdoc_perldoc = 1 """ Options if !exists('g:viewdoc_perldoc_format') let g:viewdoc_perldoc_format='text' " user may want 'ansi' endif """ Interface " - command command -bar -bang -nargs=1 -complete=custom,s:CompletePerl ViewDocPerl \ call ViewDoc(''=='' ? 'new' : 'doc', , 'perl') " - abbrev if !exists('g:no_plugin_abbrev') && !exists('g:no_viewdoc_abbrev') cnoreabbrev perldoc getcmdtype()==':' && getcmdline()=='perldoc' ? 'ViewDocPerl' : 'perldoc' cnoreabbrev perldoc! getcmdtype()==':' && getcmdline()=='perldoc!' ? 'ViewDocPerl' : 'perldoc!' endif """ Handlers function s:ViewDoc_perldoc(topic, filetype, synid, ctx) let h = { 'ft': 'perldoc_' . g:viewdoc_perldoc_format, \ 'topic': a:topic, \ } if a:ctx && a:filetype == 'perldoc_ansi' " remove tail of concealed ANSI sequence before let h.topic = substitute(h.topic, '^[0-9]\+m', '', '') endif let synname = a:ctx ? synIDattr(a:synid,'name') : '' if synname =~# 'SharpBang' let h.topic = 'perlrun' elseif synname =~# 'StatementFiles' && len(h.topic) == 1 let h.topic = '-X' elseif synname =~# 'Conditional\|Repeat\|Label' let h.topic = 'perlsyn' elseif synname =~# 'SubPrototype\|SubAttribute' let h.topic = 'perlsub' elseif h.topic ==# 'AUTOLOAD' let h.topic = 'perlsub' let h.search= '^\s*Autoloading\>' elseif h.topic ==# 'DESTROY' let h.topic = 'perlobj' let h.search= '^\s*Destructors\>' elseif h.topic =~# '^__[A-Z]\+__$' let h.topic = 'perldata' let h.search= '^\s*Special\s\+Literals' elseif h.topic ==# 'tr' || h.topic ==# 'y' let h.topic = 'perlop' let h.search= '^\s*tr\/' elseif h.topic =~# '^q[qxw]\?$' let h.search= '^\s*' . h.topic . '\/' let h.topic = 'perlop' elseif synname =~# 'StringStartEnd\|perlQQ' let h.topic = 'perlop' let h.search= '^\s*Quote\s\+and\s\+Quote-[Ll]ike\s\+Operators\s*$' elseif h.topic =~# '^\(BEGIN\|UNITCHECK\|CHECK\|INIT\|END\)$' let h.topic = 'perlmod' let h.search= '^\s*BEGIN,' elseif synname =~# '^pod[A-Z]\|POD' || h.topic =~# '^=[a-z]' || h.topic =~# '^[A-Z]<' let h.topic = 'perlpod' elseif synname =~# 'Match' let h.topic = 'perlre' elseif synname =~# 'Var' " search for position where current var's name begin (starting with [$@%]) let col = searchpos('[$@%]{\?\^\?\k*\%#\|\%#[$@%]', 'n')[1] " from that position took full var name (plus extra [ or { after it, if any) let var = col == 0 ? '' : matchstr(getline('.'), '^[$@%]{\?^\?.\k*}\?[{\[]\?', col-1) " $a[ -> @a, $a{ -> %a, @a{ -> %a, drop [ or { at end let var = substitute(var, '^$\(.*\)\[$', '@\1', '') let var = substitute(var, '^$\(.*\){$', '%\1', '') let var = substitute(var, '^@\(.*\){$', '%\1', '') let var = substitute(var, '[\[{]$', '', '') " ${a} -> $a, ${^a} -> $^a, but not ${^aa} let var = substitute(var, '^\([$@%]\){\([^^].*\|\^.\)}$', '\1\2', '') let h.topic = var == '' ? h.topic : var endif let t = shellescape(h.topic,1) 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', \ g:viewdoc_perldoc_format, t, g:viewdoc_perldoc_format, t, g:viewdoc_perldoc_format, t) return h endfunction " use function(s:SID().'Foo') instead of function('s:Foo') for " compatibility with Vim-7.3.x (7.3.762 at least) function s:SID() return matchstr(expand(''), '\zs\d\+_\zeSID$') endfunction let g:ViewDoc_perl = function(s:SID().'ViewDoc_perldoc') let g:ViewDoc_perldoc = function(s:SID().'ViewDoc_perldoc') let g:ViewDoc_perldoc_text = function(s:SID().'ViewDoc_perldoc') let g:ViewDoc_perldoc_ansi = function(s:SID().'ViewDoc_perldoc') """ Internal function s:CompletePerl(ArgLead, CmdLine, CursorPos) if exists('s:complete') return s:complete endif call ViewDoc_SetShellToBash() let data= "__FILE__\n__LINE__\n__PACKAGE__\n__DATA__\n__END__\n" let mod = "BEGIN\nUNITCHECK\nCHECK\nINIT\nEND\n" 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') 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') 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') 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') let s:complete = data.mod.pod.var.func.pkg call ViewDoc_RestoreShell() return s:complete endfunction plugin/viewdoc_man.vim [[[1 87 " Maintainer: see in viewdoc.vim " Version: see in viewdoc.vim " Last Modified: see in viewdoc.vim " License: see in viewdoc.vim " URL: see in viewdoc.vim " Description: ViewDoc handler for man pages (default handler) if exists('g:loaded_viewdoc_man') || &cp || version < 700 finish endif let g:loaded_viewdoc_man = 1 """ Constants let s:re_mansect = '\([0-9a-z]\+\)' """ Options if !exists('g:viewdoc_man_cmd') let g:viewdoc_man_cmd='man' " user may want 'LANG=en man' endif """ Interface " - command command -bar -bang -nargs=1 -complete=custom,s:CompleteMan ViewDocMan \ call ViewDoc(''=='' ? 'new' : 'doc', , 'man') " - abbrev if !exists('g:no_plugin_abbrev') && !exists('g:no_viewdoc_abbrev') cnoreabbrev man getcmdtype()==':' && getcmdline()=='man' ? 'ViewDocMan' : 'man' cnoreabbrev man! getcmdtype()==':' && getcmdline()=='man!' ? 'ViewDocMan' : 'man!' endif """ Handlers " let h = ViewDoc_man('time') " let h = ViewDoc_man('time(2)') " let h = ViewDoc_man('2 time') function s:ViewDoc_man(topic, ...) let sect = '' let name = a:topic let m = matchlist(name, '('.s:re_mansect.')\.\?$') if (len(m)) let sect = '-S '.m[1] let name = substitute(name, '('.s:re_mansect.')\.\?$', '', '') endif let m = matchlist(name, '^'.s:re_mansect.'\s\+') if (len(m)) let sect = '-S '.m[1] let name = substitute(name, '^'.s:re_mansect.'\s\+', '', '') endif return { 'cmd': printf('MANWIDTH={{winwidth}} %s %s %s | sed "s/ \xB7 / * /" | col -b', g:viewdoc_man_cmd, sect, shellescape(name,1)), \ 'ft': 'man', \ } endfunction " use function(s:SID().'Foo') instead of function('s:Foo') for " compatibility with Vim-7.3.x (7.3.762 at least) function s:SID() return matchstr(expand(''), '\zs\d\+_\zeSID$') endfunction let g:ViewDoc_man = function(s:SID().'ViewDoc_man') if !exists('g:ViewDoc_DEFAULT') let g:ViewDoc_DEFAULT = g:ViewDoc_man endif """ Internal " Autocomplete section: time( ti.*( " Autocomplete command: tim ti.*e " Autocomplete command in section: 2 tim 2 ti.*e function s:CompleteMan(ArgLead, CmdLine, CursorPos) call ViewDoc_SetShellToBash() if strpart(a:CmdLine, a:CursorPos - 1) == '(' let m = matchlist(a:CmdLine, '\s\(\S\+\)($') if !len(m) call ViewDoc_RestoreShell() return '' endif 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))) else let m = matchlist(a:CmdLine, '\s'.s:re_mansect.'\s') let sect = len(m) ? m[1] : '*' 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)) endif call ViewDoc_RestoreShell() return res endfunction plugin/viewdoc_godoc.vim [[[1 96 " Maintainer: see in viewdoc.vim " Version: see in viewdoc.vim " Last Modified: see in viewdoc.vim " License: see in viewdoc.vim " URL: see in viewdoc.vim " Description: ViewDoc handler for godoc if exists('g:loaded_viewdoc_godoc') || &cp || version < 700 finish endif let g:loaded_viewdoc_godoc = 1 """ Options if !exists('g:viewdoc_godoc_cmd') let g:viewdoc_godoc_cmd='godoc' endif """ Interface " - command command -bar -bang -nargs=1 -complete=customlist,go#package#Complete ViewDocGo \ call ViewDoc(''=='' ? 'new' : 'doc', , 'go') " - abbrev if !exists('g:no_plugin_abbrev') && !exists('g:no_viewdoc_abbrev') cnoreabbrev godoc getcmdtype()==':' && getcmdline()=='godoc' ? 'ViewDocGo' : 'godoc' cnoreabbrev godoc! getcmdtype()==':' && getcmdline()=='godoc!' ? 'ViewDocGo' : 'godoc!' endif """ Handlers " let h = ViewDoc_go('fmt') " let h = ViewDoc_go('fmt Println') function s:ViewDoc_go(topic, filetype, synid, ctx) let h = { 'ft': 'godoc', \ } " This implementation based on code from vim-go plugin: Copyright 2011 The Go Authors. if a:ctx let oldiskeyword = &iskeyword setlocal iskeyword+=. let word = expand('') let &iskeyword = oldiskeyword let word = substitute(word, '[^a-zA-Z0-9\\/._~-]', '', 'g') let words = split(word, '\.\ze[^./]\+$') if len(words) == 1 let synname = synIDattr(a:synid,'name') if synname =~# 'goBoolean\|goBuiltins\|goType\|goSignedInts\|goUnsignedInts\|goFloats\|goComplexes' let words = ['builtin', words[0]] endif endif else let words = split(a:topic, '\s\+') endif if !len(words) let pkg = "" let exported_name = "" elseif len(words) == 1 let pkg = words[0] let exported_name = "" else let pkg = words[0] let exported_name = words[1] endif let packages = go#tool#Imports() if has_key(packages, pkg) let pkg = packages[pkg] endif if exported_name != "" let h.search = '^func '.exported_name.'(\|^type '.exported_name.'\|\%(const\|var\|type\|\s\+\) '.pkg.'\s\+=\s' else let h.search = '\%(const\|var\|type\|\s\+\) '.pkg.'\s\+=\s' endif let h.topic = pkg let h.cmd = printf('%s %s', g:viewdoc_godoc_cmd, shellescape(pkg,1)) return h endfunction function s:ViewDoc_godoc(topic, filetype, synid, ctx) return { 'ft': 'go', \ 'topic': b:topic, \ 'cmd': printf('%s -src %s', g:viewdoc_godoc_cmd, shellescape(b:topic,1)), \ 'search': '^func '.a:topic.'(\|^type '.a:topic.'\|\%(const\|var\|type\|\s\+\) '.a:topic.'\s\+=\s', \ } endfunction " use function(s:SID().'Foo') instead of function('s:Foo') for " compatibility with Vim-7.3.x (7.3.762 at least) function s:SID() return matchstr(expand(''), '\zs\d\+_\zeSID$') endfunction let g:ViewDoc_go = function(s:SID().'ViewDoc_go') let g:ViewDoc_godoc = function(s:SID().'ViewDoc_godoc') plugin/viewdoc_infman.vim [[[1 88 " Maintainer: see in viewdoc.vim " Version: see in viewdoc.vim " Last Modified: see in viewdoc.vim " License: see in viewdoc.vim " URL: see in viewdoc.vim " Description: ViewDoc handler for OS Inferno man pages if exists('g:loaded_viewdoc_infman') || &cp || version < 700 finish endif let g:loaded_viewdoc_infman = 1 """ Constants let s:re_mansect = '\([1-9]\|10\)' """ Options if !exists('g:viewdoc_infman_cmd') let g:viewdoc_infman_cmd='bash -c ''emu-g sh -c "run /lib/sh/profile; $*; shutdown -h"'' --' endif """ Interface " - command command -bar -bang -nargs=1 -complete=custom,s:CompleteInfman ViewDocInfman \ call ViewDoc(''=='' ? 'new' : 'doc', , 'infman') " - abbrev if !exists('g:no_plugin_abbrev') && !exists('g:no_viewdoc_abbrev') cnoreabbrev infman getcmdtype()==':' && getcmdline()=='infman' ? 'ViewDocInfman' : 'infman' cnoreabbrev infman! getcmdtype()==':' && getcmdline()=='infman!' ? 'ViewDocInfman' : 'infman!' endif """ Handlers " let h = ViewDoc_infman('time') " let h = ViewDoc_infman('time(2)') " let h = ViewDoc_infman('2 time') function s:ViewDoc_infman(topic, ...) let sect = '' let name = a:topic let m = matchlist(name, '('.s:re_mansect.')\.\?$') if (len(m)) let sect = m[1] let name = substitute(name, '('.s:re_mansect.')\.\?$', '', '') endif let m = matchlist(name, '^'.s:re_mansect.'\s\+') if (len(m)) let sect = m[1] let name = substitute(name, '^'.s:re_mansect.'\s\+', '', '') endif return { 'cmd': printf('%s man %s %s', \ g:viewdoc_infman_cmd, sect, shellescape(name,1)), \ 'ft': 'infman', \ } endfunction " use function(s:SID().'Foo') instead of function('s:Foo') for " compatibility with Vim-7.3.x (7.3.762 at least) function s:SID() return matchstr(expand(''), '\zs\d\+_\zeSID$') endfunction let g:ViewDoc_infman = function(s:SID().'ViewDoc_infman') let g:ViewDoc_limbo = function(s:SID().'ViewDoc_infman') """ Internal " Autocomplete section: time( ti.*( " Autocomplete command: tim ti.*e " Autocomplete command in section: 2 tim 2 ti.*e function s:CompleteInfman(ArgLead, CmdLine, CursorPos) call ViewDoc_SetShellToBash() if strpart(a:CmdLine, a:CursorPos - 1) == '(' let m = matchlist(a:CmdLine, '\s\(\S\+\)($') if !len(m) call ViewDoc_RestoreShell() return '' endif let res = system(printf('%s man -w %s | sed ''s/\/man\/\([0-9]\+\)\/\(.*\)/\2(\1)/''', \ g:viewdoc_infman_cmd, shellescape(m[1],1))) else let m = matchlist(a:CmdLine, '\s'.s:re_mansect.'\s') let sect = len(m) ? m[1] : '*' let res = system(printf('%s cat /man/%s/INDEX | sed "s/ .*//" | sort -u', \ g:viewdoc_infman_cmd, sect)) endif call ViewDoc_RestoreShell() return res endfunction plugin/viewdoc.vim [[[1 336 " Maintainer: Alex Efros " Version: 1.3 " Last Modified: May 11, 2012 " License: This file is placed in the public domain. " URL: http://www.vim.org/scripts/script.php?script_id=3893 " Description: Flexible viewer for any documentation (help/man/perldoc/etc.) if exists('g:loaded_viewdoc') || &cp || version < 700 finish endif let g:loaded_viewdoc = 1 """ Constants let s:bufname = '[Doc]' """ Variables let s:bufid = 0 """ Options if !exists('g:viewdoc_open') let g:viewdoc_open='tabnew' endif if !exists('g:viewdoc_only') let g:viewdoc_only=0 endif if !exists('g:viewdoc_prevtabonclose') let g:viewdoc_prevtabonclose=1 endif if !exists('g:viewdoc_openempty') let g:viewdoc_openempty=1 endif if !exists('g:viewdoc_dontswitch') let g:viewdoc_dontswitch=0 endif if !exists('g:viewdoc_copy_to_search_reg') let g:viewdoc_copy_to_search_reg=0 endif """ Interface " - command command -bar -bang -nargs=+ ViewDoc \ call ViewDoc(''=='' ? 'new' : 'doc', ) " - abbrev if !exists('g:no_plugin_abbrev') && !exists('g:no_viewdoc_abbrev') cnoreabbrev doc getcmdtype()==':' && getcmdline()=='doc' ? 'ViewDoc' : 'doc' cnoreabbrev doc! getcmdtype()==':' && getcmdline()=='doc!' ? 'ViewDoc!' : 'doc!' endif " - map if !exists('g:no_plugin_maps') && !exists('g:no_viewdoc_maps') if g:viewdoc_copy_to_search_reg inoremap :let @/ = '\<'.expand('').'\>':call ViewDoc('new', '') nnoremap :let @/ = '\<'.expand('').'\>':call ViewDoc('new', '') nnoremap K :let @/ = '\<'.expand('').'\>':call ViewDoc('doc', '') else inoremap :call ViewDoc('new', '') nnoremap :call ViewDoc('new', '') nnoremap K :call ViewDoc('doc', '') endif endif " - function " call ViewDoc('new', '') auto-detect context/syntax and file type " call ViewDoc('doc', 'bash') auto-detect only file type " call ViewDoc('new', ':execute', 'help') no auto-detect function ViewDoc(target, topic, ...) let hh = s:GetHandles(a:topic, a:0 > 0 ? a:1 : &ft) if a:target != 'inplace' let prev_tabpagenr = tabpagenr() call s:OpenBuf(a:target) let b:stack = 0 endif " Force same settings as :help does " https://bitbucket.org/ZyX_I/vim/src/8d8a30a648f05a91c3c433f0e01343649449ca3c/src/ex_cmds.c#cl-3523 setlocal tabstop=8 setlocal nolist setlocal nobinary setlocal nonumber if exists('&relativenumber') setlocal norelativenumber endif if has('arabic') setlocal noarabic endif if has('rightleft') setlocal norightleft endif if has('folding') setlocal nofoldenable endif if has('diff') setlocal nodiff endif if has('spell') setlocal nospell endif setlocal modifiable silent 1,$d for h in hh if exists('h.cmd') call ViewDoc_SetShellToBash() let h.cmd = substitute(h.cmd, '{{winwidth}}', winwidth('.'), 'g') execute 'silent 0r ! ( ' . h.cmd . ' ) 2>/dev/null' call ViewDoc_RestoreShell() silent $d execute 'normal! ' . (exists('h.line') ? h.line : 1) . 'G' execute 'normal! ' . (exists('h.col') ? h.col : 1) . '|' if exists('h.search') call search(h.search) endif normal! zt endif let is_empty = line('$') == 1 && col('$') == 1 if !is_empty break endif endfor setlocal nomodifiable nomodified execute 'setlocal ft=' . h.ft let b:topic = h.topic if exists('h.tags') execute 'setlocal tags^=' . h.tags endif if exists('h.docft') let b:docft = h.docft endif inoremap q :call CloseBuf() nnoremap q :call CloseBuf() vnoremap q :call CloseBuf() inoremap :call Next() inoremap :call Prev() nnoremap :call Next() nnoremap :call Prev() imap imap nmap nmap if is_empty && !g:viewdoc_openempty if a:target == 'inplace' call s:Prev() else call s:CloseBuf() unlet! prev_tabpagenr endif endif if g:viewdoc_dontswitch && exists('prev_tabpagenr') if prev_tabpagenr != tabpagenr() execute 'tabnext ' . prev_tabpagenr elseif winnr('$') > 1 wincmd p else execute "normal! \" endif endif if is_empty redraw | echohl ErrorMsg | echo 'Sorry, no doc for' h.topic | echohl None endif endfunction function ViewDoc_SetShellToBash() let s:_shell=&shell let s:_shellcmdflag=&shellcmdflag let s:_shellpipe=&shellpipe let s:_shellredir=&shellredir if !has('win16') && !has('win32') && !has('win64') setlocal shell=/bin/sh setlocal shellcmdflag=-c setlocal shellpipe=2>&1\|\ tee setlocal shellredir=>%s\ 2>&1 endif endfunction function ViewDoc_RestoreShell() execute 'setlocal shell='.escape(s:_shell,'| ') execute 'setlocal shellcmdflag='.escape(s:_shellcmdflag,'| ') execute 'setlocal shellpipe='.escape(s:_shellpipe,'| ') execute 'setlocal shellredir='.escape(s:_shellredir,'| ') endfunction """ Internal " let hh = s:GetHandles('', 'perl') auto-detect syntax " let hh = s:GetHandles('query', 'perl') no auto-detect " Return: [{ " 'topic': 'query', ALWAYS " 'ft': 'perldoc', ALWAYS " 'cmd': 'cat /path/to/file', OPTIONAL " 'line': 1, OPTIONAL " 'col': 1, OPTIONAL " 'tags': '/path/to/tags', OPTIONAL " 'search': 'regex', OPTIONAL " 'docft': 'perl', OPTIONAL " },…] function s:GetHandles(topic, ft) let cword = a:topic == '' let topic = cword ? expand('') : a:topic let synid = cword ? synID(line('.'),col('.'),1) : 0 let h_type = exists('g:ViewDoc_{a:ft}') ? a:ft : 'DEFAULT' if type(g:ViewDoc_{h_type}) == type([]) if len(g:ViewDoc_{h_type}) == 0 let handlers = [ g:ViewDoc_DEFAULT ] else let handlers = g:ViewDoc_{h_type} endif else let handlers = [ g:ViewDoc_{h_type} ] endif let hh = [] for Handler in handlers if type(Handler) == type("") let name = Handler if name !~# '^g:' let name = 'g:' . name endif unlet Handler if exists('{name}') && type({name}) == type(function("tr")) let Handler = {name} else echohl ErrorMsg | echo 'No such function:' name | echohl None | sleep 2 endif endif let h = exists('Handler') ? Handler(topic, a:ft, synid, cword) : {} let h.topic = exists('h.topic') ? h.topic : topic let h.ft = exists('h.ft') ? h.ft : a:ft call add(hh, h) unlet Handler endfor return hh endfunction " Emulate doc stack a-la tag stack ( and ) function s:Next() let b:stack = exists('b:stack') ? b:stack + 1 : 1 let docft = exists('b:docft') ? b:docft : &ft if !exists('b:topic_stack') let b:topic_stack = [] endif call add(b:topic_stack, b:topic) normal! msHmt`s call ViewDoc('inplace', '', docft) endfunction function s:Prev() if exists('b:stack') && b:stack let b:stack -= 1 let b:topic = remove(b:topic_stack, -1) setlocal modifiable undo setlocal nomodifiable normal! 'tzt`s endif endfunction " call s:OpenBuf('doc') open existing '[Doc]' buffer (create if not exists) " call s:OpenBuf('new') create and open new '[DocN]' buffer function s:OpenBuf(target) let bufname = escape(s:bufname, '[]\') let [tabnr, winnr, bufnr] = s:FindBuf(bufname) if a:target == 'new' let s:bufid = s:bufid + 1 let bufname = substitute(bufname, '\(\]\?\)$', s:bufid . '\1', '') execute g:viewdoc_open . ' ' . bufname elseif tabnr == -1 execute g:viewdoc_open . ' ' . bufname else execute 'tabnext ' . tabnr execute winnr . 'wincmd w' endif if g:viewdoc_only only! endif setlocal noswapfile buflisted buftype=nofile bufhidden=hide endfunction " Close buffer with doc, and optionally move to previous tab. " Quit if closing last buffer. function s:CloseBuf() let cond = g:viewdoc_only ? 'buflisted(v:val)' : 'buflisted(v:val) && bufloaded(v:val)' if len(filter( range(1,bufnr('$')), cond )) == 1 q elseif winnr('$') > 1 || !g:viewdoc_prevtabonclose bwipeout else let tabnr = tabpagenr() bwipeout if tabnr == tabpagenr() tabprevious endif endif endfunction " let [tabnr, winnr, bufnr] = s:FindBuf(bufname) " Return: " [-1, -1, -1] if buf not exists " [-1, -1, Z] if buf not visible " [ X, Y, Z] if buf visible function s:FindBuf(bufname) let bufnr = bufnr('^' . a:bufname . '$') if bufnr == -1 return [-1, -1, -1] endif let tabnr = -1 for t in range(1, tabpagenr('$')) for nr in tabpagebuflist(t) if nr == bufnr let tabnr = t break endif endfor if tabnr != -1 break endif endfor if tabnr == -1 return [-1, -1, bufnr] endif let savetabnr = tabpagenr() execute 'tabnext ' . tabnr let winnr = bufwinnr(bufnr) execute 'tabnext ' . savetabnr return [tabnr, winnr, bufnr] endfunction plugin/viewdoc_pydoc.vim [[[1 76 " Maintainer: see in viewdoc.vim " Version: see in viewdoc.vim " Last Modified: see in viewdoc.vim " License: see in viewdoc.vim " URL: see in viewdoc.vim " Description: ViewDoc handler for pydoc if exists('g:loaded_viewdoc_pydoc') || &cp || version < 700 finish endif let g:loaded_viewdoc_pydoc = 1 """ Options if !exists('g:viewdoc_pydoc_cmd') let g:viewdoc_pydoc_cmd='pydoc' " user may want 'pydoc3.2' endif """ Interface " - command command -bar -bang -nargs=1 -complete=custom,s:CompletePydoc ViewDocPydoc \ call ViewDoc(''=='' ? 'new' : 'doc', , 'pydoc') " - abbrev if !exists('g:no_plugin_abbrev') && !exists('g:no_viewdoc_abbrev') cnoreabbrev pydoc getcmdtype()==':' && getcmdline()=='pydoc' ? 'ViewDocPydoc' : 'pydoc' cnoreabbrev pydoc! getcmdtype()==':' && getcmdline()=='pydoc!' ? 'ViewDocPydoc' : 'pydoc!' endif """ Handlers function s:ViewDoc_pydoc(topic, filetype, synid, ctx) if a:ctx let oldiskeyword = &iskeyword setlocal iskeyword+=. let topic = printf('%s %s', shellescape(a:topic,1), shellescape(expand(''),1)) let &iskeyword = oldiskeyword else let topic = shellescape(a:topic,1) endif " FIXME: remove duplicates from topic " TODO: make topic an array " TODO: implement better guessing for topic: " aaaa.bbbb.ccc|ccc " try: pydoc cccccc " if failed: try: pydoc bbbb.ccccc " if failed: try: pydoc aaaa.bbbb.ccccc " d|ddd " try: pydoc dddd " if failed: if some 'import dddd from mmmm' exists, try: pydoc mmmm.dddd " if failed: if some 'from mmmm import eeee as dddd' exists: try: pydoc mmmm.eeee 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), \ 'ft': 'pydoc', \ } endfunction " use function(s:SID().'Foo') instead of function('s:Foo') for " compatibility with Vim-7.3.x (7.3.762 at least) function s:SID() return matchstr(expand(''), '\zs\d\+_\zeSID$') endfunction let g:ViewDoc_pydoc = function(s:SID().'ViewDoc_pydoc') let g:ViewDoc_python = function(s:SID().'ViewDoc_pydoc') """ Internal " Autocomplete topics, keywords and modules. function s:CompletePydoc(ArgLead, CmdLine, CursorPos) if(!exists('s:complete_cache')) call ViewDoc_SetShellToBash() 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''') call ViewDoc_RestoreShell() endif return s:complete_cache endfunction syntax/info.vim [[[1 40 " Syntax file for output of GNU info, inspired by " http://www.vim.org/scripts/script.php?script_id=21 " " Author: pawel.wiecek@tieto.com " For version 5.x: Clear all syntax items " For version 6.x: Quit when a syntax file was already loaded if version < 600 syntax clear elseif exists("b:current_syntax") finish endif syn case match syn match infoMenuTitle /^\* Menu:/hs=s+2,he=e-1 syn match infoTitle /^[A-Z][0-9A-Za-z `',/&]\{,43}\([a-z']\|[A-Z]\{2}\)$/ syn match infoTitle /^[-=*]\{,45}$/ syn match infoString /`[^`']*'/ syn match infoLinkMenu /^\* [^:]*::/hs=s+2 syn match infoLinkDir /^\* [^:]*: ([^)]*)[^.]*\./hs=s+2,he=e-1 contains=infoDirTarget syn match infoLinkIndex /^\* [^:]*:\s*[^.]*\.[ \t\n]*(line\s\+[0-9]\+)$/hs=s+2 contains=infoIndexTarget,infoIndexLine syn region infoLinkNote start=/\*[Nn]ote/ end=/\(::\|[.,]\)/ contains=infoNoteNote syn match infoDirTarget contained /: ([^)]*)[^.]*\./hs=s+1,he=e-1 syn match infoIndexTarget contained /:\s*.\+\./hs=s+1,he=e-1 syn region infoIndexLine contained start=/(line/ end=/)$/ syn match infoNoteNote contained /\*[Nn]ote/hs=s+1 hi def link infoMenuTitle Title hi def link infoTitle Comment hi def link infoLinkMenu Directory hi def link infoLinkDir Directory hi def link infoLinkIndex Directory hi def link infoLinkNote Directory hi def link infoString String hi def link infoDirTarget Keyword hi def link infoIndexTarget Keyword hi def link infoIndexLine Identifier hi def link infoNoteNote Keyword let b:current_syntax = "info"