aitjcize / cppman

C++ 98/11/14 manual pages for Linux/MacOS
GNU General Public License v3.0
1.27k stars 79 forks source link

vim with tmux question #59

Closed CQPosts closed 5 years ago

CQPosts commented 8 years ago

The following suggestion from http://stackoverflow.com/a/30373736/5099723 doesn't do anything in console vim:

command! -nargs=+ Cppman silent! call system("tmux split-window cppman " . expand(<q-args>)) autocmd FileType cpp nnoremap <silent><buffer> K <Esc>:Cppman <cword><CR>

cppman and tmux are installed and working. keywordprg=cppman works but would be nice to split the window. Cheers

jep-dev commented 6 years ago

If you're using Vim already, why not use Vim as your Cppman pager and make the split inside Vim, or make Cppman add its pages to your man pages? Anyway, this is what I've got working so far:

au FileType txt nmap K /[ [\]{}<>]\\|^/s-1<CR>v?[^ ^[^\]^{^}^<^>]*\\|$?<CR>y:call system("tmux splitw cppman " . getreg(""))<CR>

This generates some warnings from python about an unknown terminal type 'tmux' (it decides on ANSI) but you can fix that by setting your default-terminal to xterm-256color/screen-256color instead of Tmux. Someone who knows more about Vim's search capabilities could do a far better job - I can see I'm both repeating myself and missing a lot of edge cases. Let me know if that works for you in any case.

Tmux built from Github master; Vim 7.4 with Python3, terminal Zsh 5.1.1 / shell xterm-256color

jep-dev commented 6 years ago

For practical purposes I would just recommend updating the mandb (cppman -m true), adding runtime ftplugin/man.vim to your .vimrc, and yanking std::... to use exec "Man " . getreg("") in your key binding. If you can figure out a better regex for making your selection, you can skip the yank and add it to your key binding - unfortunately Vim sees '::' as a separate word, which is why regular bindings like standard K won't work without a selection, in addition to suspending Vim instead of splitting. Anyway, the Vim Man command automatically creates a split, which is an improvement over the current behavior of the Superman plugin (https://github.com/jez/vim-superman/issues/4).

Relevant - http://vim.wikia.com/wiki/Using_vim_as_a_man-page_viewer_under_Unix - Vim can be your default pager from external invocations. I have adapted it to the following:

set filetype=man nomod
r! man -P cat <your-word-here>

Try :vert new | :set ft=man nomod | :r! man -P cat std::string for example.

As an alternative to cppman -m true, you may be able to gunzip and preprocess the man pages - I would start with unroff - and open the result in a split/buffer/tab for the most control over your layout. I read a bunch of pages about nroff/troff/groff and didn't figure out how man and the pager communicate - you may have better luck, but I just ended up with syntax highlighting for troff syntax instead of by troff.

One final note - if you still want to use a Tmux split, I would recommend adding a Tmux utility to manage the layout and man invocation instead of hard-coding it into your Vim config.

Edit -- add buftype=nofile to the set command to make the new view a scratch buffer, so you can close it without :q!, etc. (commands which have unintended consequences for things like hidden buffers).

SGSSGene commented 5 years ago

@CQPosts does this issue still exists? I tried it on vim v8.1 and tmux v2.8 and it works as expected. To get a window split you with the command above, you must have a .cpp open. Your cursor must be over something that can be found with cppman (e.g.: vector) and you must hit 'K' (Shift+k). You also have to be in "normal mode" of vim. (not insert mode).

SGSSGene commented 5 years ago

Please reopen if problem still exists.