devenv/base/nvim/init.lua
2025-08-14 12:56:20 +10:00

240 lines
6.2 KiB
Lua

-- Bootstrap lazy.nvim if it's not installed
local lazypath = vim.fn.stdpath("data") .. "/lazy/lazy.nvim"
if not vim.loop.fs_stat(lazypath) then
vim.fn.system({
"git", "clone", "--filter=blob:none",
"https://github.com/folke/lazy.nvim", lazypath,
})
end
vim.opt.rtp:prepend(lazypath)
-- Plugin setup using lazy.nvim
require("lazy").setup({
{
"voldikss/vim-floaterm",
lazy = false,
},
{
"preservim/nerdtree",
lazy = false,
},
{
"junegunn/vim-easy-align",
lazy = false,
},
{'akinsho/toggleterm.nvim', version = "*", config = true},
{
"folke/tokyonight.nvim",
lazy = false, -- load immediately
priority = 1000, -- make sure it loads first
config = function()
require("tokyonight").setup({
style = "night",
transparent = true,
})
vim.cmd("colorscheme tokyonight")
end
},
{
"neovim/nvim-lspconfig",
config = function()
-- Basic on_attach function for keybindings
local on_attach = function(_, bufnr)
local opts = { noremap = true, silent = true, buffer = bufnr }
local keymap = vim.keymap.set
keymap("n", "gd", vim.lsp.buf.definition, opts)
keymap("n", "K", vim.lsp.buf.hover, opts)
keymap("n", "<leader>rn", vim.lsp.buf.rename, opts)
keymap("n", "<leader>ca", vim.lsp.buf.code_action, opts)
keymap("n", "gr", vim.lsp.buf.references, opts)
end
-- Basic LSP servers setup
local lspconfig = require("lspconfig")
-- Example: Python (pyright)
lspconfig.pyright.setup {
on_attach = on_attach,
}
-- Example: TypeScript/JavaScript (tsserver)
lspconfig.ts_ls.setup {
on_attach = on_attach,
}
-- Example: Lua (for Neovim config dev)
lspconfig.lua_ls.setup {
on_attach = on_attach,
settings = {
Lua = {
diagnostics = {
globals = { "vim" },
},
},
},
}
lspconfig.dockerls.setup {
on_attach = on_attach,
}
lspconfig.terraformls.setup {
on_attach = on_attach,
}
lspconfig.phpactor.setup {
on_attach = on_attach,
cmd = { "phpactor", "language-server" },
filetypes = { "php" },
root_dir = lspconfig.util.root_pattern("composer.json", ".git"),
}
end
},
{
"hrsh7th/nvim-cmp",
dependencies = {
"hrsh7th/cmp-nvim-lsp",
"hrsh7th/cmp-buffer",
"hrsh7th/cmp-path",
"L3MON4D3/LuaSnip", -- snippet engine
"saadparwaiz1/cmp_luasnip", -- snippet completions
},
config = function()
local cmp = require("cmp")
local luasnip = require("luasnip")
cmp.setup({
snippet = {
expand = function(args)
luasnip.lsp_expand(args.body)
end,
},
mapping = {
-- Confirm selection (only if one is explicitly selected)
['<CR>'] = cmp.mapping(function(fallback)
if cmp.visible() and cmp.get_selected_entry() then
cmp.confirm({ behavior = cmp.ConfirmBehavior.Replace, select = false })
else
fallback()
end
end, { 'i', 's' }),
-- Navigate the menu
['<Tab>'] = cmp.mapping(function(fallback)
if cmp.visible() then
cmp.select_next_item()
else
fallback()
end
end, { 'i', 's' }),
['<S-Tab>'] = cmp.mapping(function(fallback)
if cmp.visible() then
cmp.select_prev_item()
else
fallback()
end
end, { 'i', 's' }),
},
-- Avoid auto-selecting the first item
completion = {
completeopt = 'menu,menuone,noinsert',
},
sources = cmp.config.sources({
{ name = "nvim_lsp" },
{ name = "luasnip" },
{ name = "buffer" },
{ name = "path" },
}),
})
end
},
{
"williamboman/mason.nvim",
config = true
},
{
"williamboman/mason-lspconfig.nvim",
dependencies = { "mason.nvim", "neovim/nvim-lspconfig" },
config = function()
require("mason").setup()
require("mason-lspconfig").setup({
ensure_installed = { "lua_ls" }, -- this installs lua-language-server
})
end,
},
{
'lewis6991/gitsigns.nvim',
config = function()
require('gitsigns').setup({
current_line_blame = true,
current_line_blame_opts = {
delay = 300,
virt_text_pos = 'eol', -- 'eol' | 'overlay' | 'right_align'
},
current_line_blame_formatter = '<author>, <author_time:%Y-%m-%d> - <summary>',
})
end,
}
})
-- Set <leader> key
vim.g.mapleader = " "
-- Floaterm appearance (optional)
vim.g.floaterm_width = 0.9
vim.g.floaterm_height = 0.85
vim.g.floaterm_borderchars = '─│─│╭╮╯╰'
-- <leader>g: open Floaterm running lazygit
vim.keymap.set("n", "<leader>g", function()
vim.cmd("FloatermNew --name=lazygit --autoclose=2 lazygit")
end, { noremap = true, silent = true })
-- <C-t>: toggle NERDTree in current window
vim.keymap.set("n", "<C-t>", ":NERDTreeToggle<CR>", { noremap = true, silent = true })
-- EasyAlign key mappings
vim.keymap.set("x", "<leader>ga", ":EasyAlign<CR>", { noremap = true, silent = true })
vim.keymap.set("n", "ga", "<Plug>(EasyAlign)")
require("toggleterm").setup {
open_mapping = [[<C-\>]],
direction = "horizontal", -- or "float" or "vertical"
start_in_insert = true,
insert_mappings = true,
terminal_mappings = true,
close_on_exit = true,
shell = vim.o.shell -- use your default shell
}
-- Set 2 spaces and no tabs for Terraform files
vim.api.nvim_create_autocmd("FileType", {
pattern = "terraform",
callback = function()
vim.bo.expandtab = true -- use spaces instead of tabs
vim.bo.shiftwidth = 2 -- size of an indent
vim.bo.softtabstop = 2 -- number of spaces per <Tab>
end,
})
vim.opt.clipboard = "unnamedplus"
vim.opt.termguicolors = true
vim.opt.signcolumn = "yes"
vim.opt.number = true -- Enable absolute line numbers
vim.opt.relativenumber = false -- Disable relative line numbers
vim.opt.colorcolumn = "80"