查找 c++ vim 内的文档

发布于 2024-08-22 06:09:40 字数 249 浏览 7 评论 0原文

我使用 vim 编写 c++ 代码。

很多时候,我发现自己浪费时间(和中断流程)查找琐碎的事情,例如:

std::string.substring 是否需要(开始,长度)或(开始,结束)。

这通常会导致浏览器打开;等待;在谷歌上搜索;第一个链接没用,尝试第二个链接;好的,完成。

其他人如何在 vim 中做到这一点?有没有一个很好的 *.tgz 我可以下载标准函数文档并以某种方式在 vim 中引用它们?

谢谢!

I code c++, using vim.

Often times, I find myself wasting time (and brekaing flow) looking up trivial things like:

is std::string.substring does it take (start, length) or (start, end).

This often results in open browser; wait; search on google; first link useless, try second link; okay, done.

How do others do this in vim? Is there a nice *.tgz I can download of standard function documentation and somehow reference them inside of vim?

Thanks!

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(6

白衬杉格子梦 2024-08-29 06:09:40

您还可以使用 cppman 它提供:

适用于 Linux/MacOS 的 C++ 98/11/14 手册页

在此处输入图像描述

然后您可以使用它代替 man 在 Vim 中输入 ShiftK 时(参见 @alesplin 的回答):

autocmd FileType cpp set keywordprg=cppman

这会打开一个类似 man 的漂亮页面您可以使用 Vim 寻呼机浏览 STL 文档。

为了更好地与 Vim 集成,它可以与 vim-man 或任何其他类似的工具一起使用插件。

就我个人而言,我通过为 C++ 文件重新映射 ShiftK 绕过了 keywordprg,然后打开 tmux split:

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

tmux

You can also use cppman which provides:

C++ 98/11/14 manual pages for Linux/MacOS

enter image description here

Then you could use it in place of man when typing ShiftK in Vim (cf. @alesplin's answer):

autocmd FileType cpp set keywordprg=cppman

That would open a nice man-like page with the STL documentation that you can navigate with the Vim pager.

For a better integration with Vim, it could probably be used with vim-man or any other similar plugin.

Personally, I bypassed keywordprg by remapping ShiftK for C++ files, and I open a tmux split:

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

tmux

⊕婉儿 2024-08-29 06:09:40

我不使用 C++ 编程,但如果有相关函数的手册页,您可以通过将光标放在函数名称上并点击 ShiftK 来访问它们。这仅适用于安装了手册页的功能,因此您的情况可能会有所不同。

I don't program in C++, but if there are man pages for the functions in question, you can access them by placing the cursor over the function name and hitting ShiftK. This only works for functions that have a man page installed, so your mileage may vary.

○闲身 2024-08-29 06:09:40

推荐zeal,它是一个离线文档浏览器。使用 zealvim,您只需使用 \z 即可获取定义基于文件类型的当前单词。

Recommend zeal, it's an offline documentation browser. With zealvim, you can just use \z to get the definition of current word base on filetype.

失眠症患者 2024-08-29 06:09:40

我知道这是一个老问题,但我一直在寻找同样的东西,但没有一个答案对我有帮助。如果其他人提出这个问题,他们可能会发现这很有用。

你应该使用 CRefVim 插件。这样您就可以完全访问 c 参考手册。它适用于 C,而不是 C++,但仍然非常方便。

用法:


There are several ways to specify a word CRefVim should search for in order 
to view help: 

cr 正常模式:获取光标下单词的帮助 记忆辅助cr:(c)-(r)参考 cr 视觉模式:获取有关视觉选择文本的帮助 记忆辅助cr:(c)-(r)参考 cw:提示 CRefVim 应搜索的单词 记忆辅助CW:(c)-参考(w)帽子 cc:跳转到 C 参考手册的目录 内存辅助 cc: (c)-reference (c)ontents

注意:默认为 \,例如按 \cr 调用 C-reference

注意:搜索运算符 (++、--、%、.. .) 是为了视觉上 选择它并按 cr。

要获得帮助,请执行以下操作:help crefvimdoc 要显示 C 参考手册,请执行 :help crefvim

您也可以使用 :help 。要搜索函数的帮助,请像这样使用

:help crv-FUNCTION_NAME

:h crv-strlen,您将找到 strlen() 函数的帮助。 :h crv-operator 将帮助您找到有关 C 运算符的部分。

I know it's an old question, but I was searching for the same thing and none of the answer was helpful for me. If anyone else come to this question, they might find this useful.

You should use CRefVim Plugin. With this you will have full access to c reference manual. It's for C, not for C++, but still it's very handy.

The usage:


There are several ways to specify a word CRefVim should search for in order 
to view help: 

cr normal mode: get help for word under cursor Memory aid cr: (c)-(r)eference cr visual mode: get help for visually selected text Memory aid cr: (c)-(r)eference cw: prompt for word CRefVim should search for Memory aid cw: (c)-reference (w)hat cc: jump to table of contents of the C-reference manual Memory aid cc: (c)-reference (c)ontents

Note: by default is \, e.g. press \cr to invoke C-reference

Note: The best way to search for an operator (++, --, %, ...) is to visually select it and press cr.

To get help do :help crefvimdoc To show the C-reference manual do :help crefvim

You can use :help too. To search help for a function use it like this

:help crv-FUNCTION_NAME

With :h crv-strlen, you will find help for strlen() function. :h crv-operator will help you to find the section about C operators.

我只土不豪 2024-08-29 06:09:40

这并不是一个真正的答案,因为它不是“在 vim 内部”...但是你为什么不删除“打开浏览器,搜索 Google”部分呢?只需将您的浏览器指向一个好的 API 文档并保持打开状态即可。 http://www.dinkumware.com/manuals/default.aspx 是我的最爱(也可以下载供离线参考),http://www.cplusplus.com/reference/< /a> 也不错。切换一下窗口,点击两三下,你就会得到答案;我怀疑“内部 vim”解决方案对您的工作流程的干扰会小得多。

话虽如此,对于那些在纯文本界面上工作的人来说,在 vim 中拥有一个解决方案会很好,所以我期待其他答案。 ;-)

Not really an answer as it is not "inside vim"... but why don't you cut the "open browser, search Google" part? Just point your browser at a good API documentation, and keep it open. http://www.dinkumware.com/manuals/default.aspx is my favourite (which can be downloaded for offline reference, too), http://www.cplusplus.com/reference/ is not bad either. A window switch and two or three clicks later you have your answer; I doubt an "inside vim" solution could be much less disruptive to your workflow.

That being said, having a solution inside vim would be nice for those who are working on a text-only interface, so I am looking forward to the other answers. ;-)

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文