mirror of
https://github.com/jbranchaud/til
synced 2026-01-09 01:58:02 +00:00
Add Create User Command To Open Init Config as a Neovim TIL
This commit is contained in:
27
neovim/create-user-command-to-open-init-config.md
Normal file
27
neovim/create-user-command-to-open-init-config.md
Normal file
@@ -0,0 +1,27 @@
|
||||
# Create User Command To Open Init Config
|
||||
|
||||
I'm experimenting with a fresh Neovim configuration using
|
||||
[kickstart](https://github.com/nvim-lua/kickstart.nvim). That means I'm
|
||||
frequently navigating to my `init.lua` file to add and adjust things that I
|
||||
find are missing from my workflow.
|
||||
|
||||
I got tired of typing out the path—in my case `~/.config/nvim/init.lua`—every
|
||||
single time I wanted to edit it. So, I typed out that path one last time so
|
||||
that I could add a custom user command.
|
||||
|
||||
```
|
||||
-- Open this config file
|
||||
vim.api.nvim_create_user_command(
|
||||
'Config',
|
||||
"e ~/.config/nvim/init.lua",
|
||||
{bang = true, desc = "Open init.lua Neovim config"}
|
||||
)
|
||||
```
|
||||
|
||||
This uses [the lua command
|
||||
API](https://neovim.io/doc/user/api.html#api-command) to create a user-defined
|
||||
command.
|
||||
|
||||
When I invoke `:Config` from the Neovim command prompt and hit enter, Neovim
|
||||
will effectively replace that command with the second argument to that command
|
||||
— `:e ~/.config/nvim/init.lua`. Which opens me up to the config file.
|
||||
Reference in New Issue
Block a user