Everduin94 / nvim-quick-switcher

Quickly navigate to other files/extensions based on the current file name or jump to nodes in a file via treesitter. Written in Lua.
The Unlicense
50 stars 5 forks source link

Installation instructions for LazyVim usage #6

Closed DanielCardonaRojas closed 1 year ago

DanielCardonaRojas commented 1 year ago

This plugin looks great I think its a very cool idea. Unfortunately I was trying to integrate this with LazyVim and got some setup issues that I'm not quite sure how to fix. Would be great to get some documentation for lazy package manager.

Everduin94 commented 1 year ago

@DanielCardonaRojas Hey thanks I appreciate it! I personally use packer and have not used lazy. When I get the chance I'll give this a look . Lazy seems to be taking over as the go-to plugin manager AFAIK :)

DanielCardonaRojas commented 1 year ago

Actually I think this works fine with:

return {
  "Everduin94/nvim-quick-switcher",
}

I think I was trying to apply the opts here which I don't think makes sense. I think this can be closed.

Everduin94 commented 1 year ago

Hey sorry I took forever to get back to you on this! Glad to hear its working, feel free to reach out if you have any other comments or questions.

TheDevelolper commented 12 months ago

Hey, I've just moved from vscode to astrovim and I'm still learning how to use lazy.

It would be really helpful if you could give a little more context. Which file that return goes into?

I tried adding the string to my config init.lua but I just get errors when I open nvim.

if vim.loader and vim.fn.has "nvim-0.9.1" == 1 then vim.loader.enable() end

for _, source in ipairs {
  "astronvim.bootstrap",
  "astronvim.options",
  "astronvim.lazy",
  "astronvim.autocmds",
  "astronvim.mappings",
    <--- I tried adding it here but get errors. 
} do
  local status_ok, fault = pcall(require, source)
  if not status_ok then vim.api.nvim_err_writeln("Failed to load " .. source .. "\n\n" .. fault) end
end

if astronvim.default_colorscheme then
  if not pcall(vim.cmd.colorscheme, astronvim.default_colorscheme) then
    require("astronvim.utils").notify(
      ("Error setting up colorscheme: `%s`"):format(astronvim.default_colorscheme),
      vim.log.levels.ERROR
    )
  end
end
-- Enable showing hidden files in AstroVim Explorer
vim.g.astro_galaxy_browsing_explore_hidden = 1

require("astronvim.utils").conditional_func(astronvim.user_opts("polish", nil, false), true)
TheDevelolper commented 12 months ago

Okay so I think I installed it now but I have no idea where to put the options. I mean out of the box it seems to do nothing? I guess I need to set up the options specified in the readme but as a beginner there's no context. I don't know where to put those settings.

So I looked in my plugin status and I can see it's not loaded:

image

but it is there. I am currently in an html file I'm not sure how to get the plugin loaded.

Everduin94 commented 12 months ago

@TheDevelolper - Hey there, I have not used lazy before but I'll try to update the docs when I get the chance.

Quick switcher is slightly unique in the sense that it just exposes lua functions. i.e. it doesn't have a setup function and you just bind the functions to hot-keys.

As an example, you could run something like this in command mode require('nvim-quick-switcher').find('.service.ts')

So for a setup/keymap example, I have a file called nvim-quick-switcher.lua that looks something like this

local keymap = vim.api.nvim_set_keymap
local opts = { noremap = true, silent = true }

-- Tests
keymap("n", "<leader>ot", "<cmd>:lua require('nvim-quick-switcher').find('.+test|.+spec', { regex = true, prefix='full' })<CR>", opts)

-- Angular
keymap("n", "<leader>oy", "<cmd>:lua require('nvim-quick-switcher').find('.service.ts')<CR>", opts)
keymap("n", "<leader>ou", "<cmd>:lua require('nvim-quick-switcher').find('.component.ts')<CR>", opts)
keymap("n", "<leader>oo", "<cmd>:lua require('nvim-quick-switcher').find('.component.html')<CR>", opts)
keymap("n", "<leader>op", "<cmd>:lua require('nvim-quick-switcher').find('.module.ts')<CR>", opts)

-- SvelteKit
keymap("n", "<leader>oso", "<cmd>:lua require('nvim-quick-switcher').find('*page.svelte', { maxdepth = 1, ignore_prefix = true })<CR>", opts)
keymap("n", "<leader>osi", "<cmd>:lua require('nvim-quick-switcher').find('*layout.svelte', { maxdepth = 1, ignore_prefix = true })<CR>", opts)

So if lazy has somewhere you can run arbitrary code or call keymap that might be the place to do it.

Daerniss commented 8 months ago

What worked for me: Create a file in plugins folder with any name (quick-switcher.lua for example) and set keys you want

return {
  "Everduin94/nvim-quick-switcher",
  keys = {
    {
      "<leader>oo",
      "<cmd>:lua require('nvim-quick-switcher').find('.component.html')<CR>",
      desc = "Open template file",
    },
    {
      "<leader>ou",
      "<cmd>:lua require('nvim-quick-switcher').find('.component.ts')<CR>",
      desc = "Open Component File",
    },
    {
      "<leader>op",
      "<cmd>:lua require('nvim-quick-switcher').find('.module.ts')<CR>",
      desc = "Open Module File",
    },
    {
      "<leader>oy",
      "<cmd>:lua require('nvim-quick-switcher').find('.service.ts')<CR>",
      desc = "Open Service File",
    },
  },
}