Neovim rework.
Consolidated modules into a single file. Added syntax files over using treesitter.
This commit is contained in:
+154
-4
@@ -2,6 +2,7 @@ require("vim._core.ui2").enable({})
|
||||
map = vim.keymap.set
|
||||
vim.g.mapleader = " "
|
||||
vim.g.termguicolors = true
|
||||
|
||||
-- mini.basics sets defaults see plugin folder for more
|
||||
vim.o.swapfile = false
|
||||
vim.o.winborder = "single"
|
||||
@@ -15,11 +16,12 @@ vim.o.path = "**"
|
||||
vim.o.clipboard = "unnamedplus"
|
||||
vim.o.foldmethod = "expr"
|
||||
vim.o.foldlevel = 99
|
||||
vim.o.foldexpr = "v:lua.vim.treesitter.foldexpr()"
|
||||
vim.o.completeopt = "menuone,noselect,fuzzy,nosort"
|
||||
vim.opt.shortmess:append("c")
|
||||
vim.o.undodir = os.getenv("HOME") .. "/.cache/nvim/undodir"
|
||||
|
||||
-- @BINDS
|
||||
-- -----------------------------
|
||||
map("t", "<ESC><ESC>", "<C-\\><C-n>")
|
||||
map({"t", "n"}, "<C-h>", "<C-\\><C-n><C-w><C-h>")
|
||||
map({"t", "n"}, "<C-j>", "<C-\\><C-n><C-w><C-j>")
|
||||
@@ -35,6 +37,154 @@ map("n", "<leader>l", ":b#<CR>")
|
||||
map("n", "<leader>e", ":Ex<CR>")
|
||||
map("n", "<leader>x", ":bd<CR>")
|
||||
|
||||
require("autocmds")
|
||||
require("terminal")
|
||||
require("plugins")
|
||||
-- @AUTOCMDS
|
||||
-- -----------------------------
|
||||
-- Terminals should open with insert mode
|
||||
vim.api.nvim_create_autocmd({ "BufEnter", "TermEnter", "WinEnter" }, {
|
||||
pattern = "term://*",
|
||||
callback = function()
|
||||
if vim.bo.buftype == "terminal" then
|
||||
vim.schedule(function()
|
||||
vim.cmd("startinsert")
|
||||
end)
|
||||
end
|
||||
end
|
||||
})
|
||||
|
||||
-- highlights yanked text
|
||||
vim.api.nvim_create_autocmd("TextYankPost", {
|
||||
callback = function()
|
||||
vim.highlight.on_yank({
|
||||
higroup = "IncSearch",
|
||||
timeout = 200,
|
||||
})
|
||||
end,
|
||||
})
|
||||
|
||||
-- removes trailing whitespace on save
|
||||
vim.api.nvim_create_autocmd("BufWritePre", {
|
||||
callback = function()
|
||||
local save_cursor = vim.fn.getpos(".")
|
||||
vim.cmd([[%s/\s\+$//e]])
|
||||
vim.fn.setpos(".", save_cursor)
|
||||
end,
|
||||
})
|
||||
|
||||
-- @TERMINAL
|
||||
-- -----------------------------
|
||||
local term_buf = nil
|
||||
|
||||
local function open_term_split()
|
||||
vim.cmd('botright vsplit')
|
||||
local win = vim.api.nvim_get_current_win()
|
||||
if term_buf and vim.api.nvim_buf_is_valid(term_buf) then
|
||||
vim.api.nvim_win_set_buf(win, term_buf)
|
||||
else
|
||||
vim.cmd('terminal')
|
||||
term_buf = vim.api.nvim_get_current_buf()
|
||||
end
|
||||
vim.api.nvim_win_set_width(win, math.floor(vim.o.columns * 0.37))
|
||||
vim.cmd('startinsert')
|
||||
end
|
||||
|
||||
local function toggle_term()
|
||||
-- Check if terminal is already visible in a window
|
||||
for _, win in ipairs(vim.api.nvim_list_wins()) do
|
||||
if vim.api.nvim_win_get_buf(win) == term_buf then
|
||||
vim.api.nvim_win_close(win, false)
|
||||
return
|
||||
end
|
||||
end
|
||||
open_term_split()
|
||||
end
|
||||
|
||||
local function open_term_fullscreen()
|
||||
if term_buf and vim.api.nvim_buf_is_valid(term_buf) then
|
||||
vim.api.nvim_set_current_buf(term_buf)
|
||||
else
|
||||
vim.cmd('terminal')
|
||||
term_buf = vim.api.nvim_get_current_buf()
|
||||
end
|
||||
vim.cmd('startinsert')
|
||||
end
|
||||
|
||||
local function prev_non_term_buf()
|
||||
local cur = vim.api.nvim_get_current_buf()
|
||||
local bufs = vim.fn.getbufinfo({ buflisted = 1 })
|
||||
local candidates = {}
|
||||
for _, info in ipairs(bufs) do
|
||||
if info.bufnr ~= cur and vim.bo[info.bufnr].buftype ~= 'terminal' then
|
||||
table.insert(candidates, info)
|
||||
end
|
||||
end
|
||||
if #candidates == 0 then
|
||||
print('No previous non-terminal buffer')
|
||||
return
|
||||
end
|
||||
table.sort(candidates, function(a, b) return a.lastused > b.lastused end)
|
||||
vim.api.nvim_set_current_buf(candidates[1].bufnr)
|
||||
end
|
||||
|
||||
map('n', '<leader>l', prev_non_term_buf, { desc = 'Go to previous non-terminal buffer' })
|
||||
map('n', '<C-j>', toggle_term, { desc = 'Toggle terminal split' })
|
||||
map('n', '<C-o>', open_term_fullscreen, { desc = 'Open terminal fullscreen' })
|
||||
map('t', '<C-j>', toggle_term, { desc = 'Toggle terminal split' })
|
||||
map('t', '<C-o>', prev_non_term_buf, { desc = 'Exit terminal mode' })
|
||||
|
||||
-- @PLUGINS
|
||||
-- -----------------------------
|
||||
vim.pack.add({
|
||||
{ src = 'https://github.com/nvim-mini/mini.nvim' },
|
||||
{ src = 'https://github.com/neovim/nvim-lspconfig' },
|
||||
{ src = 'https://github.com/metalelf0/kintsugi-nvim' },
|
||||
{ src = 'https://github.com/xiyaowong/transparent.nvim' },
|
||||
{ src = 'https://github.com/brenoprata10/nvim-highlight-colors' }
|
||||
})
|
||||
|
||||
-- { src = 'https://github.com/romus204/tree-sitter-manager.nvim' },
|
||||
-- require('tree-sitter-manager').setup()
|
||||
require('nvim-highlight-colors').setup()
|
||||
-- Mini setups
|
||||
require('mini.extra').setup()
|
||||
require('mini.pairs').setup()
|
||||
require('mini.files').setup()
|
||||
require('mini.surround').setup()
|
||||
require('mini.sessions').setup()
|
||||
require('mini.statusline').setup()
|
||||
require('mini.basics').setup({options = { extra_ui = true }})
|
||||
require('mini.completion').setup({lsp_completion = { auto_setup = true }})
|
||||
require('mini.pick').setup({
|
||||
window = {
|
||||
config = function()
|
||||
local height = math.floor(0.65 * vim.o.lines)
|
||||
local width = math.floor(0.80 * vim.o.columns)
|
||||
return {
|
||||
anchor = 'NW', height = height, width = width,
|
||||
row = math.floor(0.5 * (vim.o.lines - height)),
|
||||
col = math.floor(0.5 * (vim.o.columns - width)),
|
||||
}
|
||||
end
|
||||
}
|
||||
})
|
||||
|
||||
vim.cmd(":HighlightColors Off")
|
||||
vim.cmd(":colorscheme kintsugi-dark")
|
||||
|
||||
-- Lsp specific, uses nvim-lspconfigs with the below
|
||||
vim.lsp.enable({ "gopls", "ols" })
|
||||
map("n", "L", ":lua vim.diagnostic.open_float()<CR>")
|
||||
map("n", "gd", ":lua vim.lsp.buf.definition()<CR>")
|
||||
map("n", "<leader>r", ":lua vim.lsp.buf.rename()<CR>")
|
||||
map("n", "<leader>a", ":lua vim.lsp.buf.code_action()<CR>")
|
||||
-- Mini Keybinds
|
||||
map("n", "<leader>e", function() MiniFiles.open(vim.fn.getcwd()) end)
|
||||
map("n", "<leader>f", function() MiniPick.builtin.files(nil, { source = { cwd = vim.fn.getcwd() } }) end)
|
||||
map("n", "<leader>o", ":lua MiniPick.builtin.buffers()<CR>")
|
||||
map("n", "<leader>h", ":lua MiniPick.builtin.help()<CR>")
|
||||
map("n", "<leader>d", ":lua MiniExtra.pickers.diagnostic()<CR>")
|
||||
map("n", "<leader>pp", ":lua MiniSessions.select()<CR>")
|
||||
map("n", "<leader>ss", ":Pick buf_lines scope='current'<CR>")
|
||||
map("n", "<leader>sp", function() MiniPick.builtin.grep_live(nil, { source = { cwd = vim.fn.getcwd() } }) end)
|
||||
map('n', '<leader>sw', function() MiniPick.builtin.grep({ pattern = vim.fn.expand('<cword>') }) end)
|
||||
-- Others
|
||||
map("n", "<leader>tc", ":HighlightColors Toggle<CR>")
|
||||
|
||||
Reference in New Issue
Block a user