Enhance Your Neovim Experience with Cmdline Configuration
Written on
Chapter 1: Introduction to Cmdline Enhancements
When I share my screen or post content on YouTube, one question comes up repeatedly: how to elevate the Cmdline experience in Neovim. In this guide, I will introduce two essential plugins that transform how you interact with the Cmdline feature.
Section 1.1: Installing Noice.nvim
It’s no surprise that one of the top-requested plugins is created by the talented Folke. If you’re already using plugins like noice.nvim, trouble.nvim, lazy.nvim, LazyVim, which-key.nvim, or tokyonight.nvim, you're likely familiar with some of his remarkable work.
The most common inquiry I receive is how to position the Cmdline in the center of the screen when invoking it with :.
TL;DR: To enhance your UI, install noice.nvim.
Once installed, noice.nvim will revitalize your UI experience by centering the Cmdline prompt, bringing it to eye level instead of relegating it to the bottom of the screen.
This plugin also includes various features, such as message notifications that appear in the upper right corner. Personally, I find these notifications somewhat excessive, so I added a keymapping to dismiss them:
-- Dismiss Noice Message
vim.keymap.set("n", "nd", "NoiceDismiss", {desc = "Dismiss Noice Message"})
Another great aspect is the virtual text that appears when you search using /. Here’s an example after searching for "telescope":
Noice.nvim simplifies the process of viewing messages and searching through your command history, with options to redirect messages as needed. You can retrieve the first or last message with :Noice first or :Noice last, and list all messages in a split using :messages.
If you add the telescope extension, you can fuzzy find through your messages using:
require("telescope").load_extension("noice")
For a polished UI experience and to keep your messages and Cmdline elevated, installing noice.nvim is highly recommended.
Section 1.2: Implementing cmp-cmdline
If you’re accustomed to configuring your LSP and have utilized cmp* plugins, then cmp-cmdline will feel familiar. This plugin introduces an additional source for autocompletion, allowing you to autocomplete file paths directly from the Cmdline.
Make sure to include cmp-cmdline in your LSP dependencies:
dependencies = {
{ "hrsh7th/cmp-cmdline" },
}
Next, integrate this into your LSP or cmp configuration:
local cmp = require("cmp")
-- / cmdline setup.
cmp.setup.cmdline('/', {
mapping = cmp.mapping.preset.cmdline(),
sources = {
{ name = 'buffer' }}
})
-- : cmdline setup.
cmp.setup.cmdline(':', {
mapping = cmp.mapping.preset.cmdline(),
sources = cmp.config.sources({
{ name = 'path' }}, {
{
name = 'cmdline',
option = {
ignore_cmds = { 'Man', '!' }}
}
})
})
After restarting Neovim, you can type :e / and enjoy seamless autocompletion. When used alongside noice.nvim, the overall experience is significantly enhanced. If you ever need to cancel autocompletion, simply press Ctrl+e, or exit the prompt with Ctrl+c.
Conclusion
Your UI should now be significantly improved, complete with excellent autocompletion for file or directory searches. If you have any favorite plugins, feel free to share your thoughts in the comments!
If you found this article helpful, consider subscribing to my Medium page! Here are a few other Neovim articles worth checking out. For those interested in technical interviews, please reach out via Twitter (@Exosyphon) or visit my website. If this topic resonates with you, you might also enjoy my YouTube channel. Have a wonderful day!