batteriesinfinity.com

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":

Visual representation of Noice.nvim search results

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!

Share the page:

Twitter Facebook Reddit LinkIn

-----------------------

Recent Post:

The Freedom Trap: Why 'Do Whatever You Want' Isn't Enough

Exploring the paradox of freedom and happiness, questioning if doing whatever we want truly leads to fulfillment.

# Elevate Your Personal Brand: Strategies for Success

Discover essential skills and strategies to enhance your personal brand and achieve your career aspirations.

Crows: The Unexpected Intelligence of Our Feathered Friends

Discover the surprising intelligence of crows and their unique social dynamics, revealing how they relate to humans and their environment.

Maximize Every Moment: Time Is Irreplaceable

Learn to value your time wisely and make the most out of every moment you have.

Navigating the Landscape of High and Low-Risk Businesses

Explore the differences between high and low-risk businesses, their pros and cons, and tips for aspiring entrepreneurs.

Unlocking the Secret to Effective LinkedIn Lead Generation

Discover the critical steps to enhance your LinkedIn marketing strategy and effectively generate leads.

Vegan Diet: Unlocking the Secrets to Aging Gracefully in 8 Weeks

Discover how a vegan diet can potentially reverse aging and improve health in just eight weeks.

# Exciting News: I Got $45 Worth of Free DALL-E2 Credits!

I received $45 worth of DALL-E2 credits for free and share my experience with the new credit system and subsidy program.