Introduction
Hello, I felt as my Neovim configuration was bloated. So, today I'll be teaching you on how to configure your Neovim config, from scratch!
The layout of the configuration.
(If you don't like something, feel free to change up some stuff!)
First, if you haven't already go get Neovim from your favorite package manager(s) or build Neovim from scratch (!)
So, first we're going to set some basic Neovim options, keymaps and then we can go add some plugins!
Initalize your Neovim config.
Go ahead and make a nvim
folder in:
*Nix systems: ~/.config/nvim (or your:
$XDG_CONFIG_HOME/nvim
, if you set that up.)Windows: ~/AppData/Local/nvim
If you've done that, go create an init.lua
in your nvim
configuration directory.
Neovim 5.0+ provides users to write their Neovim configurations in Lua which is:
- Fast.
- Easy.
- And fun!
So, nuf' talkin' and let's go write our Neovim configuration.
We can write all our configuration in one big file. That'll work, but it'll be less easier to maintain. So, we can go break our Neovim configuration in multiple files.
We can have a file structure like:
~/.config/nvim/
├── init.lua
└── lua/
├── core/
│ ├── init.lua
│ └── options.lua
└── keymaps/
└── movement.lua
└── ...
Alright. In out core/init.lua
we're going to require the core.options
and keymaps
modules.
using:
local M = {}
M.setup = function()
require("core.options")
require("keymaps.movement")
end
return M
This code, it provided a .setup()
function. Because it looks cool.
So, now...
Setting options
Let's set some options in our core/options.lua
!
Here's how it could look like:
local o = vim.opt
o.undofile = true -- Persistent undo's across all sessions
o.backup = false -- Don't write backups. (For better performance and, unneeded non-sense
o.writebackup = false -- Don't write backups.
o.shiftwidth = 2 -- Insert two shifts per indent.
o.autoindent = true -- Copy indent from the current line when starting a new line
o.breakindent = true -- Indent wrapped lines too.
o.copyindent = true -- Copy the structure of the existing lines' indents.
o.expandtab = true -- Convert tabs to spaces.
o.smartindent = true -- Non-strict cindent.
o.number = true -- Enable line numbers
I'm not going into much detail on what these options do, but the comments should be self-explanatory
Keymaps.
Neovim provides an interface for it's user to create new key mappings. I'll give you an example:
local map = vim.api.nvim_set_keymap
-- Move up/down on VISUAL line instead of a ACTUAL line
map("n", "j", "v:count == 0 ? 'gj' : 'j'", { expr = true, silent = true })
map("n", "k", "v:count == 0 ? 'gk' : 'k'", { expr = true, silent = true })
That's it!
That's it x2! In the next post, I'll show you how to install lazy.nvim. So be tuned! (P.S this is the final result: here)
Top comments (0)