Advanced gf
command for neovim.
smartjump.nvim
will lookup the filename under the cursor in vim.o.path
.
There are several main.go
file in the project, smartjump will find it in all folders defined by path
variable, and show them with line number awareness.
Using packer:
use {"moevis/smartjump.nvim", requires = "nvim-telescope/telescope.nvim"}
Default setup (optional):
require("smartjump").setup({
-- telescope config
telescope = {
prompt_title = "Go To File",
},
-- or require("telescope.themes").get_dropdown()/.get_ivy()/.get_cursor()
theme = nil,
})
Set keymap (by lua):
-- maping to 'gl'
vim.keymap.set("n", "gl", ":GoToFile<cr>", nil)
-- or you can replace default 'gf' command
vim.keymap.set("n", "gf", ":GoToFile<cr>", nil)
Key mapping (Telescope default behaviors):
<Enter>
: open the file in current buffer.<C-t>
: open the file in new tab.<C-x>
: open file in horizontal window.<C-v>
: open file in vertical window.
You can define a custom vim.o.path
for your project by adding a local .vimrc
in your project root.
set path=/usr/include,/usr/local/include
And remember add these lines in your init.vim:
set exrc " equal to vim.opt.exrc = true
set secure " equal to vim.opt.secure = true