Skip to content

Commit 43ea081

Browse files
committed
Add Create User Command To Open Init Config as a Neovim TIL
1 parent ed2e96c commit 43ea081

File tree

2 files changed

+33
-1
lines changed

2 files changed

+33
-1
lines changed

README.md

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,7 @@ pairing with smart people at Hashrocket.
1010

1111
For a steady stream of TILs, [sign up for my newsletter](https://crafty-builder-6996.ck.page/e169c61186).
1212

13-
_1256 TILs and counting..._
13+
_1257 TILs and counting..._
1414

1515
---
1616

@@ -40,6 +40,7 @@ _1256 TILs and counting..._
4040
* [Mac](#mac)
4141
* [MongoDB](#mongodb)
4242
* [MySQL](#mysql)
43+
* [Neovim](#neovim)
4344
* [Netlify](#netlify)
4445
* [Next.js](#nextjs)
4546
* [Phoenix](#phoenix)
@@ -536,6 +537,10 @@ _1256 TILs and counting..._
536537
- [Show Tables That Match A Pattern](mysql/show-tables-that-match-a-pattern.md)
537538
- [Show Indexes For A Table](mysql/show-indexes-for-a-table.md)
538539

540+
### Neovim
541+
542+
- [Create User Command To Open Init Config](neovim/create-user-command-to-open-init-config.md)
543+
539544
### Netlify
540545

541546
- [Override The Default Yarn Version](netlify/override-the-default-yarn-version.md)
Lines changed: 27 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,27 @@
1+
# Create User Command To Open Init Config
2+
3+
I'm experimenting with a fresh Neovim configuration using
4+
[kickstart](https://github.com/nvim-lua/kickstart.nvim). That means I'm
5+
frequently navigating to my `init.lua` file to add and adjust things that I
6+
find are missing from my workflow.
7+
8+
I got tired of typing out the path—in my case `~/.config/nvim/init.lua`—every
9+
single time I wanted to edit it. So, I typed out that path one last time so
10+
that I could add a custom user command.
11+
12+
```
13+
-- Open this config file
14+
vim.api.nvim_create_user_command(
15+
'Config',
16+
"e ~/.config/nvim/init.lua",
17+
{bang = true, desc = "Open init.lua Neovim config"}
18+
)
19+
```
20+
21+
This uses [the lua command
22+
API](https://neovim.io/doc/user/api.html#api-command) to create a user-defined
23+
command.
24+
25+
When I invoke `:Config` from the Neovim command prompt and hit enter, Neovim
26+
will effectively replace that command with the second argument to that command
27+
`:e ~/.config/nvim/init.lua`. Which opens me up to the config file.

0 commit comments

Comments
 (0)