This is the third episode of the series All about Neovim with Lua if you haven’t read the previous ones, follow the links:
First of all, let’s organize our files and define all the settings (based on mine I use daily).
The lua/tools.lua
file was just an example, so we can already remove it and the lua/settings.lua
file we will put inside a directory named configs/
that we will create to be more organized.
Clean your init.lua
first to not show errors:
Now let’s prepare the environment
Now open init.lua
and insert this content:
You could also use it like this:
require("configs/settings")
Now use my settings.lua
or modify it however you like:
nvim lua/configs/settings.lua
Note: You can also use a single
vim.cmd
to run all the settings, but this has no impact on performance.
Most of these settings for those who use Vim already know what it is, if you don’t know see this article . Then close and reopen your Neovim to see the changes, we’ll change just 3 more lines of that file when we install a color theme!
packer.nvim is a plugin that installs plugins! It is similar to plugins like vim-plug and Vundle that are used in Vim.
Its differential is that it was entirely written in Lua in addition to using resources from LuaJIT to compile and features plugin update, removal, more accurate and detailed UI interfaces. For all his resources see the repository .
It installs plugins written in both Lua and VimScript and runs normally!
To install, just run this command:
Note: You need to have Git installed.
For Unix and GNU/Linux systems
Copy and paste to your terminal and press [ENTER]
After cloning now, let’s create a new directory inside lua/
and let’s create two new files with the contents that we will indicate.
Create the sub directory:
Create and open the file that will hold the packer
installations:
And insert this content inside:
The use
function determines which plugins will be used/handled.
Note that packer.nvim handles itself and we take the opportunity to start it by installing two new plugins:
packer.nvim has the following commands:
:PackerCompile
- Generates the compiled file in: ~/.config/nvim/plugins/packer_compiled.lua
(Note that this is a plugins directory at the root of nvim
and not inside the lua
directory.PackerClean
- Removes all disabled or unused pluginsPackerInstall
- Installs or Cleans up missing pluginsPackerUpdate
- Cleans, updates and installs pluginsPackerSync
- Same as running PackerUpdate
and then PackerCompile
PackerLoad
- Loads the opt
plugin immediately
Some plugins can be installed in the
opt
folder in~/.local/share/nvim/site/pack/packer/opt
instead ofstart
in the same path. For that you need to inform the table{ source = opt }
for theuse
function.
Now just open your init.lua
at the root of your Neovim’s configuration directory and add this line:
Now close and open init.lua
again and run the command:
It saves the files in the directory:
~/.local/share/nvim
and the plugins are in the subdirectory:site/pack/packer/start
.
And once you finish run: :PackerCompile
. You can automate :PackerCompile
for every time there are new installs, if you want to add this line to your settings.lua
:
It will install the plugins and we can already use them! To activate the color theme open the file: nvim lua/configs/settings.lua
and add these 3 lines to the end:
When closing open any file (Ex.:
nvim main.cpp
) and notice a nicer look! 😃
If you want an even darker background change the line in settings.lua
that has this content: vim.cmd([[ colorscheme onedark ]])
with this:
For more “sub-themes” tips from onedark.nvim (in addition to darker) see the repository.
To use vim-simple-emoji see the tips in the repository.
Telescope.nvim is the latest, it is a better alternative to fzf.
It has a modern interface and serves to: Find, filter, view, select and open files simply and quickly. It was also written entirely in Lua.
To install it, add this line to the file: plugins/plugins.lua
Note that
nvim-telescope
has a dependency onnvim-plenary
so we usepacker.nvim
’s own settings for this!
The new plugins.lua
settings will look like this:
Close and open Neovim and run the command: :PackerInstall
. After closing and opening again, run the command:
A “window” will open in the bottom combo you can type the name of the file you want to manipulate, for more details see the repository .
See the Telescope output below:
To end this episode, I’ll leave the mapping file that I use every day. Create a file:
And insert this content inside:
Read the comments and change it any way you like, and then don’t forget to call it in your init.lua