vim.cmd.colorscheme("vim") vim.g.mapleader = " " vim.keymap.set("n", "", "zz") vim.keymap.set("n", "", "") vim.keymap.set("n", "", "") vim.keymap.set("n", "", "") vim.keymap.set("n", "", "") vim.keymap.set("n", "", "zz") vim.keymap.set("n", "", ":nohlsearch") vim.keymap.set("n", "f", vim.lsp.buf.format) vim.keymap.set("n", "a", ":lua vim.lsp.buf.code_action()") vim.keymap.set("n", "pv", ":Ex") vim.keymap.set("v", "J", ":m '>+1gv=gv") vim.keymap.set("v", "K", ":m '<-2gv=gv") vim.keymap.set({ 'n', 'v', 'x' }, 'd', '"+d') vim.keymap.set({ 'n', 'v', 'x' }, 'y', '"+y') vim.o.number = true vim.o.relativenumber = true vim.o.shiftwidth = 2 vim.o.tabstop = 2 vim.o.expandtab = true vim.o.scrolloff = 8 vim.o.wrap = false vim.o.winborder = "rounded" vim.o.clipboard = "unnamedplus" vim.o.swapfile = false vim.opt.path:append("**") local augroup = vim.api.nvim_create_augroup("vxclutch", {}) vim.api.nvim_create_autocmd("BufReadPost", { group = augroup, callback = function() local mark = vim.api.nvim_buf_get_mark(0, '"') local lcount = vim.api.nvim_buf_line_count(0) if mark[1] > 0 and mark[1] <= lcount then pcall(vim.api.nvim_win_set_cursor, 0, mark) end end, }) vim.api.nvim_create_autocmd("TermOpen", { group = augroup, callback = function() vim.opt_local.number = false vim.opt_local.relativenumber = false vim.opt_local.signcolumn = "no" end, }) vim.api.nvim_create_autocmd("BufWritePre", { group = augroup, callback = function() local dir = vim.fn.expand(':p:h') if vim.fn.isdirectory(dir) == 0 then vim.fn.mkdir(dir, 'p') end end, }) local undodir = vim.fn.expand("~/.vim/undodir") if vim.fn.isdirectory(undodir) == 0 then vim.fn.mkdir(undodir, "p") end local terminal_state = { buf = nil, win = nil, is_open = false } local function FloatingTerminal() if terminal_state.is_open and vim.api.nvim_win_is_valid(terminal_state.win) then vim.api.nvim_win_close(terminal_state.win, false) terminal_state.is_open = false return end if not terminal_state.buf or not vim.api.nvim_buf_is_valid(terminal_state.buf) then terminal_state.buf = vim.api.nvim_create_buf(false, true) vim.api.nvim_buf_set_option(terminal_state.buf, 'bufhidden', 'hide') end local width = math.floor(vim.o.columns * 0.8) local height = math.floor(vim.o.lines * 0.8) local row = math.floor((vim.o.lines - height) / 2) local col = math.floor((vim.o.columns - width) / 2) terminal_state.win = vim.api.nvim_open_win(terminal_state.buf, true, { relative = 'editor', width = width, height = height, row = row, col = col, style = 'minimal', border = 'rounded', }) vim.api.nvim_win_set_option(terminal_state.win, 'winblend', 0) vim.api.nvim_win_set_option(terminal_state.win, 'winhighlight', 'Normal:FloatingTermNormal,FloatBorder:FloatingTermBorder') vim.api.nvim_set_hl(0, "FloatingTermNormal", { bg = "none" }) vim.api.nvim_set_hl(0, "FloatingTermBorder", { bg = "none", }) local has_terminal = false local lines = vim.api.nvim_buf_get_lines(terminal_state.buf, 0, -1, false) for _, line in ipairs(lines) do if line ~= "" then has_terminal = true break end end if not has_terminal then vim.fn.termopen(os.getenv("SHELL")) end terminal_state.is_open = true vim.cmd("startinsert") vim.api.nvim_create_autocmd("BufLeave", { buffer = terminal_state.buf, callback = function() if terminal_state.is_open and vim.api.nvim_win_is_valid(terminal_state.win) then vim.api.nvim_win_close(terminal_state.win, false) terminal_state.is_open = false end end, once = true }) end local function CloseFloatingTerminal() if terminal_state.is_open and vim.api.nvim_win_is_valid(terminal_state.win) then vim.api.nvim_win_close(terminal_state.win, false) terminal_state.is_open = false end end vim.keymap.set("n", "t", FloatingTerminal, { noremap = true, silent = true }) vim.keymap.set("t", "", function() if terminal_state.is_open then vim.api.nvim_win_close(terminal_state.win, false) terminal_state.is_open = false end end, { noremap = true, silent = true }) vim.pack.add({ { src = "https://github.com/neovim/nvim-lspconfig" }, }) local lspconfig = require("lspconfig") local servers = { "lua_ls", "clangd" } for _, server in ipairs(servers) do lspconfig[server].setup({}) end vim.api.nvim_create_autocmd('LspAttach', { callback = function(ev) local client = vim.lsp.get_client_by_id(ev.data.client_id) if client:supports_method('textDocument/completion') then vim.lsp.completion.enable(true, client.id, ev.buf, { autotrigger = true }) end end, }) vim.diagnostic.config({ virtual_text = true, underline = true, })