Skip to content

Instantly share code, notes, and snippets.

@elpddev
Last active March 30, 2025 14:18
Show Gist options
  • Save elpddev/4e5b13d0376a38fcd7fb9c57a35c86fb to your computer and use it in GitHub Desktop.
Save elpddev/4e5b13d0376a38fcd7fb9c57a35c86fb to your computer and use it in GitHub Desktop.
Neovim Setup from Scratch (Based on ThePrimeagen)

WIP

This is based on 0 to LSP : Neovim RC From Scratch by ThePrimeagen. Go check it out, big like and subscribe!

This is a learning by doing hands-on writeup. I suggest doing a writeup on your own if you have the time for it.

Steps

Clean Previous Installation

rm -rf ~/.config/nvim
rm -rf ~/.local/share/nvim
rm -rf ~/.local/state/nvim

Create the Config Folder

mkdir ~/.config/nvim

Create the Init file

Enter nvim with netrw activated:

nvim ./

Without the path as argument, netrw does not launch. You can launch it manuall by :Ex (Explore) command.

Create the init.loa file

%
Eneter filename: init.lua

Create the lua Directory

Any directory in the lua directory is required by lua on start.

Launch the directory creator:

d

Enter the directory name:

Please give directory name: lua

Create the Custom Directory

Using netrw or vim external shell running command:

:! mkdir ~/.config/nvim/lua/custom

Create the cusotm init script

:e ~/.config/nvim/lua/custom/init.lua

Require custom script from main script

In the main init.lua

require("custom")

Map netrw to keys shortcut

Instead of entering :Ex to open netrw file explorer each time, we want to map a keyshortcut for it.

Create a file remap.lua using %

Enter filename; `rempal.lua`

In custom/loa/rempa.lua, insert the mapping code:

vim.g.mapleader = " "
vim.keymap.set("n",  "<leader>pv", vim.cmd.Ex)

Require the remap.lua from the init script:

require("custom.remap")

Install Packer Vim Package Manager

Go to packer.nvim

Install using the script:

git clone --depth 1 https://github.com/wbthomason/packer.nvim\
 ~/.local/share/nvim/site/pack/packer/start/packer.nvim

Create a packer.lua file fot storing it's coniguration logic:

:e ~/.config/nvim/lua/custom/packer.lua

Copy the first lines from the README and paste them in the config with closing the function also:

-- This file can be loaded by calling `lua require('plugins')` from your init.vim

-- Only required if you have packer configured as `opt`
vim.cmd [[packadd packer.nvim]]

return require('packer').startup(function(use)
  -- Packer can manage itself
  use 'wbthomason/packer.nvim'
end)

Require packer.lua from the init file:

require("custom.packer")

Exit and start vim again.

Install telescope as Fazzy Finder Plugin

Go to telecope github website and copy the installation code for packer.

Edit the packer.lua config to add the telescope installation:

return require('packer').startup(function(use)
  -- Packer can manage itself
  use 'wbthomason/packer.nvim'
  
  use {
	  'nvim-telescope/telescope.nvim', tag = '0.1.2',
  }
end)

Source the config file:

:so

Install the new package:

:PackerSync

Create a new config file for telescope at ~/.config/nvim/lua/after/plugin/telescope.lua.

Remember, in netrw

  • % - Create file
  • d - Create directory

Add the lua config lines (part of them) to the telescope.lua config file:

local builtin = require('telescope.builtin')
vim.keymap.set('n', '<leader>pf', builtin.find_files, {})

Add search for within a git repo (that respect .gitignore config):

vim.keymap.set('n', '<C-p>', builtin.git_files, {})

Add config for search files containing a desired string:

vim.keymap.set('n', '<leader>ps', function()
	builtin.grep_string({ search = vim.fn.input("Grep > ") })
end)

Resoure (:so) but we get an error. It seems telescope needs plenary package as a dependency.

Install plenary package by adding it to the packer.lua file:

return require('packer').startup(function(use)
  -- Packer can manage itself
  use 'wbthomason/packer.nvim'

  use {
	 'nvim-telescope/telescope.nvim', tag = '0.1.2',
  }

  use "nvim-lua/plenary.nvim"
end)

If the grep not working but without error, you need to install the dependency ripgrep

Examples:

Arch:

$ sudo pacman -S ripgrep

Ubuntu:

$ curl -LO https://github.com/BurntSushi/ripgrep/releases/download/13.0.0/ripgrep_13.0.0_amd64.deb
$ sudo dpkg -i ripgrep_13.0.0_amd64.deb

Setup Color Scheme

Install the rose-pine neovim plugin.

use({ 'rose-pine/neovim', as = 'rose-pine' })

vim.cmd('colorscheme rose-pine')

Source :so and install :PackerSync.

To update the background to be transparent again, Create a config file for the colors after/plugin/colors.lua.

Edit the colors.lua file:

function ColorMyPencils(color)
	color = color or "rose-pine"
	vim.cmd.colorscheme(color)

	vim.api.nvim_set_hl(0, "Normal",  { bg = "none" })
	vim.api.nvim_set_hl(0, "NormalFloat", { bg = "none" })
