Home NeoVim Installation and Plugins using lua
Post
Cancel

NeoVim Installation and Plugins using lua

Neovim is a hyperextensible, highly customizable text editor that has gained immense popularity among developers for its modern features and enhanced performance over the classic Vim. Whether you’re a seasoned Vim user looking to make the switch or a newcomer eager to delve into efficient code editing, this post will walk you through everything you need to get started. This guide is part of my personal documentation, and all the plugins discussed are configured using Lua. You’ll learn how to install Neovim on various operating systems and tailor it to suit your workflow, making your coding experience more productive and enjoyable.

Installing Neovim

  1. Update and upgrade your system:
    1
    2
    
    sudo apt update && sudo apt upgrade -y
    sudo apt install curl wget make unzip tree gcc git -y
    
  2. Download and install Neovim:
    1
    2
    3
    4
    
    cd /tmp
    curl -LO https://github.com/neovim/neovim/releases/latest/download/nvim.appimage
    chmod u+x nvim.appimage
    ./nvim.appimage
    

    If the above command fails, try:

    1
    2
    
    ./nvim.appimage --appimage-extract
    ./squashfs-root/AppRun --version
    
  3. (Optional) Expose Neovim globally:
    1
    2
    
    sudo mv squashfs-root /
    sudo ln -s /squashfs-root/AppRun /usr/bin/nvim
    

    If you encounter errors due to an existing file:

    1
    2
    
    sudo rm /usr/bin/nvim
    sudo ln -s /squashfs-root/AppRun /usr/bin/nvim
    
  4. Verify the installation:
    1
    
    nvim
    

Setting Up Neovim

  1. Create the Neovim configuration directory:
    1
    
    mkdir -p ~/.config/nvim
    
  2. Create the initial configuration file:
    1
    
    touch ~/.config/nvim/init.lua
    
  3. Create plugins directory:
    1
    
    mkdir -p ~/.config/nvim/lua/core
    

    Setting keymaps

  4. Create the Neovim keymaps file
    1
    
    nvim ~/.config/nvim/lua/core/keymaps.lua
    

    keymaps.lua:

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
vim.g.mapleader = ' '
vim.g.maplocalleader = ' '

vim.opt.autoindent = true
vim.opt.smarttab = true
vim.opt.backspace = '2'
vim.opt.showcmd = true
vim.opt.laststatus = 2
vim.opt.autowrite = true
vim.opt.relativenumber = true
vim.opt.cursorline = true
vim.opt.autoread = true

-- use spaces for tabs and whatnot
vim.opt.tabstop = 2
vim.opt.shiftwidth = 2
vim.opt.softtabstop = 2
vim.opt.shiftround = true
vim.opt.expandtab = true

Installing Packer Package Manager

  1. Install Packer using the bootstrapping method. Create the file
    1
    
    nvim ~/.config/nvim/lua/core/plugins.lua
    

    plugins.lua

    1
    2
    3
    4
    5
    6
    7
    8
    9
    10
    11
    12
    13
    14
    15
    16
    17
    18
    19
    20
    21
    
    local ensure_packer = function()
      local fn = vim.fn
      local install_path = fn.stdpath('data')..'/site/pack/packer/start/packer.nvim'
      if fn.empty(fn.glob(install_path)) > 0 then
        fn.system({'git', 'clone', '--depth', '1', 'https://github.com/wbthomason/packer.nvim', install_path})
        vim.cmd [[packadd packer.nvim]]
        return true
      end
      return false
    end
    
    local packer_bootstrap = ensure_packer()
    
    return require('packer').startup(function(use)
      use 'wbthomason/packer.nvim'
      -- Add your plugins here
         
      if packer_bootstrap then
        require('packer').sync()
      end
    end)
    
  2. Update your init.lua
    1
    
    nvim ~/.config/nvim/init.lua
    

    init.lua

    1
    2
    
    require("core.keymaps")
    require("core.plugins")
    
  3. Restart Neovim and run :PackerSync to install Packer.

Installing and Configuring Plugins

  1. Add the following plugins to plugins.lua
    1
    
    nvim ~/.config/nvim/lua/core/plugins.lua
    

    plugins.lua

    1
    2
    3
    4
    5
    6
    7
    8
    9
    10
    11
    
      -- Add your plugins here
      use 'ellisonleao/gruvbox.nvim'
      use 'nvim-tree/nvim-tree.lua'
      use 'nvim-tree/nvim-web-devicons'
      use 'nvim-lualine/lualine.nvim'
      use 'nvim-treesitter/nvim-treesitter'
      use {
          "nvim-telescope/telescope.nvim",
          tag = "0.1.4",
          requires = { "nvim-lua/plenary.nvim" }
         }
    
  2. Create a directory for plugin configurations:
    1
    
    mkdir -p ~/.config/nvim/lua/core/plugin_config
    
  3. Create configuration files for each plugin:
    1
    
    touch ~/.config/nvim/lua/core/plugin_config/{gruvbox,nvim-tree,lualine,telescope,treesitter}.lua
    
  4. Configure each plugin:
    1
    
    cd ~/.config/nvim/lua/core/plugin_config/
    
    • gruvbox.lua:
      1
      2
      
      vim.o.termguicolors = true
      vim.cmd [[ colorscheme gruvbox]]
      
    • lualine.lua:
      1
      2
      3
      4
      5
      6
      7
      8
      9
      10
      11
      12
      13
      14
      
      require('lualine').setup {
      options = {
       icons_enabled = true,
       theme = 'gruvbox',
      },
      sections = {
       lualine_a = {
       {
       'filename',
       path = 1,
       }
       }
      }
      }
      
    • nvim-tree.lua:
      1
      2
      3
      4
      
      vim.g.loaded_netrw = 1
      vim.g.loaded_netrwPlugin = 1
      require("nvim-tree").setup()
      vim.keymap.set('n', '<c-n>', ':NvimTreeFindFile<CR>')
      
    • telescope.lua:
      1
      2
      3
      4
      5
      
      local builtin = require('telescope.builtin')
      vim.keymap.set('n', '<c-p>', builtin.find_files, {})
      vim.keymap.set('n', '<Space><Space>', builtin.oldfiles, {})
      vim.keymap.set('n', '<Space>fg', builtin.live_grep, {})
      vim.keymap.set('n', '<Space>fh', builtin.help_tags, {})
      
    • treesitter.lua:
      1
      2
      3
      4
      5
      6
      7
      8
      9
      10
      11
      
      require'nvim-treesitter.configs'.setup {
      ensure_installed = { "c", "lua", "markdown", "python", "vim", "dockerfile", "bash"},
      sync_install = false,
      auto_install = true,
      highlight = {
       enable = true,
       },
      indent = {
       enable = true,
       },
      }
      
  5. Create:
    1
    
    nvim ~/.config/nvim/lua/core/plugin_config/init.lua
    

    init.lua

    1
    2
    3
    4
    5
    
    require("core.plugin_config.gruvbox")
    require("core.plugin_config.lualine")
    require("core.plugin_config.nvim-tree")
    require("core.plugin_config.telescope")
    require("core.plugin_config.treesitter")
    
  6. Update your main ~/.config/nvim/init.lua:
    1
    2
    3
    
    require("core.keymaps")
    require("core.plugins")
    require("core.plugin_config")
    
  7. Restart Neovim and run :PackerSync to install and configure all plugins.

Plugin Descriptions

  • packer.nvim: A package manager for Neovim.
  • gruvbox.nvim: A warm, retro-style color scheme.
  • nvim-tree.lua: A file explorer tree for easy project navigation.
  • nvim-web-devicons: Adds filetype icons to enhance visual identification.
  • lualine.nvim: A fast and customizable statusline.
  • nvim-treesitter: Provides better syntax highlighting and code understanding.
  • telescope.nvim: A highly extendable fuzzy finder over lists.
This post is licensed under CC BY 4.0 by the author.
Contents