My Neovim Development Environment
How init.vim and init.lua Work
The init.vim file serves as the entry point for Neovim, where we load the Lua configuration. It contains the following line:
vimluafile ~/.config/nvim/lua/init.lua
This command loads the init.lua file, which in turn requires the necessary modules, including:
luarequire("remap")
This structure allows for a clean separation of configuration and functionality, making it easier to manage and update.
Overview
After transitioning from VSCode, I've built a powerful Neovim setup that provides a fast, keyboard-centric development environment. This configuration focuses on Lua-based plugins and modern development features while maintaining Vim's core efficiency.
Directory Structure
My Neovim configuration follows a modular structure for better organization:
.
├── after/
│ └── plugin/
│ ├── colors.lua
│ ├── fugitive.lua
│ ├── harpoon.lua
│ ├── lsp.lua
│ ├── telescope.lua
│ ├── treesitter.lua
│ └── undotree.lua
├── lua/
│ ├── init.lua
│ ├── packermanager.lua
│ └── remap.lua
├── plugin/
│ └── packer_compiled.lua
└── init.vim
Plugin Configurations
Each plugin has its own configuration file in after/plugin/
for better organization and maintainability:
colors.lua
Custom color scheme configuration:
luafunction 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()
fugitive.lua
Git integration setup:
luavim.keymap.set("n", "<leader>gs", vim.cmd.Git)
harpoon.lua
Quick file navigation configuration:
lualocal mark = require("harpoon.mark")
local ui = require("harpoon.ui")
vim.keymap.set("n", "<leader>a", mark.add_file)
vim.keymap.set("n", "<C-e>", ui.toggle_quick_menu)
vim.keymap.set("n", "<C-h>", function() ui.nav_file(1) end)
vim.keymap.set("n", "<C-t>", function() ui.nav_file(2) end)
vim.keymap.set("n", "<C-n>", function() ui.nav_file(3) end)
vim.keymap.set("n", "<C-s>", function() ui.nav_file(4) end)
lsp.lua
Language Server Protocol configuration:
lualocal lsp_zero = require('lsp-zero')
lsp_zero.on_attach(function(client, bufnr)
lsp_zero.default_keymaps({buffer = bufnr})
end)
require('mason').setup({})
require('mason-lspconfig').setup({
ensure_installed = {'lua_ls', 'clangd', 'cssls', 'html', 'jdtls', 'pyright'},
handlers = {
function(server_name)
require('lspconfig')[server_name].setup({})
end,
},
})
-- Language-specific configurations
local function setup_lua_ls()
require('lspconfig').lua_ls.setup({
settings = {
Lua = {
runtime = { version = 'LuaJIT' },
diagnostics = { globals = { 'vim' } },
workspace = {
library = vim.api.nvim_get_runtime_file("", true),
checkThirdParty = false,
},
},
},
})
end
setup_lua_ls()
telescope.lua
Fuzzy finder configuration:
lualocal builtin = require('telescope.builtin')
vim.keymap.set('n', '<leader>pf', builtin.find_files, {})
vim.keymap.set('n', '<C-p>', builtin.git_files, {})
vim.keymap.set('n', '<leader>ps', function()
builtin.grep_string({ search = vim.fn.input("Grep > ") })
end)
treesitter.lua
Syntax highlighting configuration:
luarequire'nvim-treesitter.configs'.setup { ensure_installed = { "javascript", "c", "lua", "rust", "vim", "vimdoc", "query", "java" }, sync_install = false, auto_install = true, highlight = { enable = true, additional_vim_regex_highlighting = false, }, }
undotree.lua
Version history visualization:
luavim.keymap.set("n", "<leader>u", vim.cmd.UndotreeToggle)
Conclusion
This setup provides a modern development environment while maintaining Vim's speed and efficiency. The configuration is constantly evolving as I discover new plugins and optimization opportunities.
The complete configuration is available on GitHub
I also referenced a helpful YouTube video by ThePrimeagen for this setup: Watch here