end

ColorMyPencils()

Source :so again.

We want to color also by language tokens and parsing. We install treesitter

Edit the packer.lua file and add treesitter installation:

  use {
        'nvim-treesitter/nvim-treesitter',
        run = ':TSUpdate'
  }

Add a config file for treesitter in after/plugin/treesitter.lua.

Add the config from the nvim treesitter readme and some custom config.

  1. "help" was changed to vimdoc
  2. Markout the unnessery disable config
require'nvim-treesitter.configs'.setup {
  -- A list of parser names, or "all" (the five listed parsers should always be installed)
  ensure_installed = { "vimdoc", "javascript", "typescript", "c", "lua", "vim", "vimdoc", "query" },

  -- Install parsers synchronously (only applied to `ensure_installed`)
  sync_install = false,

  -- Automatically install missing parsers when entering buffer
  -- Recommendation: set to false if you don't have `tree-sitter` CLI installed locally
  auto_install = true,

  -- List of parsers to ignore installing (for "all")
  -- ignore_install = { "javascript" },

  ---- If you need to change the installation directory of the parsers (see -> Advanced Setup)
  -- parser_install_dir = "/some/path/to/store/parsers", -- Remember to run vim.opt.runtimepath:append("/some/path/to/store/parsers")!

  highlight = {
    enable = true,

    -- NOTE: these are the names of the parsers and not the filetype. (for example if you want to
    -- disable highlighting for the `tex` filetype, you need to include `latex` in this list as this is
    -- the name of the parser)
    -- list of language that will be disabled
    --- disable = { "c", "rust" },
    -- Or use a function for more flexibility, e.g. to disable slow treesitter highlight for large files
    ---disable = function(lang, buf)
    ---    local max_filesize = 100 * 1024 -- 100 KB
    ---    local ok, stats = pcall(vim.loop.fs_stat, vim.api.nvim_buf_get_name(buf))
    ---    if ok and stats and stats.size > max_filesize then
    ---        return true
    ---    end
    ---end,

    -- Setting this to true will run `:h syntax` and tree-sitter at the same time.
    -- Set this to `true` if you depend on 'syntax' being enabled (like for indentation).
    -- Using this option may slow down your editor, and you may see some duplicate highlights.
    -- Instead of true it can also be a list of languages
    additional_vim_regex_highlighting = false,
  },
}

Source :so.

Helpers

Get NVim Lookup Paths

In vim, popup the help for Real Time Paths:

:h rtp
				*'runtimepath'* *'rtp'* *vimfiles*
'runtimepath' 'rtp'	string	(default:     "$XDG_CONFIG_HOME/nvim,
					       $XDG_CONFIG_DIRS[1]/nvim,
					       $XDG_CONFIG_DIRS[2]/nvim,
					       …
					       $XDG_DATA_HOME/nvim[-data]/site,
					       $XDG_DATA_DIRS[1]/nvim/site,
					       $XDG_DATA_DIRS[2]/nvim/site,
					       …
					       $VIMRUNTIME,
					       …
					       $XDG_DATA_DIRS[2]/nvim/site/after,
					       $XDG_DATA_DIRS[1]/nvim/site/after,
					       $XDG_DATA_HOME/nvim[-data]/site/after,
					       …
					       $XDG_CONFIG_DIRS[2]/nvim/after,
					       $XDG_CONFIG_DIRS[1]/nvim/after,
					       $XDG_CONFIG_HOME/nvim/after")

Netrw Cheatsheet

  • '%' - Create a file
  • 'd' - Create a directory

Helper text:

					*netrw-newfile* *netrw-createfile*
OPEN A NEW FILE IN NETRW'S CURRENT DIRECTORY		*netrw-%* {{{2

To open a new file in netrw's current directory, press "%".  This map
will query the user for a new filename; an empty file by that name will
be placed in the netrw's current directory (ie. b:netrw_curdir).

If Lexplore (|netrw-:Lexplore|) is in use, the new file will be generated
in the |g:netrw_chgwin| window.

Related topics:               |netrw-d|

Vim Cheetsheet

  • :so - Source vim config files (like sourcing .bashrc after changing it)
  • :e filepath - Open file for editing in the buffer

Help for so

					*:so* *:source* *load-vim-script*
:[range]so[urce] [file]	Runs |Ex| commands or Lua code (".lua" files) from
			[file], or current buffer if no [file].
			Triggers the |SourcePre| autocommand.

Packer Cheetsheet

  • :PackerSync - Install all new packages specified in the config and update existing ones.
@swickrotation
Copy link

Hey,

I read through this guide while working on my own nvim config- I made a couple corrections of some typos in this document. You can see them here. Have a look if you like. Would make it a PR but gists doesn't allow those?

Anyway, the file is largely unchanged but slight improvement in clarity.

https://gist.github.com/swickrotation/2da780b9e463f09e34882a0e60e33cf9

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment