├── README.md
├── example.png
└── ftplugin
├── c.vim
└── cpp.vim
/README.md:
--------------------------------------------------------------------------------
1 | # vim-cppman
2 |
3 | A plugin for using [*cppman*](https://github.com/aitjcize/cppman) from within
4 | Vim. *cppman* is used to lookup "C++ 98/11/14 manual pages for Linux/MacOS"
5 | through either [cplusplus.com](https://cplusplus.com) or
6 | [cppreference.com](https://cppreference.com).
7 |
8 |
9 |
10 | Originally *cppman* uses Vim to page and syntax highlight the man page, but it
11 | is not set up to be used in buffer in an existing VIM instance. That is what
12 | this small plugin does.
13 |
14 | This is heavily based on the existing
15 | [cppman.vim](https://github.com/aitjcize/cppman/blob/master/cppman/lib/cppman.vim)
16 | which is used for the Vim pager.
17 |
18 | ## Usage
19 |
20 | The `keywordprg` and `iskeyword`settings are automatically set for `C++` and `C` files. Otherwise use the same keybindings as in *cppman*:
21 |
22 | Move the cursor to the keyword and hit `K` to lookup the keyword in a new buffer.
23 |
24 | You can also use e.g. `:Cppman iostream` to lookup a keyword.
25 |
26 |
27 | ## Installation
28 |
29 | 1.) Install [cppman](https://github.com/aitjcize/cppman)
30 |
31 | 2.) Install this plugin using your favourite plugin manager.
32 |
33 |
--------------------------------------------------------------------------------
/example.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/gauteh/vim-cppman/de1318252b68fba9b8249254475b6e050d160b73/example.png
--------------------------------------------------------------------------------
/ftplugin/c.vim:
--------------------------------------------------------------------------------
1 | cpp.vim
--------------------------------------------------------------------------------
/ftplugin/cpp.vim:
--------------------------------------------------------------------------------
1 | " This is essentially an adapted version of the cppman.vim script that is
2 | " included with cppman. Authored by Wei-Ning Huang (AZ)
3 | " and others.
4 | "
5 | "
6 | " This program is free software; you can redistribute it and/or modify
7 | " it under the terms of the GNU General Public License as published by
8 | " the Free Software Foundation; either version 3 of the License, or
9 | " (at your option) any later version.
10 | "
11 | " This program is distributed in the hope that it will be useful,
12 | " but WITHOUT ANY WARRANTY; without even the implied warranty of
13 | " MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
14 | " GNU General Public License for more details.
15 | "
16 | " You should have received a copy of the GNU General Public License
17 | " along with this program; if not, write to the Free Software Foundation,
18 | " Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.
19 |
20 |
21 | function! BackToPrevPage()
22 | if len(g:stack) > 0
23 | let context = g:stack[-1]
24 | call remove(g:stack, -1)
25 | let g:page_name = context[0]
26 | call s:reload()
27 | call setpos('.', context[1])
28 | end
29 | endfunction
30 |
31 | function! s:reload()
32 | setl noro
33 | setl ma
34 | echo "Loading..."
35 | exec "%d"
36 | exec "0r! cppman --force-columns " . (winwidth(0) - 2) . " '" . g:page_name . "'"
37 | setl ro
38 | setl noma
39 | setl nomod
40 | endfunction
41 |
42 | function! s:Rerender()
43 | if winwidth(0) != s:old_col
44 | let s:old_col = winwidth(0)
45 | let save_cursor = getpos(".")
46 | call s:reload()
47 | call setpos('.', save_cursor)
48 | end
49 | endfunction
50 |
51 | function! LoadNewPage()
52 | " Save current page to stack
53 | call add(g:stack, [g:page_name, getpos(".")])
54 | let g:page_name = expand("")
55 | setl noro
56 | setl ma
57 | call s:reload()
58 | normal! gg
59 | setl ro
60 | setl noma
61 | setl nomod
62 | endfunction
63 |
64 | function! s:Cppman(page)
65 | vertical bo new
66 | setlocal buftype=nofile
67 | setlocal bufhidden=delete
68 | setlocal noswapfile
69 |
70 | let g:page_name = a:page
71 |
72 | setl nonu
73 | setl nornu
74 | setl noma
75 | noremap q :q!
76 |
77 | if version < 600
78 | syntax clear
79 | elseif exists("b:current_syntax")
80 | finish
81 | endif
82 |
83 | syntax on
84 | syntax case ignore
85 | syntax match manReference "[a-z_:+-\*][a-z_:+-~!\*<>]\+([1-9][a-z]\=)"
86 | syntax match manTitle "^\w.\+([0-9]\+[a-z]\=).*"
87 | syntax match manSectionHeading "^[a-z][a-z_ \-:]*[a-z]$"
88 | syntax match manSubHeading "^\s\{3\}[a-z][a-z ]*[a-z]$"
89 | syntax match manOptionDesc "^\s*[+-][a-z0-9]\S*"
90 | syntax match manLongOptionDesc "^\s*--[a-z0-9-]\S*"
91 |
92 | syntax include @cppCode runtime! syntax/cpp.vim
93 | syntax match manCFuncDefinition display "\<\h\w*\>\s*("me=e-1 contained
94 |
95 | syntax region manSynopsis start="^SYNOPSIS"hs=s+8 end="^\u\+\s*$"me=e-12 keepend contains=manSectionHeading,@cppCode,manCFuncDefinition
96 | syntax region manSynopsis start="^EXAMPLE"hs=s+7 end="^ [^ ]"he=s-1 keepend contains=manSectionHeading,@cppCode,manCFuncDefinition
97 |
98 | " Define the default highlighting.
99 | " For version 5.7 and earlier: only when not done already
100 | " For version 5.8 and later: only when an item doesn't have highlighting yet
101 | if version >= 508 || !exists("did_man_syn_inits")
102 | if version < 508
103 | let did_man_syn_inits = 1
104 | command -nargs=+ HiLink hi link
105 | else
106 | command -nargs=+ HiLink hi def link
107 | endif
108 |
109 | HiLink manTitle Title
110 | HiLink manSectionHeading Statement
111 | HiLink manOptionDesc Constant
112 | HiLink manLongOptionDesc Constant
113 | HiLink manReference PreProc
114 | HiLink manSubHeading Function
115 | HiLink manCFuncDefinition Function
116 |
117 | delcommand HiLink
118 | endif
119 |
120 | """ Vim Viewer
121 | setl mouse=a
122 | setl colorcolumn=0
123 |
124 |
125 | let g:stack = []
126 |
127 | noremap K :call LoadNewPage()
128 | map K
129 | map K
130 | map <2-LeftMouse> K
131 |
132 | noremap :call BackToPrevPage()
133 | map
134 |
135 | let b:current_syntax = "man"
136 |
137 | let s:old_col = 0
138 | autocmd VimResized * call s:Rerender()
139 |
140 | " Open page
141 | call s:reload()
142 | exec "0"
143 | endfunction
144 |
145 | command! -nargs=+ Cppman call s:Cppman(expand())
146 | setl keywordprg=:Cppman
147 |
148 |
--------------------------------------------------------------------------------