Configure Neovim - Options

Published on Feb 3, 2024

Configure Neovim - Options

Setting Default Options For Neovim

Now before we start loading plugins for Neovim, we must set default options like the line number’s, gutter size and other settings which can enable us customize Neovim to a degree. I will endeavour to explain the changes we make to the options and how it affects the Neovim editor. 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

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: In addition, the swap file is disabled to make sure that no temp copy of the file is saved when the editor quits unexpectedly.

vim.o.undofile = true
vim.o.swapfile = false -- disables the swap file, so when editing only one copy of the file is used at the same time 

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.

Author Information

aeon501
aeon501

Web Developer, Restless. My mind goes on epic voyages, then return back to reality. I write about things I have experienced in my coding journey.

View all posts
Advertisement
Ad placeholder
Sponsored
Ad 2