Skip to content

a Neovim plugin that use Telescope and GNU global to find symbol definitions and references.

Notifications You must be signed in to change notification settings

rargo/nvim-global

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

63 Commits
 
 
 
 

Repository files navigation

✨ Features

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.

⚡️ Requirements

📦 Installation

Install the plugin with your preferred package manager:

{ 'rargo/nvim-global' }

Setup

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 })

💻 Commands

Update tag files in current project

: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

Add other project

: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>

Add kernel headers

: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

Show all projects

:GlobalShowProjects

It will show path information for all the projects

List symbols

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.

current_project_definitions

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.

current_project_references

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.

other_project_definitions

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.

other_project_references

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.

all_project_definitions

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.

all_project_references

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.

current_project_definitions_smart

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

other_project_definitions_smart

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

find cursor word definition in current project

:GlobalFindCursorWordDefinitionCurrentProject

find cursor word references in current project

:GlobalFindCursorWordReferenceCurrentProject

find cursor word definition in all projects

:GlobalFindCursorWordDefinitionAllProject

find cursor word references in all projects

:GlobalFindCursorWordReferenceAllProject

🛠️ Keymaping

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})

About

a Neovim plugin that use Telescope and GNU global to find symbol definitions and references.

Resources

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published

Languages