Setting Default Options For Neovim
Now before we start loading plugins for Neovim, we must set default options like the line number, gutter size and other settings which can enable us customize Neovim to a degree.
I will endeavour to explain the configuration code and how it affects the Neovim editor. To set up the folder structure check out my previous post.
So, in the lua folder we created, we will see a config folder. Now we create an options.lua
file to contain our configuration options for Neovim.You can reference the Neovim Docs for help.
1.Line Numbers
I use relative line numbers,it informs me of how many lines up or down of my current cursor position i am. To set this we add the following.
vim.o.number = true -- this enables line numbers
vim.o.relativenumber = true -- enable relative line numbers
2. Clipboard
I want to be able to copy text from other applications and paste them in Neovim. For that i will need access to the system clipboard.
vim.o.clipboard = "unnamedplus"
3. Searching Text
In writing code, there comes a point where you need to find some text in your code. The options below help with this.
vim.o.ignorecase = true -- return result ignoring the case of the search text
vim.o.smartcase = true
vim.o.hlsearch = false -- Do not hightlight all occurances of the search result
vim.o.incsearch = true -- Hightlight the matched search string/text.
4. Undo
In working mistakes do occur, such mistakes need to be undone. So to enable this functionaliy we use the following:
vim.o.undofile = true
vim.o.swapfile = false -- edit only one copy of the file, no swap file
5. Indenting & Tabs
Indenting wars have occured and were stopped by the use of coding standards. To set your indenting and spacing use the following code:
Setting tabstop, shiftwidth and expandtab will ensure that spaces is always inserted when the Tab key is pressed and the formatting will be ok.
-- Sets the number of spaces when the tab key is pressed when in insert mode(editing)
vim.o.expandtab = true
-- Sets the number of spaces when auto indenting
vim.o.shiftwidth = 2
-- Same as the expandtab option, needed to be set for expandtab to work properly
vim.o.softtabstop = 2
-- Set the number of spaces a tab keypress creates.
vim.o.tabstop = 2
-- Automatic Indent
vim.o.smartindent = true
6. Other Options
Here are other options which i use.
-- Have 8 lines at the bottom of the buffer always.
vim.o.scrolloff = 8
-- Options for splits relative to the current buffer
vim.o.splitright = true
vim.o.splitbelow = true
-- Mouse options to use the mouse when it is right-clicked.
vim.o.mouse = "a"
-- Default file encoding for my files.
vim.o.encoding = "UTF-8"
So with these options set we can now move on to adding plugins to our Neovim configuration.