[关闭]
@woshichuanqilz 2015-11-15T03:13:40.000000Z 字数 1149 阅读 1150

Add Python help in Vim

Vim


  • Two Keys here
  • 1. Read the output from the cmd line use the statement "r !echo hello" you will get the output in the current window
  • 2. Redirect the output to the buffer window.
    execute "split" fnamescape(bufname)
    setlocal buftype=nofile
    setlocal nobuflisted
  1. " Press leader r and the word under the curor will be search in the python help
  2. nnoremap <leader>r :<C-u>execute "!start cmd /k python C:\\Python27\\Lib\\pydoc.py " . expand("<cword>")<CR>
  3. "Enter :Pyhelp "SearchWord" in the command line you will get the help about the word in a new buffer.
  4. command! -nargs=1 -bar Pyhelp :call ShowPydoc(<f-args>)
  5. function! ShowPydoc(what)
  6. let bufname = a:what . ".pydoc"
  7. " check if the buffer exists already
  8. if bufexists(bufname)
  9. let winnr = bufwinnr(bufname)
  10. if winnr != -1
  11. " if the buffer is already displayed, switch to that window
  12. execute winnr "wincmd w"
  13. else
  14. " otherwise, open the buffer in a split
  15. execute "sbuffer" bufname
  16. endif
  17. else
  18. " create a new buffer, set the nofile buftype and don't display it in the
  19. " buffer list
  20. execute "split" fnameescape(bufname)
  21. setlocal buftype=nofile
  22. setlocal nobuflisted
  23. " read the output from pydoc
  24. let l:cmd = "r !python C:\\Python27\\Lib\\pydoc.py " . a:what
  25. " execute "r !" . shellescape(s:pydoc_path, 1) . " " . shellescape(a:what, 1)
  26. execute cmd
  27. endif
  28. " go to the first line of the document
  29. 1
  30. endfunction
添加新批注
在作者公开此批注前,只有你和作者可见。
回复批注