Neovim
Neovim setup and general info
Updated: 08 November 2024
Installation
The following need to be installed to use Neovim with Plugins
I had an issue installing
vim-plug
that ended up putting the config into the wrong folder, just ensure that~/.vim/autoload
contents are copied to~/.config/nvim/autoload
if nvim can’t find theplug
function - create the.config/nvim
directory if it doesn’t exist
Setup
Vim Plug
First, create a ~/.config/nvim/init.vim
file if it doesn’t already exist, and add the following to setup vim-plug
init.vim
After adding a plugin and saving (:w
), you will need to reload the nvim config:
And then install the plugins again with:
CoC
CoC is a Vim plugin for code completion, it can be installed using Plug
like so:
Next, run nvim
and install the relevant language servers, for example we can install ts
, eslint
, prettier
, and json
support like so:
Alternatively, you can add the CoC extensions into the init.vim
file like so:
The relevant CoC extensions will be automatically installed the next time you open an editor if they aren’t already
Key Bindings/Mappings
We can add keybindings for CoC by copying the base keybindings from their documentation, you can also see them below:
Additionally, you can add the following for some spacing preferences and line numbers:
Themes
You can use Vim themes by downliading them and adding to the ~/.config/nvim/colors
folder. For example, you can use the Molokai Theme
Then, use the :Colors
command to select at theme - this should automatically load any themes in the colors
directory as available
You can also set a default theme like so:
FZF
FZF Is a Command Line Fuzzy Search and can be installed in the init.vim
file like so:
I’m using this along with the below settings:
After that, resource and install plugins, and then you can use the following commands:
Command | Description |
---|---|
:Files | Search all Files |
:GFiles | Search all Git Tracked Files |
:Buffers | View Open Buffers |
:Rg | Search in Files (see below) |
You can then search for files and press enter to open a file
Adding a !
to the end of the FZF Command will open the search window in full screen
Additionally, we can use ripgrep via the :Rg
command to search for text content inside of files
It should also be noted that unless bat
is installed, you will not have syntax highlighting in the FZF search results
NERDTree
:NERDTree
provides a file explorer within NVIM
Command | Description |
---|---|
:NERDTree | Open the file explorer |
? | View Help |
m | Open the file manu |
Note that NERDTree
can also be used from the :Explore
menu by using :Explore
followed by x
(special option) which will launch NERDTree
in place of the explore but will be in the file context so you can do things like create files, etc. more easily
Useful Keybindings
Shortcut | Description |
---|---|
[space] c | View Commands w/ Search |
[space] a | View Language Server Errors |
\f [enter] | Format File |
\rn | Rename Symbol |
gd | Go to Definition |
gr | Go to References |
\a | Code Action |
[g | Previous Error |
]g | Next Error |
qf | Code Fix |
[ctr] [space] | View Suggestions |
[shift] k | View Code Doc |
[space] o | View Symbols |
[ctrl] t | From GFiles View, open in new tab |
gt gT | Go to next tab/previous tab |
Using NuShell with Vim
You can configure Nushell with Vim using Lua config as:
Telescope + Quickfix
Telescope is used often as a UI for finding stuff and integrates with a lot of other tools in the Neovim ecosystem. Something particularly handy with telescope is the ability to create a quickfix list from a telescope search/filter. This can be done from Telescope with ctrl + q
which will close telescope and open a quickfix list with the current set of results
Using telescope this way is a nice method to get quickfix lists from a few other things:
- LSP references
- LazyGit Status (faster than the viewing the git file tree)
- Ripgrep
- Telescope file search