cargo
has a nice feature to generate document. But it doesn't have a feature to search it yet.
This plugin searches documents (standard libraries, libraries your crate depends on, and so on) from Vim.
- Open a document for the word under cursor
std
- Search documents with unit.vim interface
:RustDoc
command
:RustDoc {crate or module name} [{identifier name}]
For example, assume that your crate uses rand.
:RustDoc rand
opens the document for craterand
.:RustDoc rand::distributions
opens the document for modulerand::distributions
.:RustDoc rand Rng
opens the document for traitrand::Rng
.
All arguments of the command can be completed. Please enter <Tab>
to complete them.
Of course you can search standard libraries.
:RustDoc std::vec
And :RustDocFuzzy
and :RustDocModule
are also available.
Please see document for them for more detail.
- Mapping
K
Entering key K
in your Rust source opens a document most corresponding to a word under the cursor.
K
mapping is available in normal mode and visual mode. In normal mode, the word under the cursor is used.
In visual mode, the selected text is used.
- unite.vim source
:Unite rust/doc
You can select from all document candidates with unite.vim interface.
And if you want to use unite.vim for K
mapping, you can setup in your vimrc as follows.
let g:rust_doc#define_map_K = 0
augroup vimrc-rust
autocmd!
autocmd FileType rust nnoremap <buffer><silent>K :<C-u>Unite rust/doc:cursor -no-empty -immediately<CR>
autocmd FileType rust vnoremap <buffer><silent>K :Unite rust/doc:visual -no-empty -immediately<CR>
augroup END
It may takes some time to prepare candidates. If you don't want to wait and it is enough for you to search only module names,
please specify modules
to the argument of rust/doc
source as below.
:Unite rust/doc:modules
If you use some plugin manager, please follow the instruction of them. For example, you can install this plugin with neobundle.vim as below.
NeoBundle 'rhysd/rust-doc.vim'
If you use no plugin manager, copy all directories and files in autoload
, plugin
, ftplugin
and doc
directories to your ~/.vim
directory's corresponding directories.
Or you can also use Vim's standard package management. Please read :help packages
.
rust-doc.vim searches documents downloaded by rustup. If there is a toolchain installed by rustup, rust-doc.vim tries to use documentations in it.
If you want to see your own standard library documents, you must set g:rust_doc#downloaded_rust_doc_dir
.
The variable should be string type and contain the path to rust documents bundled in downloaded rust tar.
e.g.:
$ wget https://static.rust-lang.org/dist/rust-1.0.0-i686-unknown-linux-gnu.tar.gz
$ tar xf rust-1.0.0-i686-unknown-linux-gnu.tar.gz
$ mv rust-1.0.0-i686-unknown-linux-gnu/rust-doc ~/Documents/
Then set the variable as below
let g:rust_doc#downloaded_rust_doc_dir = '~/Documents/rust-docs'
g:rust_doc#vim_open_cmd
Vim command to open the path to a document. rust-doc.vim uses it to open the document if it is not empty. The command must take a url to the local file.
g:rust_doc#open_cmd
Shell command to open the path to a document. rust-doc.vim uses it to open the document if it is not empty. The command must take a url to the local file.
g:rust_doc#do_not_ask_for_module_list
If the value is 1
, rust-doc.vim never ask if it shows the list of modules/identifiers when no document is found.
The default value is 0
.
g:rust_doc#define_map_K
If the value is 1
, K
mappings described above is defined. The default value is 1
.
g:rust_doc#downloaded_rust_doc_dir
As described above, the path to directory of rust standard library documents.
This plugin is distributed under the MIT License.
Copyright (c) 2015 rhysd