Skip to content

Instantly share code, notes, and snippets.

@siduck
Last active April 15, 2024 08:14
Show Gist options
  • Star 3 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save siduck/048bed2e7570569e6b327b35d1715404 to your computer and use it in GitHub Desktop.
Save siduck/048bed2e7570569e6b327b35d1715404 to your computer and use it in GitHub Desktop.
Migrate from v2.0 to v2.5 ( Unix Only )
#!/bin/bash
# Run the script from home dir
cd ~
nvim_config="$HOME/.config/nvim"
nvim_data="$HOME/.local/share/nvim"
cp -r "$nvim_config" nvim_bak # backup nvim dir
cp -r "$nvim_config/lua/custom" .
# Remove prefix 'custom.' from all files
find custom -type f -exec sed -i 's/custom\.//g' {} +
# replace all plugins.configs -> nvchad.configs
find custom -type f -exec sed -i 's/plugins.configs/nvchad.configs/g' {} +
cd custom
# we will load this in main init.lua
mv init.lua myinit.lua
# disable these fields in chadrc
sed -Ei 's/M.mappings|M.plugins/-- &/g' chadrc.lua
# add new module paths
[ -e options.lua ] && sed -i '1s/^/require "nvchad.options"\n/' options.lua
[ -e autocmds.lua ] && sed -i '1s/^/require "nvchad.autocmds"\n/' autocmds.lua
[ -e mappings.lua ] && sed -i '1s/^/require "nvchad.mappings"\n/' mappings.lua
cd ..
rm -rf "$nvim_config" "$nvim_data"
# setup new config
git clone https://github.com/NvChad/starter "$nvim_config"
if [ -e custom/configs ]; then
mv custom/configs/* "$nvim_config/lua/configs/"
rm -rf custom/configs
fi
mv custom/* "$nvim_config/lua"
cd "$nvim_config"
# load custom.init.lua if it exists
[ -e lua/myinit.lua ] && echo "require 'myinit'" >> init.lua
# Some users have plugins.lua instead of plugins dir/ so move it in the plugins dir
[ -e lua/plugins.lua ] && mv lua/plugins.lua lua/plugins/myplugins.lua
nvim
@Maritsu
Copy link

Maritsu commented Mar 10, 2024

Is the branch supposed to be test on line 34, or should it be v2.5?

@siduck
Copy link
Author

siduck commented Mar 10, 2024

@Maritsu thanks for correcting, it should be starter. Starter config will pull Nvchad main repo's v2.5 branch!

@h0pes
Copy link

h0pes commented Mar 10, 2024

From which dir is the script expected to be run? (i.e. line 7 recursively copying to current dir). Thanks

@siduck
Copy link
Author

siduck commented Mar 10, 2024

@h0pes home dir

@h0pes
Copy link

h0pes commented Mar 10, 2024

Do you mean ~? Might be useful to add a simple cd ~ then. Thanks for the code comment though

@siduck
Copy link
Author

siduck commented Mar 10, 2024

Do you mean ~? Might be useful to add a simple cd ~ then. Thanks for the code comment though

yes

@LeonardoMor
Copy link

Lines 23 and 24 can be replaced with:

sed -Ei 's/M.mappings|M.plugins/-- &/g' chadrc.lua

This will comment these lines as opposed to alter them.

@siduck
Copy link
Author

siduck commented Mar 11, 2024

@LeonardoMor
Copy link

Also a small bug, line 48 should be replaced with:

[ -e lua/myinit.lua ] && echo "require 'myinit'" >>init.lua

@siduck
Copy link
Author

siduck commented Mar 11, 2024

Also a small bug, line 48 should be replaced with:

[ -e lua/myinit.lua ] && echo "require 'myinit'" >>init.lua

done

@Andrew15-5
Copy link

rm -rf $nvim_config $nvim_data

Line 32 suddenly lacks the double quotes.

https://sipb.mit.edu/doc/safe-shell/

You can throw in

set -eu

for good measure.

@igordertigor
Copy link

Unfortunately, this didn't work for me. It seems that the plugin installation part works without issues, but then I get

Error detected while processing /Users/xxx/.config/nvim/init.lua:
E5113: Error while calling lua chunk: cannot open /Users/xxx/.local/share/nvim/nvchad/base46/defaults: No such file or directory
stack traceback:
        [C]: in function 'dofile'
        /Users/xxx/.config/nvim/init.lua:32: in main chunk

When I press enter (to skip the error message) I get the next error message:

Failed to run `config` for ui
/Users/xxx/.local/share/nvim/lazy/ui/lua/nvchad/init.lua:2: loop or previous error loading module 'nvconfig'

# stacktrace:
  - /ui/lua/nvchad/init.lua:2
  - //NvChad/lua/nvchad/plugins.ui.lua:16 _in_ **config**
  - .config/nvim/init.lua:17

and a large message for base46 "build failed" then with red background:

/Users/xxx/.config.nvim/lua/chadrc.lua:14: module 'custom.mappings' not found:
  no field package.preload['custom.mappings']
cache_loader: module custom.mappings not found
cache_loader_lib: module custom.mappings not found
  no file './custom/mappings.lua'
  no file '/opt/homebrew/share/luajit-2.1/custom/mappings.lua'
  no file '/usr/local/share/lua/5.1/custom/mappings.lua'
  no file '/usr/local/share/lua/5.1/custom/mappings/init.lua'
  no file '/opt/homebrew/share/lua/5.1/custom/mappings.lua'
  no file '/opt/homebrew/share/lua/5.1/custom/mappings/init.lua'
  no file './custom/mappings.so'
  no file '/usr/local/lib/lua/5.1/custom/mappings.so'
  no file '/opt/homebrew/lib/lua/5.1/custom/mappings.so'
  no file '/usr/local/lib/lua/5.1/loadall.so'
  no file './custom.so'
  no file '/usr/local/lib/lua/5.1/custom.so'
  no file '/opt/homebrew/lib/lua/5.1/custom.so'
  no file '/usr/local/lib/lua/5.1/loadall.so'

The last error seems to suggest that there was some custom file that wasn't properly renamed. Any ideas how to fix this?

@siduck
Copy link
Author

siduck commented Apr 4, 2024

@igordertigor now you check the manual migration, check v2.5 release news article. you should understand how the new config structure works, and is same as general nvim configs unlike custom config abstraction in v2.0 . Man up!

So first of all check your chadrc, M.mappings and M.plugins in it are no longer needed

@bendavis78
Copy link

bendavis78 commented Apr 12, 2024

This script needs set -e at the top (or && or || exit 1 on each step), so it won't continue if there are previous errors. I ran it, got a bunch of errors, and couldn't read the errors before nvim started. In hindsight I should have just done each step manually.

@Andrew15-5
Copy link

I haven't done the migration yet, but the code is pretty big and has a lot going on. I already posted feedback about this (here), but I'll probably try to understand what it exactly does anyway and then see if I want to run it manually or not.

@siduck
Copy link
Author

siduck commented Apr 13, 2024

This script needs set -e at the top (or && or || exit 1 on each step), so it won't continue if there are previous errors. I ran it, got a bunch of errors, and couldn't read the errors before nvim started. In hindsight I should have just done each step manually.

feel free to send an updated version of the script, i'll add it in the migration docs on nvchad.com itself

@baiwfg2
Copy link

baiwfg2 commented Apr 14, 2024

hi. I'm configure nvim-dap. In 2.0, it can be configured like (copied from here https://github.com/dreamsofcode-io/neovim-cpp/blob/main/plugins.lua#L33):

 {
    "mfussenegger/nvim-dap",
    config = function(_, _)
      require("core.utils").load_mappings("dap")
    end
  },

Migrate it into lua/plugins/xxx.lua in v2.5, it reports error:

Failed to run `config` for nvim-dap

/root/.config/nvim/lua/plugins/myplugins.lua:35: module 'core.utils' not found:
^Ino field package.preload['core.utils']
cache_loader: module core.utils not found
cache_loader_lib: module core.utils not found
^Ino file './core/utils.lua'
^Ino file '/__w/neovim/neovim/.deps/usr/share/luajit-2.1/core/utils.lua'
^Ino file '/usr/local/share/lua/5.1/core/utils.lua'
^Ino file '/usr/local/share/lua/5.1/core/utils/init.lua'
^Ino file '/__w/neovim/neovim/.deps/usr/share/lua/5.1/core/utils.lua'
^Ino file '/__w/neovim/neovim/.deps/usr/share/lua/5.1/core/utils/init.lua'
^Ino file './core/utils.so'
^Ino file '/usr/local/lib/lua/5.1/core/utils.so'
^Ino file '/__w/neovim/neovim/.deps/usr/lib/lua/5.1/core/utils.so'
^Ino file '/usr/local/lib/lua/5.1/loadall.so'
^Ino file './core.so'
^Ino file '/usr/local/lib/lua/5.1/core.so'
^Ino file '/__w/neovim/neovim/.deps/usr/lib/lua/5.1/core.so'
^Ino file '/usr/local/lib/lua/5.1/loadall.so'

# stacktrace:
  - lua/plugins/myplugins.lua:35 _in_ **config**
Press ENTER or type command to continue
Failed to run `config` for nvim-dap-ui

/root/.local/share/nvim/lazy/nvim-dap-ui/lua/dapui/init.lua:36: nvim-dap-ui requires nvim-nio to be installed. Install from https://github.com/nvim-neotest/nvim-nio

How can I solve this ?

BTW, I install neovim 0.9.5 in customized path:

# ls /data/opt/nvim/
bin  lib  man  share

@siduck
Copy link
Author

siduck commented Apr 14, 2024

@baiwfg2 the mapping part isnt automatic, so please remove the core.utils** stuff and convert your mappings to new ones

@tariks
Copy link

tariks commented Apr 15, 2024

Works on macos with gsed in lieu of sed

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