Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Need Feedback for using starter template config for v2.5( Freedom from custom config ) #2706

Closed
siduck opened this issue Mar 5, 2024 · 25 comments

Comments

@siduck
Copy link
Member

siduck commented Mar 5, 2024

Hi guys, Configs like lazyvim, astrovim4 have this starter config in which you import their main repos itself as plugins and use it as your config. https://github.com/LazyVim/starter

I like the idea, with this change you will be able to track your configs 100% in git and actually have a config that adheres to standard nvim config structure rather than abstracted custom config stuff.

Also Currently dirs like after, syntax, ftplugin etc which are outside of custom dir git-ignored. So you can only track custom config which is bad for users who use those dirs which are outside of custom dir i.e /after ftplugin etc

So what do you think of having a starter config, in which you can just import modules from nvchad repo and use nvchad repo as plugin so you can just import its mappings/options/plugins etc

This change removes the custom config abstraction too btw. Take a look at how simple is this :

vim.g.base46_cache = vim.fn.stdpath "data" .. "/nvchad/base46/"
vim.g.mapleader = " "

-- bootstrap lazy and all plugins
local lazypath = vim.fn.stdpath "data" .. "/lazy/lazy.nvim"

if not vim.loop.fs_stat(lazypath) then
  local repo = "https://github.com/folke/lazy.nvim.git"
  vim.fn.system { "git", "clone", "--filter=blob:none", repo, "--branch=stable", lazypath }
end

vim.opt.rtp:prepend(lazypath)

local lazy_config = require "configs.lazy"

-- load plugins
require("lazy").setup({
  {
    "NvChad/NvChad",
    lazy = false,
    branch = "starter",
    import = "nvchad.plugins",
    config = function()
      require "options"
    end,
  },

  { import = "plugins" }, -- your plugins!
}, lazy_config)

-- load theme
dofile(vim.g.base46_cache .. "defaults")
dofile(vim.g.base46_cache .. "statusline")

require "nvchad.autocmds"
require "nvchad.mappings"

Check these repos for actual configs.

https://github.com/NvChad/NvChad/tree/test

https://github.com/siduck/dotfiles/tree/master/nv3 ( My custom config migrated using starter template )

Pros

  • Removes abstraction of custom config, the chadrc.lua you see is a config for both ui/base46 repo actually!
  • Clean structure of the config, you have total control over it, can add dirs like after ftplugin syntax etc
  • Can 100% git-track the files
  • No need to learn custom dir syntax

Cons

  • Its a breaking change, but dont worry, when v3.0 releases, v2.0 will still be available so you could take your own time in migrating.
  • You have to open up your browser / local path to see src code of default nvchad config, But I can make a command for this which would open a new tab in nvim and use tcd to cd in the nvim src code.

I think a script could be made to automate the migration! 🤔 https://gist.github.com/siduck/048bed2e7570569e6b327b35d1715404

simplescreenrecorder-2024-03-07_19.14.05.mp4

If you like this, then give 👍 or 👎

@siduck siduck pinned this issue Mar 5, 2024
@ARBoyGo
Copy link

ARBoyGo commented Mar 5, 2024

I'm excited to try it. The only challenging part seems to be the updating process, but if you can create a custom command for it, it would be amazing. Thank you, Sid for your amazing work. 😊

@Alexis12119
Copy link
Contributor

I'm excited to try it. The only challenging part seems to be the updating process, but if you can create a custom command for it, it would be amazing. Thank you, Sid for your amazing work. 😊

That's hard and maybe impossible for now.

@DockterTeagle
Copy link

I personally think that the current system is fine, as I think that plugin and ftplugin can be written around with vim.g for plugin and filetype specific plugins loading with their own custom mapping, If I didnt already have my own config I would be 100% down for this change, I am just being lazy. Then again I dont know much about the merits of ftplugin and plugin, so it is possible that there is a use to those directories that I do not know.

I was going to say that this loses its plugin and play, but I read more and I think that while this problem is solved it seems to cause another problem(unless I am wrong again) in that it requires you to fork it to really have your own config, and then you have to deal with updating.

Ideally you would support both configs somehow but that is too much work I believe. Overall though I think that this is going to be a net positive change, once the kinks are worked out(if any).

@AdiCahyaSaputra
Copy link

This gave me more flexibility to customize NvChad and maybe I can use the custom config I built myself and just install the NvChad as a plugin 😅

@siduck
Copy link
Member Author

siduck commented Mar 6, 2024

ftplugin can be written around with vim.g

kinda sketchy for newbies. Users should just use what a normal config uses for ftplugin etc and not go for such overriding qwirks for that custom config abstraction

@siduck
Copy link
Member Author

siduck commented Mar 6, 2024

I'm excited to try it. The only challenging part seems to be the updating process, but if you can create a custom command for it, it would be amazing. Thank you, Sid for your amazing work. 😊

That's hard and maybe impossible for now.

I dont think so @ARBoyGo . Just clone the starter repo and then mv your plugins dir into .config/nvim/lua/plugins instead of .config/nvim/lua/custom , and custom init.lua stuff can be loaded in main init.lua itself.

but i think we can make a script for this? @Alexis12119

@nautrw
Copy link

nautrw commented Mar 9, 2024

Yes. The current state of NvChad configs in v2 isn't very good. They aren't beginner-friendly. This would make it easier to use NvChad as now you can use the same old Nvim config rather than this maze we have in v2. I think y'all could take it even a step forward and make the plugins not depend on each other so much, to be able to use the NvChad status bar and whatever other GUI plugins. I think it would require custom color schemes to be implemented and not the current base46 system, but that's just a thought,

@siduck
Copy link
Member Author

siduck commented Mar 9, 2024

plugins not depend on each other so much

UI plugin is dependent on base46. Both can be used if nvconfig module is in your path i.e lua dir

@siduck siduck closed this as completed Mar 9, 2024
@KorigamiK
Copy link
Contributor

So, would v3.0 be sunsetted as v2.5 did all the things that v3.0 promised?

@siduck
Copy link
Member Author

siduck commented Mar 12, 2024

@KorigamiK v2.5 isnt a big release as it doesnt have much features. v3.0 will be a big one (Although most changes will come from ui/base46 )

@siduck siduck changed the title Need Feedback for using starter template config for v3.0 ( Freedom from custom config ) Need Feedback for using starter template config for v2.5( Freedom from custom config ) Mar 12, 2024
@moooooo16
Copy link

One little glitch I found is loading order. When mapping is loaded, LSP related mapping is not loaded. So if I want to delete LSP mapping it will result a no mapping found error.

@siduck
Copy link
Member Author

siduck commented Mar 15, 2024

@moooooo16 thats just for buffer local mappings so lsp / gitsigns mappings are loaded on attached buffers only. So to delete or override those mappings u gotta make a wrapper on_attach func which loads default onattach + your mapping code

@moooooo16
Copy link

@siduck That worked, thanks! Also I really wanna say this entire thing is awesome!

@LimingFang
Copy link

Already use v2.5, quite nice. One minor question(maybe unrelated with starter template), say that if I want to disable clangd LSP server autostart, I can config it in lua/config/lspconfig.lua:

lspconfig.clangd.setup {
    autostart = false,
    -- ......
}

But lua-lsp-server is already confined in NvChad plugin, if I want to do the same thing as clangd, I have to override the config, is this the only way?

@siduck
Copy link
Member Author

siduck commented Apr 2, 2024

@LimingFang you'll have to override the config, yes. lspconfig will use yours one

@treeshateorcs
Copy link

I have C-c set to ":wq!" (also for insert and visual modes) in lua/mappings.lua, but it still copies instead of saving and exiting

@siduck
Copy link
Member Author

siduck commented Apr 5, 2024

I have C-c set to ":wq!" (also for insert and visual modes) in lua/mappings.lua, but it still copies instead of saving and exiting

