|
| 1 | +--- |
| 2 | +title: Editing Ghostty Config in Neovim |
| 3 | +date: 2024-12-27 |
| 4 | +draft: false |
| 5 | +--- |
| 6 | + |
| 7 | +Finally, the new-kid-on-the-block of terminal emulators, |
| 8 | +[Ghostty](https://ghostty.org), has made its public debut! As someone who |
| 9 | +missed out on the beta program, I was eagerly counting down the days and jumped |
| 10 | +in as soon as it was released. |
| 11 | + |
| 12 | +When I began configuring Ghostty, I noticed it uses its own simple |
| 13 | +configuration format—essentially `key = value` pairs. Naturally, I tried |
| 14 | +setting the filetype to `ini` with `:set ft=ini`, but the highlighting didn’t |
| 15 | +quite hit the mark. So, I thought, “Why not write a custom syntax file?” |
| 16 | +Perhaps I could even upstream it to [vim/vim](https://github.com/vim/vim). But, |
| 17 | +surprise! The Ghostty team had already done the hard work for me. |
| 18 | + |
| 19 | +Ghostty generates a complete set of Vim/Neovim support files during its build |
| 20 | +process: an |
| 21 | +[`ftdetect`](https://neovim.io/doc/user/usr_41.html#_filetype-detection), an |
| 22 | +[`ftplugin`](https://neovim.io/doc/user/usr_41.html#_writing-a-filetype-plugin), |
| 23 | +and a [`syntax`](https://neovim.io/doc/user/syntax.html#_2.-syntax-files) file. |
| 24 | +These can be added to Vim’s runtimepath for automatic integration. |
| 25 | + |
| 26 | +On macOS, these files are bundled in `/Applications/Ghostty.app/`. |
| 27 | +On Linux, it’s likely in `/usr/share/ghostty` or |
| 28 | +`/usr/share/vim`, I'm not sure. But you can always use the |
| 29 | +`$GHOSTTY_RESOURCES_DIR` environment variable as a platform-agnostic way to |
| 30 | +locate them. |
| 31 | + |
| 32 | +Then I discovered that changing the runtimepath yourself when you use Lazy.nvim |
| 33 | +is not that straightforward. So, I took the simpler route and just treated it |
| 34 | +as a local Lazy plugin: |
| 35 | + |
| 36 | +```lua |
| 37 | +return { |
| 38 | + dir = vim.env.GHOSTTY_RESOURCES_DIR .. "/../vim/vimfiles", |
| 39 | + lazy = false, -- Ensures it loads for Ghostty config detection |
| 40 | + name = "ghostty", -- Avoids the name being "vimfiles" |
| 41 | + cond = vim.env.GHOSTTY_RESOURCES_DIR ~= nil, -- Only load if Ghostty is installed |
| 42 | +} |
| 43 | +``` |
| 44 | + |
| 45 | +Tada! Thanks to the great work by the authors, this now provides syntax |
| 46 | +highlighting for the Ghostty config file. Bonus points: |
| 47 | +[<C-x><C-o>](https://neovim.io/doc/user/insert.html#i_CTRL-X_CTRL-O) completes |
| 48 | +the Ghostty options! |
0 commit comments