5

(This question is posted in vim_mac user group in Google, but I did not get a solution)

When pressing <K> on keyword, in terminal vim it will produce the man page correctly. However, in MacVim, it generates a warning:

WARNING: terminal is not fully functional 

The ANSI control sequence is then display and not correctly escaped. A screenshot can be found here.

Help needed, thanks!

1
  • Screenshot is gone. Please add it to the question. Nov 7, 2020 at 16:34

5 Answers 5

5

The ConqueTerm Vim plugin provides GUI-based instances of Vim with a fairly robust terminal emulation. It requires Vim 7.0+ (7.3+ for Windows) compiled with +python or +python3; MacVim satisfies these requirements.

Here is a function and binding that re-implements the functionality of the normal-mode K command using ConqueTerm (you can put it in your .vimrc):

:function! ConqueMan()
    let cmd = &keywordprg . ' '
    if cmd ==# 'man ' || cmd ==# 'man -s '
        if v:count > 0
            let cmd .= v:count . ' '
        else
            let cmd = 'man '
        endif
    endif
    let cmd .= expand('<cword>')
    execute 'ConqueTermSplit' cmd
:endfunction
:map K :<C-U>call ConqueMan()<CR>
:ounmap K
2
  • Looks nice! Nevertheless it looks a bit weird under MacVim with a colorful output.
    – Ivan Xiao
    Jun 1, 2011 at 21:00
  • Perfect! and has insert mode too.
    – sunkencity
    Sep 18, 2011 at 7:59
1

This can't be solved without a lot of programming because, as that thread states, MacVim creates its own "terminal" that does not conform to any terminfo entries, hence less cannot handle using it properly. You can try poking $TERM in MacVim via :set term=..., but I don't think that there's any value that would be appropriate for MacVim.

If you have some graphical man page viewer you could set it as keywordprg. See :h keywordprg for more details.

1
  • Hi, I did try setting the term, but still. It doesn't work. However setting keywordprg seems to be a reasonable workaround. After some search I cannot find a good alternative to man, though...
    – Ivan Xiao
    May 29, 2011 at 4:22
1

Try solving this by enabling the builtin man page plugin:

runtime ftplugin/man.vim
if has("gui_running")
    nnoremap K :<C-U>exe "Man" v:count "<C-R><C-W>"<CR>
endif
1
  • This intercepts all documentation calls, even those not destined for man. I have a solution that conditionalizes on just man pages in my answer.
    – Adam Katz
    May 3, 2019 at 14:37
0

If you use Linux,you can try my script,just put it in the .vimrc file Before try it,you shold check if your vim support python run this command to check: vim --version | grep +python

"my K
function! KyMANit()
python<<EOF
import os
import vim
import re
col=vim.current.window.cursor[1] #得到col 
line=vim.current.line
cmd_line='gnome-terminal -e "man '  #you may replace the gnome-terminal with another terminal emulator.However in Ubuntu 10.04,it's perfect

for m in re.finditer(r"\w+",line):
    if m.start()<=col and m.end()>=col:
        cmd_line+=m.group()+'"'
        os.system(cmd_line)
EOF
endfunction
map K :<C-U>call KyMANit()<CR>
ounmap K
0

cmcginty's answer uses Vim's :Man filetype plugin, but that's only appropriate when the K command would run man (which is keyed on the keywordprg setting). Here is a solution that only offers that functionality when K would invoke man:

function! ManVim(...)
  if (&keywordprg == "man")
    runtime ftplugin/man.vim
    setlocal keywordprg=:Man
  endif
  normal! K
endfunction

noremap K :call ManVim()<CR>

You can optionally surround this with if has("gui_running") and endif but I find this works great on the console too.

Note that this checks whether Vim would run man from within the function call in order to prevent intercepting keywordprg when it would run a different command, say after loading a python script. The next time you hit K, keywordprg will not match.

Caveat: Like the original K command, this solution gets stuck on hyphens and dots, such as for man pages like ssh-add and resolv.conf. This is because the sh filetype doesn't consider hyphens or dots to be keyword characters.

Here is a solution that temporarily redefines keyword characters to include hyphen and dot:

function! ManVim(...)
  if (&keywordprg != "man") " not invoking man, operate as per normal
    normal! K
  else
    if ! exists(":Man")  " load man.vim if it's not already present
      runtime ftplugin/man.vim
    endif

    " man pages allow dashes and dots, so we temporarily add those kwd chars
    let old_iskeyword = &iskeyword
    setlocal iskeyword+=\.,-

    if ! exists(":Man")  " fallback in case man.vim failed to load
      normal! K
    endif

    let l:man_page = expand("<cword>")
    let &l:iskeyword = old_iskeyword

    if exists(":Man")  " for whatever reason, the exe has to be last
      exe "Man" v:count l:man_page
    endif
  endif
endfunction

noremap K :call ManVim()<CR>

This is a bit more complicated than I'd like because :Man changes the current buffer and therefore needs to be run last, but the fallback for when man.vim is missing must be earlier since it has to be run while iskeyword has the extra characters.

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .