Neovim — init.lua

Neovim + Lua = init.lua

Overview

What to Achieve

Neovim Setup with Lua LSP

Learn the Basics of Lua

vim.cmd [[packadd packer.nvim]]
vim.cmd 'autocmd BufWritePost plugins.lua PackerCompile'

NeoVim Lua Basics

Global, Buffer, and Window Scoped Options

lua-vim-options
Vim hidden Global Option

Lua-Vimscript Bridge

lua-vimscript

Lua Vim Variables

lua-vim-variables

Configure Startup Options

Leader Key

-- Map leader to space
vim.g.mapleader = ' '

utils Module

Settings

settings.lua
-- Map leader to space
vim.g.mapleader = ' '
local fn = vim.fn
local execute = vim.api.nvim_command
-- Sensible defaults
require('settings')

Configure Key Mappings

local utils = require('utils')utils.map('n', '<C-l>', '<cmd>noh<CR>') -- Clear highlights
utils.map('i', 'jk', '<Esc>') -- jk to escape
-- Key mappings
require('keymappings')

Configure Package Manager

Auto Install packer.nvim

-- Auto install packer.nvim if not exists
local install_path = fn.stdpath('data')..'/site/pack/packer/opt/packer.nvim'
if fn.empty(fn.glob(install_path)) > 0 then
execute('!git clone https://github.com/wbthomason/packer.nvim '..install_path)
end
vim.cmd [[packadd packer.nvim]]
vim.cmd 'autocmd BufWritePost plugins.lua PackerCompile' -- Auto compile when there are changes in plugins.lua

plugins.lua

Configure Plugins

telescope.nvim

" Find files using Telescope command-line sugar.
nnoremap <leader>ff <cmd>Telescope find_files<cr>
nnoremap <leader>fg <cmd>Telescope live_grep<cr>
nnoremap <leader>fb <cmd>Telescope buffers<cr>
nnoremap <leader>fh <cmd>Telescope help_tags<cr>
telescope.nvim

Lua LSP

Lua Language Server

LspInfo Screen
Lua LSP
Neovim Lua LSP

Color Scheme, Fugitive and Code Completion

local utils = require('utils')
local cmd = vim.cmd
utils.opt('o', 'termguicolors', true)
cmd 'colorscheme gruvbox-material'
local utils = require('utils')utils.opt('o', 'completeopt', 'menuone,noinsert,noselect')
vim.cmd [[set shortmess+=c]]
vim.g.completion_confirm_key = ""
vim.g.completion_matching_strategy_list = {'exact', 'substring', 'fuzzy'}
-- <Tab> to navigate the completion menu
utils.map('i', '<S-Tab>', 'pumvisible() ? "\\<C-p>" : "\\<Tab>"', {expr = true})
utils.map('i', '<Tab>', 'pumvisible() ? "\\<C-n>" : "\\<Tab>"', {expr = true})
local utils = require('utils')utils.map('n', '<Leader>gs', '<cmd>Gstatus<CR>')  -- Git status
require('config.colorscheme')
require('config.completion')
require('config.fugitive')
-- Another option is to groups configuration in one folder
require('config')
-- OR you can invoke them individually here
--require('config.colorscheme') -- color scheme
--require('config.completion') -- completion
--require('config.fugitive') -- fugitive
Main init.lua

Summary

References

Programmer and occasional blogger.

Get the Medium app

A button that says 'Download on the App Store', and if clicked it will lead you to the iOS App store
A button that says 'Get it on, Google Play', and if clicked it will lead you to the Google Play store