nvim-global is a Neovim plugin that uses Telescope and GNU global to list symbol definitions and references.
Supports multiple tag files. Useful for finding symbols defined in other projects, for example, in libraries, kernel header files.
To use nvim-global, you need to install the GNU global package first. In Ubuntu or Debian systems, use "sudo apt-get install global".
Neovim has stopped supporting cscope. Despite there are treesitter and LSP, global is still useful in some scenarios, like developing kernel drivers.
- GNU global software package installed
- Neovim has Neovim telescope plugin installed
- Install Trouble if you want to use it as quickfix window
Install the plugin with your preferred package manager:
{ 'rargo/nvim-global' }
Use default quickfix window
require("nvim-global").setup()
Use Trouble as quickfix window, you need to install Trouble first
require("nvim-global").setup({ Trouble = true })
:GlobalUpdateTags
Update tags in current project, if tags already generated, global will update it incrementally. If tag files not exist, will call gtags to generate tag files
:GlobalAddProject <project directory>
Use it to add other projects like header files, library source. it's useful for find symbols that defined in other projects.
If tag files not exist for that project, you will be prompt if want to generate it in that <project directory>
:GlobalAddKernelHeaders
If you have already generate tags file in the kernel header directory("/usr/src/linux-headers-`uname -r`), you can use this command to add the kernel header files directly. Note you need root privilege to generate tag files for the kernel header directory
:GlobalShowProjects
It will show path information for all the projects
Global <action>
action can be empty or the followings:
- current_project_definitions
- current_project_references
- other_project_definitions
- other_project_references
- all_project_references
- all_project_definitions
- current_project_definitions_smart
- other_project_definitions_smart
If is empty, a Telescope selector window will be displayed, you will be further asked which action to be taken.
Find symbol definitions in current project, if multiple definitions are found, a quick fix window will be displayed under the current buffer.
In the telescope preview window, Only current project's definition symbols will be shown.
Find symbol references in current project, if multiple references are found, a quick fix window will be displayed under the current buffer.
In the telescope preview window, current project's all symbols will be shown.
Find symbol definitions in other project which add via GlobalAddProject
, if multiple definitions are found, a quick fix window will be displayed under the current buffer.
In the telescope preview window, Only other project's definition symbols will be shown.
Find symbol references in other project which add via GlobalAddProject
, if multiple references are found, a quick fix window will be displayed under the current buffer.
In the telescope preview window, other project's all symbols will be shown.
Find symbol definitions in all projects(current project and other project which add via GlobalAddProject
), if multiple definitions are found, a quick fix window will be displayed under the current buffer.
In the telescope preview window, all projects definition symbols will be shown.
Find symbol references in all projects(current project and other project which add via GlobalAddProject
), if multiple references are found, a quick fix window will be displayed under the current buffer.
In the telescope preview window, all projects all symbols will be shown.
In the telescope preview window, current project's all symbols will be shown,
This finds definitions in the follow step until one of them successfully find symbols
- find symbol definitions in current projects
- find symbol definitions in other projects
- find symbol references in other projects
In the telescope preview window, other project's all symbols will be shown,
This finds definitions in the follow step until one of them successfully find symbols
- find symbol definitions in other projects
- find symbol references in other projects
:GlobalFindCursorWordDefinitionCurrentProject
:GlobalFindCursorWordReferenceCurrentProject
:GlobalFindCursorWordDefinitionAllProject
:GlobalFindCursorWordReferenceAllProject
Default has no keymappings, you can map commands to some key.
map key "F11" and "Ctrl-F11"
vim.api.nvim_set_keymap('n', '<F11>', '<cmd>Global current_project_definitions_smart<CR>', {noremap = true, silent = true})
vim.api.nvim_set_keymap('n', '<C-F11>', '<cmd>Global other_project_definitions_smart<CR>', {noremap = true, silent = true})
-- for some laptop computer C-F8 keymap
vim.api.nvim_set_keymap('n', '<C-F35>', '<cmd>Global other_project_definitions_smart<CR>', {noremap = true, silent = true})
map key "\d", "\D", "\r", "\R"
vim.api.nvim_set_keymap('n', '\\d', '<cmd>GlobalFindCursorWordDefinitionCurrentProject<CR>', {noremap = true, silent = true})
vim.api.nvim_set_keymap('n', '\\r', '<cmd>GlobalFindCursorWordReferenceCurrentProject<CR>', {noremap = true, silent = true})
vim.api.nvim_set_keymap('n', '\\D', '<cmd>GlobalFindCursorWordDefinitionAllProject<CR>', {noremap = true, silent = true})
vim.api.nvim_set_keymap('n', '\\R', '<cmd>GlobalFindCursorWordReferenceAllProject<CR>', {noremap = true, silent = true})