For old school code navigation :)
Only supports neovim. Heavily inspired by emacs' xcscope.el.
🌟 Now with cscope
support for Neovim 0.9+
- Tries to mimic vim's builtin cscope functionality.
- Provides user command,
:Cscope
which acts same as good old:cscope
. - No need to add cscope database (
:cscope add <file>
), it is automaticaly picked from current directory ordb_file
option. - Only want to use Cscope? No worries, keymaps can be disabled using
disable_maps
option.
- Opens results in quickfix window.
- Has which-key.nvim hints baked in.
- See this for
vim-gutentags
.
Install the plugin with your preferred package manager.
-- Lua
use 'dhananjaylatkar/cscope_maps.nvim' -- cscope keymaps
use 'folke/which-key.nvim' -- optional
-- load cscope maps
-- pass empty table to setup({}) for default options
require('cscope_maps').setup({
disable_maps = false, -- true disables my keymaps, only :Cscope will be loaded
cscope = {
db_file = "./cscope.out", -- location of cscope db file
},
})
use({
"dhananjaylatkar/cscope_maps.nvim",
after = "which-key.nvim",
config = function()
require("cscope_maps").setup({})
end,
})
" Vim Script
Plug 'dhananjaylatkar/cscope_maps.nvim' " cscope keymaps
Plug 'folke/which-key.nvim' " optional
lua << EOF
require("cscope_maps").setup({})
EOF
Cscope provided by this plugin is not exactly same as built-in vim cscope, vim-gutentags fails to load.
I have created a patch to support this plugin and my fork can be used until it's merged in upstream.
use({
"dhananjaylatkar/vim-gutentags",
after = "cscope_maps.nvim",
config = function()
vim.g.gutentags_modules = {"cscope_maps"} -- This is required. Other config is optional
vim.g.gutentags_cscope_build_inverted_index_maps = 1
vim.g.gutentags_cache_dir = vim.fn.expand("~/code/.gutentags")
vim.g.gutentags_file_list_command = "fd -e c -e h"
-- vim.g.gutentags_trace = 1
end,
})
Keymaps | Description |
---|---|
<leader>cs |
find all references to the token under cursor |
<leader>cg |
find global definition(s) of the token under cursor |
<leader>cc |
find all calls to the function name under cursor |
<leader>ct |
find all instances of the text under cursor |
<leader>ce |
egrep search for the word under cursor |
<leader>cf |
open the filename under cursor |
<leader>ci |
find files that include the filename under cursor |
<leader>cd |
find functions that function under cursor calls |
<leader>ca |
find places where this symbol is assigned a value |
Disable default keymaps by setting disable_maps = true
.
There are 2 ways to add keymaps for Cscope
.
cscope_prompt(operation, default_symbol)
is exposed to user. This function provides prompt which asks for input (see screenshots below) before running :Cscope
command.
e.g. Following snippet maps C-c C-g to find global def of symbol under cursor
vim.api.nvim_set_keymap(
"n",
"<C-c><C-g>",
[[<cmd>lua require('cscope_maps').cscope_prompt('g', vim.fn.expand("<cword>"))<cr>]],
{ noremap = true, silent = true }
)
Use vim.api.nvim_set_keymap()
to set keymap for cscope.
e.g. Following snippet maps C-c C-g to find global def of symbol under cursor
vim.api.nvim_set_keymap(
"n",
"<C-c><C-g>",
'<cmd>Cscope find g vim.fn.expand("<cword>"))<cr>',
{ noremap = true, silent = true }
)