My neovim setup (with Ghostty)
Last year, I switched from Sublime Text to Neovim and Neovim has proved to be very efficient. This post showcases my Neovim setup and some useful tips.
I agree with Guilherme D. Garcia that multiple tools for multiple purposes (RStudio for R, Sublime Text for markdown and $LaTeX$, etc.) is far from perfect, and Neovim indeed provided an integrated way of dealing with all these purposes (markdown/$LaTeX$, R, Python, and many more). It also provides the incredible capabilities of the Vim arsenal.
I use the LazyVim and it ships with many useful and convenient functions. One of the Plugins that I use many times a day is Telescope. It can bring you the files you want using fuzzy finder with blazing speed.
What I have always been confused is why dark colorschemes are so popular, and I’m far more comfortable with bright colorschemes. A few searching gave me the github-nvim-theme, which has a bright theme, and it has been very comfortable so far. I use the Consolas font for ASCII, but for Chinese characters, there are not so many options. Two fonts, Sarasa Term SC Nerd and Maple Mono, are the two most famous monospace fonts for Chinese characters, and they both align well with ASCII characters with a perfect 2:1 ratio. I chose Sarasa-Term-SC-Nerd because I find it asthetically more appealing.
LuaSnip is a powerful snippet manager for Neovim, and using Lua, you can define your own snippets very quickly. For example, I need to insert the head of each blog post with title, author, date, etc, so I have a snippet for it.
{
"Insert front matter": {
"prefix": "meta",
"body": ["---", "title: ${1:title}", "author: ${2:Chunyu Ge 葛淳宇}", "documentclass: tufte-handout\ndate: $CURRENT_YEAR-$CURRENT_MONTH-$CURRENT_DATE\nnumbersections: false\ndraft: yes", "---"]
}
}
Note that the snippet is in the VS-Code fashion, and the reason is that I haven’t figured out how to make the Lua version work in my MBP.
For running code in REPL, I installed the nvim-repl, which is very easy to set up and use.
When I take notes using markdown, I use bullet points a lot. The bullets.vim plugin is great in demoting and promoting bullet types with Ctrl-t (denote) and Ctrl-d (promote).
Thanks to Neovim, now I stay in the terminal almost all day long, and I use tmux to manage the buffers and windows. The default statusline of tmux in at the bottom of the terminal window, which can be quite distracting for Neovim, because it also has the statusline on the bottom, so I moved the statusline of tmux to the top, and I use a minimalist configuration for the color scheme of the statusline, as shown below. Also, the default tmux prefix combination is Ctrl+b, but it conflicts with the back-half-page hotkey in vim, so I changed it to Ctrl-f, although it conflicts with the backpage hotkey. But it is very convenient, especially for touch typing.
unbind C-b
set-option -g prefix C-f
set -g status-position top
set -g status-style fg=white,bg=black
setw -g window-status-current-style fg=white,bg=red,bright
set -g status-left ""
set -g status-right ""
Convert markdown files to pdf, epub, and etc using Pandoc
Now I have a more efficient and fast way to convert markdown files to pdf in Neovim than my earlier approach. I have the following autocommand which can quickly be called in Neovim, and after successful convertion, the pdf reader Sioyek will open automatically, showing the pdf file. I use Sioyek to preview the pdf file, because unlike Skim, it can use the same keybinding as vim, and makes it more convenient to navigate the pdf file.
vim.opt_local.wrap = true
--
-- Pandoc <format> to compile documents quickly and easily:
vim.api.nvim_create_user_command("Pandoc", function()
vim.cmd(
"!pandoc -F pandoc-crossref --pdf-engine=xelatex --metadata-file=/Users/chunyu/template/metadata.yaml -H /Users/chunyu/template/head.tex "
.. vim.fn.fnameescape(vim.fn.expand("%p"))
.. " -o /Users/chunyu/pdf/"
.. vim.fn.fnameescape(vim.fn.expand("%:r"))
.. ".pdf && open -a sioyek /Users/chunyu/pdf/"
.. vim.fn.fnameescape(vim.fn.expand("%:r"))
.. ".pdf"
)
end, {})
What’s more, I can have more Pandoc commands, which can convert the markdown file to different formats. For example, I have another command, which converts markdown to epub files. I use the cool epub reader Readest to preview the epub file.
vim.api.nvim_create_user_command("PandocEpub", function()
vim.cmd(
"!pandoc -V lang=zh --css /Users/chunyu/template/epub.css "
.. vim.fn.fnameescape(vim.fn.expand("%"))
.. " -o /Users/chunyu/pdf/"
.. vim.fn.fnameescape(vim.fn.expand("%:r"))
.. ".epub && open -a Readest /Users/chunyu/pdf/"
.. vim.fn.fnameescape(vim.fn.expand("%:r"))
.. ".epub"
)
end, {})
My Ghostty setup
Compared to my previous terminal emulator, iTerm2, Ghostty is light-weight, and its can be configured using a config file. This is better than iTerm2 because it can be set up more quickly. Again, I chose the github-light theme for Ghostty, and I changed the default the icon to another cute one. I also defined some keybindings so that the movements across tabs and splits are smoother and more convenient. The following is my config file.
font-family = "Consolas"
font-family = "Sarasa Term SC Nerd"
font-size = 18
theme = github-light
cursor-color = #4188d0
cursor-text = ffffff
cursor-style = block
background = ffffff
selection-background = #4188d0
selection-foreground = ffffff
window-decoration = true
macos-icon = custom
macos-titlebar-style = tabs
unfocused-split-opacity = 0.6
keybind = cmd+left=previous_tab
keybind = cmd+right=next_tab
keybind = cmd+shift+right=goto_split:right
keybind = cmd+shift+left=goto_split:left
keybind = cmd+shift+up=goto_split:up
keybind = cmd+shift+down=goto_split:down
keybind = cmd+ctrl+right=resize_split:right,20
keybind = cmd+ctrl+left=resize_split:left,20
keybind = cmd+ctrl+up=resize_split:up,20
keybind = cmd+ctrl+down=resize_split:down,20