Files
dotfiles/dot_config/nvim/init.lua
2025-07-23 00:26:25 -07:00

588 lines
16 KiB
Lua

-- -----------------------------------------------------------------------------
-- mini.nvim
-- -----------------------------------------------------------------------------
--
-- This Neovim configuration leans heavily on the mini.nvim ecosystem.
--
-- Installing mini.nvim and all its modules allows us to load each module with
-- a simple 'require('mini.module').setup()'. Using the mini.deps module allows
-- for adding plugins using the `MiniDeps.add()` function followed by the same
-- 'require('plugin').setup()'. Pass a config to setup to configure modules and
-- plugins, for example `require('plugin').setup.({config})`.
--
-- See `https://github.com/echasnovski/mini.nvim`
--
local path_package = vim.fn.stdpath('data') .. '/site'
local mini_path = path_package .. '/pack/deps/start/mini.nvim'
if not vim.loop.fs_stat(mini_path) then
vim.cmd('echo "Installing `mini.nvim`" | redraw')
local clone_cmd = {
'git', 'clone', '--filter=blob:none',
'https://github.com/echasnovski/mini.nvim', mini_path
}
vim.fn.system(clone_cmd)
vim.cmd('packadd mini.nvim | helptags ALL')
end
-- -----------------------------------------------------------------------------
-- mini.deps
-- -----------------------------------------------------------------------------
--
-- See `https://github.com/echasnovski/mini.deps`
--
local deps = require('mini.deps')
deps.setup()
-- -----------------------------------------------------------------------------
-- mini.ai
-- -----------------------------------------------------------------------------
--
-- See `https://github.com/echasnovski/mini.ai`
--
local ai = require('mini.ai')
ai.setup()
-- -----------------------------------------------------------------------------
-- mini.basics
-- -----------------------------------------------------------------------------
--
-- See `https://github.com/echasnovski/mini.basics`
--
local basics = require('mini.basics')
basics.setup()
-- -----------------------------------------------------------------------------
-- mini.completion
-- -----------------------------------------------------------------------------
--
-- See `https://github.com/echasnovski/mini.completion`
--
local completion = require('mini.completion')
completion.setup()
-- -----------------------------------------------------------------------------
-- mini.diff
-- -----------------------------------------------------------------------------
--
-- See `https://github.com/echasnovski/mini.diff`
--
local diff = require('mini.diff')
diff.setup()
-- -----------------------------------------------------------------------------
-- mini.git
-- -----------------------------------------------------------------------------
--
-- See `https://github.com/echasnovski/mini.git`
--
local git = require('mini.git')
git.setup()
-- -----------------------------------------------------------------------------
-- mini.hipatterns
-- -----------------------------------------------------------------------------
--
-- See `https://github.com/echasnovski/mini.hipatterns`
--
local hipatterns = require('mini.hipatterns')
hipatterns.setup({
highlighters = {
hex_color = hipatterns.gen_highlighter.hex_color(),
}
})
-- -----------------------------------------------------------------------------
-- mini.indentscope
-- -----------------------------------------------------------------------------
--
-- See `https://github.com/echasnovski/mini.indentscope`
--
local indentscope = require('mini.indentscope')
indentscope.setup()
-- -----------------------------------------------------------------------------
-- mini.pairs
-- -----------------------------------------------------------------------------
--
-- See `https://github.com/echasnovski/mini.pairs`
--
local pairs = require('mini.pairs')
pairs.setup()
-- -----------------------------------------------------------------------------
-- mini.surround
-- -----------------------------------------------------------------------------
--
-- See `https://github.com/echasnovski/mini.surround`
--
local surround = require('mini.surround')
surround.setup()
-- -----------------------------------------------------------------------------
-- mini.statusline
-- -----------------------------------------------------------------------------
--
-- See `https://github.com/echasnovski/mini.statusline`
--
local special_filetypes = {
'NvimTree',
'NeoTree',
'Trouble'
}
local function is_special_filetype(filetype)
for _, special_filetype in ipairs(special_filetypes) do
if filetype == special_filetype then
return true
end
end
return false
end
local function get_position_indicator()
local filetype = vim.bo.filetype
if is_special_filetype(filetype) then
return ""
end
local space_or_tab = vim.bo.expandtab and "S" or "T"
local shiftwidth = vim.bo.shiftwidth
local row, col = vim.fn.line('.'), vim.fn.col('.')
return space_or_tab .. shiftwidth .. ' ' .. string.format("%d:%d", row, col) .. ' '
end
local function get_filename()
local filetype = vim.bo.filetype
local symbol = vim.bo.readonly and " [-] " or (vim.bo.modified and " [+] " or "")
if filetype == '' then
return "[scratch]" .. symbol
elseif is_special_filetype(filetype) then
return filetype
else
return vim.fn.expand('%:.') .. symbol
end
end
-- Set up mini.statusline
require('mini.statusline').setup({
content = {
active = function()
local filetype = vim.bo.filetype
-- For special filetypes, return a simplified statusline
if is_special_filetype(filetype) then
return get_filename()
end
-- For regular files, construct the full statusline
return string.format(
' %s%s%s',
get_filename(), -- filename with modification symbol
'%=', -- middle spacing
get_position_indicator() -- position indicator
)
end,
inactive = function()
-- For inactive windows, show a simpler statusline
return string.format(
' %s%s%s',
get_filename(), -- filename with modification symbol
'%=', -- middle spacing
get_position_indicator() -- position indicator
)
end,
},
use_icons = true,
set_vim_settings = true,
})
-- -----------------------------------------------------------------------------
-- nvim-lspconfig
-- -----------------------------------------------------------------------------
--
-- See `https://github.com/neovim/nvim-lspconfig`
--
MiniDeps.add({
source = 'neovim/nvim-lspconfig',
})
vim.lsp.config('luals', {
cmd = {'lua-language-server'},
filetypes = {'lua'},
root_markers = {'.luarc.json', '.luarc.jsonc'},
settings = {
Lua = {
diagnostics = {
globals = {'vim', 'MiniDeps'}
}
}
}
})
vim.lsp.enable('luals')
vim.lsp.config('gopls', {
cmd = {'gopls'},
filetypes = {'go', 'gomod', 'gowork', 'gotmpl'},
root_markers = {'go.mod', '.git'},
settings = {
gopls = {
analyses = {
unusedparams = true,
},
staticcheck = true,
},
},
})
vim.lsp.enable('gopls')
-- -----------------------------------------------------------------------------
-- nvim-treesitter
-- -----------------------------------------------------------------------------
--
-- See `https://github.com/nvim-treesitter/nvim-treesitter`
--
MiniDeps.add({
source = 'nvim-treesitter/nvim-treesitter',
checkout = 'master',
monitor = 'main',
hooks = {
post_checkout = function()
vim.cmd('TSUpdate')
end
},
})
-- Add the custom Blade parser
local parser_config = require("nvim-treesitter.parsers").get_parser_configs()
parser_config.blade = {
install_info = {
url = "https://github.com/EmranMR/tree-sitter-blade", -- Community parser repo
files = { "src/parser.c" },
branch = "main",
},
filetype = "blade",
}
-- Treesitter setup
require('nvim-treesitter.configs').setup({
auto_install = true, -- Automatically install missing parsers
ensure_installed = {
'bash',
'c',
'c_sharp',
'css',
'csv',
'dockerfile',
'editorconfig',
'git_config',
'gitcommit',
'gitignore',
'go',
'graphql',
'html',
'javascript',
'jq',
'jsdoc',
'json',
'lua',
'luadoc',
'markdown',
'markdown_inline',
'nginx',
'php',
'phpdoc',
'python',
'query',
'ruby',
'rust',
'scss',
'sql',
'tmux',
'toml',
'typescript',
'vim',
'vimdoc',
'xml',
'yaml',
'blade', -- Add blade here
},
highlight = {
enable = true, -- Enable syntax highlighting
},
indent = {
enable = false, -- Disable indentation for now
},
})
-- Set filetype for Blade files
vim.cmd [[autocmd BufRead,BufNewFile *.blade.php set filetype=blade]]
-- -----------------------------------------------------------------------------
-- tmux.nvim
-- -----------------------------------------------------------------------------
--
-- See `https://github.com/aserowy/tmux.nvim`
--
MiniDeps.add({ source = 'aserowy/tmux.nvim' })
require('tmux').setup({})
-- Terminal Keymaps
vim.keymap.set("t", "<c-j>", "<c-\\><c-n><c-w>j", {noremap = true})
vim.keymap.set("t", "<c-h>", "<c-\\><c-n><c-w>h", {noremap = true})
vim.keymap.set("t", "<c-k>", "<c-\\><c-n><c-w>k", {noremap = true})
vim.keymap.set("t", "<c-l>", "<c-\\><c-n><c-w>l", {noremap = true})
-- -----------------------------------------------------------------------------
-- Oil
-- -----------------------------------------------------------------------------
--
-- See `https://github.com/stevearc/oil.nvim`
--
MiniDeps.add({ source = 'stevearc/oil.nvim' })
require('oil').setup({
skip_confirm_for_simple_edits = true,
prompt_save_on_select_new_entry = false,
delete_to_trash = true,
confirmation = {
border = "double",
},
view_options = {
show_hidden = true,
sort = {
{
"name", "asc"
},
},
}
})
vim.keymap.set("n", "-", "<CMD>Oil<CR>", { desc = "Open parent directory" })
-- -----------------------------------------------------------------------------
-- Neogit
-- -----------------------------------------------------------------------------
--
-- See `https://github.com/NeogitOrg/neogit`
--
MiniDeps.add({ source = 'nvim-lua/plenary.nvim' })
MiniDeps.add({ source = 'NeogitOrg/neogit' })
require('neogit').setup({
integrations = {
fzf_lua = true, -- Use your existing fzf-lua
},
})
-- -----------------------------------------------------------------------------
-- FZF Lua
-- -----------------------------------------------------------------------------
--
-- See `https://github.com/ibhagwan/fzf-lua`
--
MiniDeps.add({
source = 'ibhagwan/fzf-lua'
})
require('fzf-lua').setup({
fzf_bin = 'fzf', -- Use system fzf (not embedded)
-- Make it fill the screen like terminal fzf
winopts = {
height = 1.0, -- Full height
width = 1.0, -- Full width
row = 0, -- Top of screen
col = 0, -- Left of screen
border = 'none', -- No border (like terminal)
preview = {
border = 'double',
title = false, -- Remove the preview title
title_pos = false,
}
},
-- Let fzf handle the layout/preview like in terminal
fzf_opts = {
-- Remove fzf-lua's default overrides to use your terminal config
['--height'] = false, -- Don't override height
['--layout'] = false, -- Don't override layout
['--border'] = false, -- Don't override border
['--info'] = false, -- Don't override info position
},
-- Ensure previews work like your terminal setup
files = {
-- preview_opts = 'hidden', -- Let fzf handle preview
},
})
vim.keymap.set("n", "<leader>f", "<cmd>FzfLua files<cr>", { desc = "Search Files" })
vim.keymap.set("n", "<leader>o", "<cmd>FzfLua oldfiles<cr>", { desc = "List Recent Files" })
vim.keymap.set("n", "<leader>b", "<cmd>FzfLua buffers<cr>", { desc = "List Buffers" })
vim.keymap.set("n", "<leader>g", "<cmd>FzfLua live_grep<cr>", { desc = "List Matched Strings" })
vim.keymap.set("n", "<leader>d", "<cmd>FzfLua lsp_diagnostics<cr>", { desc = "List Diagnostics" })
-- -----------------------------------------------------------------------------
-- VimWiki
-- -----------------------------------------------------------------------------
--
--
--
-- MiniDeps.add({
-- source = 'vimwiki/vimwiki'
-- })
--
-- require('vimwiki').setup()
-- -----------------------------------------------------------------------------
-- Set Colorscheme
-- -----------------------------------------------------------------------------
--
-- Use the custom colorscheme at `nvim/colors/lpcstudio`
--
vim.cmd 'colorscheme lpcstudio'
-- -----------------------------------------------------------------------------
-- Disable swapfile
-- -----------------------------------------------------------------------------
--
-- The swapfiles seem unneeded with my local development environment. Crashes
-- are rare, and the files are combersome.
--
vim.opt.swapfile = false
-- -----------------------------------------------------------------------------
-- Show the mode in the command line
-- -----------------------------------------------------------------------------
--
-- I like seeing the mode in the bottom left and not following me around.
-- I generally know what mode I'm in and don't need a vibrant hint.
--
vim.opt.showmode = true
-- -----------------------------------------------------------------------------
-- Make cursor blink
-- -----------------------------------------------------------------------------
--
-- Sometimes on a big monitor I have trouble finding cursors. This helps.
--
vim.cmd [[ set guicursor+=a:blinkon1 ]]
-- -----------------------------------------------------------------------------
-- Automatically resize windows
-- -----------------------------------------------------------------------------
--
--
vim.api.nvim_create_autocmd("VimResized", {
command = "wincmd =",
})
-- -----------------------------------------------------------------------------
-- Default Spacing
-- -----------------------------------------------------------------------------
--
--
--
local space = 4
vim.opt.shiftwidth = space
vim.opt.tabstop = space
vim.opt.softtabstop = space
vim.opt.expandtab = true
vim.opt.shiftround = true
-- -----------------------------------------------------------------------------
-- Keymaps
-- -----------------------------------------------------------------------------
--
--
--
vim.keymap.set('i', '<F15>', '<C-o>o', { noremap = true, silent = true, desc = "Open new line below (Shift+Enter)" })
-- -----------------------------------------------------------------------------
-- Open Help buffers to the right
-- -----------------------------------------------------------------------------
--
--
vim.api.nvim_create_autocmd("FileType", {
desc = "Automatically Split help Buffers to the right",
pattern = "help",
command = "wincmd L",
})
-- -----------------------------------------------------------------------------
-- Search highlight remove on cursor move
-- -----------------------------------------------------------------------------
--
--
local function augroup(name, fnc)
fnc(vim.api.nvim_create_augroup(name, { clear = true }))
end
augroup("ibhagwan/ToggleSearchHL", function(g)
vim.api.nvim_create_autocmd("InsertEnter", {
group = g,
callback = function()
vim.schedule(function() vim.cmd("nohlsearch") end)
end
})
vim.api.nvim_create_autocmd("CursorMoved", {
group = g,
callback = function()
local view, rpos = vim.fn.winsaveview(), vim.fn.getpos(".")
vim.cmd(string.format("silent! keepjumps go%s",
(vim.fn.line2byte(view.lnum) + view.col + 1 - (vim.v.searchforward == 1 and 2 or 0))))
local ok, _ = pcall(vim.cmd, "silent! keepjumps norm! n")
local insearch = ok and (function()
local npos = vim.fn.getpos(".")
return npos[2] == rpos[2] and npos[3] == rpos[3]
end)()
vim.fn.winrestview(view)
if not insearch then
vim.schedule(function() vim.cmd("nohlsearch") end)
end
end
})
end)