Giter Club home page Giter Club logo

nvim-reload's Introduction

nvim-reload

About

Nvim-reload is a Neovim plugin that allows you to reload your entire Neovim config completely, including your start plugins. It also reloads all lua modules inside your Neovim config directory.

THIS PROJECT IS NO LONGER BEING MAINTAINED. YOU MIGHT STILL BE ABLE TO USE IT BUT DO NOT EXPECT ANY ISSUES YOU HAVE WITH IT TO BE FIXED. THOSE WILLING TO MAINTAIN IT CAN FEEL FREE TO CREATE A FORK

Requires:

How to install

use 'famiu/nvim-reload'
paq 'famiu/nvim-reload'
Plug 'famiu/nvim-reload'

How to use

Just install the plugin and it'll define two commands for you, :Reload and :Restart, to reload and restart your Vim config, respectively. Note that 'restart' here just means reloading and manually triggering the VimEnter autocmd to emulate a new run of Vim, it will not actually restart Vim.

You can also use the following Lua functions require('nvim-reload').Reload() and require('nvim-reload').Restart() instead of the :Reload and :Restart commands.

Configuration

By default, nvim-reload reloads:

  • Your init file.
  • Your config files (VimL files in stdpath('config').
  • Your start plugins (plugins that are automatically loaded when Neovim is started, located in stdpath('data')/site/pack/*/start/*).

NOTE: The asterisks used above are file globs, not literal asterisks.

In case you didn't know, Lua caches the modules you load using require(). Which can prevent you from reloading your configuration since Lua will use the cached version of your config instead of the modified version. So the plugin also unloads the Lua modules inside your Neovim config located in stdpath('config')/lua, which makes Lua actually reload them.

If you want, you can change the default behavior through the following configuration options.

  • vim_reload_dirs - Table containing list of directories to reload the Vim files from. The plugin will look into the 'compiler', 'doc', 'keymap', 'syntax' and 'plugin' subdirectories of each directory provided here and reload all VimL files in them.
    Default: { vim.fn.stdpath('config'), vim.fn.stdpath('data') .. '/site/pack/*/start/*' }

  • lua_reload_dirs - Table containing list of directories to load the Lua modules from. The plugin will look into the lua subdirectory of each directory provided here for modules to reload.
    Default: { vim.fn.stdpath('config') }

  • files_reload_external - Table containing paths to external VimL files (files not inside any of the vim_reload_dirs) to reload.
    Default: {}

  • modules_reload_external - Table containing Names of external modules (modules not inside any of the lua_reload_dirs) to reload.
    Default: {}

  • pre_reload_hook - Function to run before reloading the config.
    Default: nil

  • post_reload_hook - Function to run after reloading the config.
    Default: nil

Example config:

local reload = require('nvim-reload')

-- If you use Neovim's built-in plugin system
-- Or a plugin manager that uses it (eg: packer.nvim)
local plugin_dirs = vim.fn.stdpath('data') .. '/site/pack/*/start/*'

-- If you use vim-plug
-- local plugin_dirs = vim.fn.stdpath('data') .. '/plugged/*'

reload.vim_reload_dirs = {
    vim.fn.stdpath('config'),
    plugin_dirs
}

reload.lua_reload_dirs = {
    vim.fn.stdpath('config'),
    -- Note: the line below may cause issues reloading your config
    plugin_dirs
}

reload.files_reload_external = {
    vim.fn.stdpath('config') .. '/myfile.vim'
}

reload.modules_reload_external = { 'packer' }

reload.post_reload_hook = function()
    require('feline').reset_highlights()
end

NOTE: The directories provided in lua_reload_dirs and vim_reload_dirs can be globs, which will automatically be expanded by the plugin.

Note

This plugin is still quite new and might have some bugs. And in case it does, feel free to make an issue here to report them.

Self-plug

If you liked this plugin, also check out:

  • feline.nvim - A nice customizable statusline for Neovim written in Lua.
  • bufdelete.nvim - Delete Neovim buffers without losing your window layout.

nvim-reload's People

Contributors

famiu avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar

nvim-reload's Issues

Error calling Reload/Reset with vim-polyglot

When I have vim-polyglot installed via packer:

use 'sheerun/vim-polyglot'

And I attempt to run either Restart or Reload, I get the following error:

Error detected while processing BufWritePost Autocommands for "init.lua":
E5108: Error executing lua ...e/pack/packer/start/nvim-reload/lua/nvim-reload/init.lua:130: Vim:E492: Not an editor command: HaxeHiLink haxeError2 haxeError

When I remove vim-polyglot from my configuration everything works fine. Is there a way to work around this? Maybe excluding vim-polyglot from reloading?

Add a vim help file

to make it easy to read up on it with the need to go to your github repo.

Errors on :Reload and :Restart

Hi,

I'm getting the following when running ':Reload' or ':Restart':
E5108: Error executing lua ...e\pack\packer\start\nvim-reload\lua\nvim-reload\init.lua:107: bad argument #1 to 'gsub' (string expected, got nil)

I haven't added anything specific for nvim-reload to my init.lua or plugins.lua, which is called with require('plugins.lua') from init.lua (which lives under stdpath('config')). I'm just installing it and running it via packer, This is with nvim 0.5.0 on windows. nvim-reload and plenary are pulled as start plugins by packer:

  -- Lua Reloading Related
  use {
	  'famiu/nvim-reload',
	  opt = false,
	  requires = {
	  	{'nvim-lua/plenary.nvim', opt = false}
	  }
}

Any idea what the issue might be?

Experimental branch - E5108: error executing lua

Setup with Packer:
use { '~/git/nvim-reload', branch = 'experimental' }

Steps to reproduce error:

  • run either :Reload or :Restart

Full error message:

CSV Syntax:Invalid column pattern, using default pattern %([^,]*,|$)
E5108: Error executing lua ...e/pack/packer/start/nvim-reload/lua/nvim-reload/in
it.lua:154: Vim(lua):E5108: Error executing lua /usr/share/nvim/runtime/lua/vim/
treesitter/query.lua:291: Overriding nth?

Probably the same error you getting with the branch... I haven't found the reason why this error is showing up, yet, gotta dive deeper in the code next week. With this error I am only able to use the experimental branch while working on the error, and that's why I will roll back to master for everyday use.

Lualine disappears on `:Reload`

Hi. Good plugin, but i don't understand why when i run :Reload lualine deletes all of its content until restart. Using packer.nvim

nvim-reload's config:

local reload = require('nvim-reload')

reload.lua_reload_dirs = {
	vim.fn.stdpath('config')
}

Lsp isnt restarted properly (using dein.vim)

Hey there,
nice plugin, exactly what i need, though im having a little trouble.
Im using dein and it has a little bit of a weird policy for folders. As far as i understood it it has all the repos in ~/.cache/dein/repos/github.com/ and it caches them all together in a cache dir (~/.cache/dein/.cache/init.vim/.dein/), so the rtp of vim isnt as cluttered. Anyway, i did this to setup your plugin:
`" nvim-reload
lua <<EOF
local reload = require('nvim-reload')

local plugin_dirs = os.getenv("HOME") .. '/.cache/dein/.cache/init.vim/.dein/*'

reload.vim_reload_dirs = {
vim.fn.stdpath('config'),
plugin_dirs
}

reload.lua_reload_dirs = {
vim.fn.stdpath('config'),
-- Note: the line below may cause issues reloading your config
plugin_dirs
}
EOF`

i dont know lua but it seems to work? but not quite.
when i do either :Reload or :Restart i get
Client 1 quit with exit code 1 and signal 0 Client 3 quit with exit code 1 and signal 0 Client 5 quit with exit code 1 and signal 0
(called it three times and the client count is increasing by 2 each time)
and also before the restart :LspInfo gives this
`Configured servers: clangd
Neovim logs at: /home/momo/.cache/nvim/lsp.log

1 client(s) attached to this buffer: clangd

Client: clangd (id 1)
root: ..
filetypes: c, cpp, objc, objcpp
cmd: clangd --background-index

1 active client(s):

Client: clangd (id 1)
root: ..
filetypes: c, cpp, objc, objcpp
cmd: clangd --background-index

Clients that match the filetype cpp:

Config: clangd
cmd: clangd --background-index
cmd is executable: True
identified root: ..
custom handlers:
`

and afterwards it gives this
`Configured servers: clangd
Neovim logs at: /home/momo/.cache/nvim/lsp.log

0 client(s) attached to this buffer:

1 active client(s):

Client: clangd (id 3)
root: ..
filetypes: c, cpp, objc, objcpp
cmd: clangd --background-index

Clients that match the filetype cpp:

Config: clangd
cmd: clangd --background-index
cmd is executable: True
identified root: ..
custom handlers:
`

there is some code to restart the lsp in your plugin but it isnt doing it properly for me at least. Any thoughts?

pre/post reload hooks

I'm currently trying to build some auto reload functionality for the main packer file, however I noticed that feline drops highlights after the reload. Being able to add hooks in config to do this would be super neat.

I could see sth like the following (however I really have no experience with lua whatsoever, I'm just replicating what I've seen over the past days)

use {
  'famiu/nvim-reload',
  config = function()
    local post_reload = function()
      require('feline').reset_highlights()
      vim.api.nvim_command('syntax on') -- no clue why but syntax seems slightly broken when reloading, probably another plugin
    end

    require('nvim-reload').setup {
      post = post_reload
    }
  end
}

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.