show me your code, it works fine here -_-

simplescreenrecorder-2024-04-05_07.55.18.mp4

@treeshateorcs
Copy link

treeshateorcs commented Apr 5, 2024

i just did migrate.sh, nothing else. this is the entire mappings.lua

require "nvchad.mappings"
---@type MappingsTable
local M = {}

M.general = {
  n = {
    [";"] = { ":", "enter command mode", opts = { nowait = true } },
    ["<C-c>"] = { ":wq!<cr>" },
    ["<C-s>"] = { ":w!<cr>" },
    ["j"] = { "gj" },
    ["k"] = { "gk" },
    ["<2-LeftMouse>"] = { "<LeftMouse>" },
    ["<LeftMouse>"] = { "<Nop>" },
  },
  v = {
    [">"] = { ">gv", "indent" },
    ["<C-c>"] = { "<ESC>:wq!<cr>" },
    ["<C-s>"] = { "<ESC>:w!<cr>" },
    ["<2-LeftMouse>"] = { "<LeftMouse>" },
    ["<LeftMouse>"] = { "<Nop>" },
  },
  i = {
    ["<C-c>"] = { "<ESC>:wq!<cr>" },
    ["<C-s>"] = { "<ESC>:w!<cr>" },
    ["<2-LeftMouse>"] = { "<LeftMouse>" },
    ["<LeftMouse>"] = { "<Nop>" },
  },
}

-- more keybinds!

return M

@siduck
Copy link
Member Author

siduck commented Apr 5, 2024

@treeshateorcs u should know that the old mapping stuff is removed, in v2.5 your mapping syntax can be anything, so just loop over your table and use vim.keymap.set , and pls remove return M too

#2688

in nvchad v2.5 it has config structure to that of general nvim configs so no custom config abstractions, now y'all will actually learn how neovim configs work, and please read all of nvchad.com too

@treeshateorcs
Copy link

okay, will do. thank you!

@LimingFang
Copy link

Hi, i have a question about how to override plugin configs. Take "nvim-cmp" as an example. In nvchad plugin nvchad/configs/cmp.lua, it configs nvim-cmp's completion source like this:

sources = {
    { name = "nvim_lsp" },
    { name = "luasnip" },
    { name = "buffer" },
    { name = "nvim_lua" },
    { name = "path" },
  },

And in nvchad/plugins/init.lua, it loads like this:

{
  -- .....
 opts = function()
      return require "nvchad.configs.cmp"
  end,
  config = function(_, opts)
    require("cmp").setup(opts)
  end,
}

If i only want nvim_lsp as cmp source, i try to define configs/cmp.lua in my lua configs:

local options = require("niched.configs.cmp")
options.source = {
    { name = "nvim_lsp" },
}
return options

And in plugins/init.lua:

{
    "hrsh7th/nvim-cmp",
     opts = function()
       require "configs.cmp"
     end,
     config = function(_, opts)
       require("cmp").setup(opts)
    end,
},

But it doesn't work?🤔

@siduck
Copy link
Member Author

siduck commented Apr 10, 2024

image
its nvchad lol

and return require... in opts because opts can be a table or a function that returns a table

@LimingFang
Copy link

@siduck Thanks for pointing out! I corrected the typo and changed the opts function, but it still didn't work🤔, and i found that it's options.sources😛. BTW, one more question, since in nvchad/plugins/init.lua, it returns a table, so actually i will just do require("cmp").setup(opts) once, right? Since my init.lua override NvChad one?
This is my plugin/init.lua:
image
This is my configs/cmp.lua:
image

@siduck
Copy link
Member Author

siduck commented Apr 11, 2024

i'll test this tomorrow, how are u verifying if it works? cmpstatus command?

@LimingFang also seek help in our discord server! ( check nvchad.com footer for link ) , we shouldnt be discussing in this thread lol

@LimingFang
Copy link

@siduck one last replay! Finally it worked

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

10 participants