Cargo is used by run-ctags
to list all files on which your Rust project depends. Once all dependent paths are discovered, the results are piped to [universal-ctags] to build a tags file.
This is intended for use with Vim or Emacs in combination with [universal-ctags].
This crate depends on univeral-ctags. Please follow the installation instructions for [universal-ctags].
After [universal-ctags] has been installed, install run-ctags
.
cargo install run-ctags
Once [universal-ctags] is installed, use the following command to enumerate all root directories and then pipe the results to ctags. From there, ctags will recursively search through all files and folders, starting from the root directory, and create a file named ctags in your project's folder.
From the root directory of your Rust project, run the following command:
sh
run-ctags | ctags -R -L -
This command pipes all of your project dependencies to ctags which then in turn builds an index for your project saved in a file named tags
. If you now open vim in your project's root directory, you can use ctags to jump in and out of different definitions.
Here are a few helpful commands to run from within vim after the tags file has been created:
Ctrl+] - go to definition
Ctrl+T - Jump back from the definition.
Ctrl+W Ctrl+] - Open the definition in a horizontal split
Note, vim can only find the tags file if you start vim in the project root. However, the following command can be added to .vimrc
which allows vim to open the tags file from any subdirectory:
set tags=./tags;/