vim.g.mapleader = " " -- set vim.opt.number = true vim.opt.relativenumber = true vim.opt.tabstop = 4 vim.opt.softtabstop = 4 vim.opt.shiftwidth = 4 vim.opt.expandtab = true vim.opt.smartindent = true vim.opt.wrap = false vim.opt.swapfile = false vim.opt.backup = false vim.opt.undodir = os.getenv("HOME") .. "/.vim/undodir" vim.opt.undofile = true vim.opt.hlsearch = true vim.opt.incsearch = true vim.opt.scrolloff = 2 vim.opt.colorcolumn = "80,100,120" vim.api.nvim_create_autocmd({"BufEnter"}, { callback = function() vim.cmd("set formatoptions-=r") vim.cmd("set formatoptions-=o") end }) vim.g.netrw_bufsettings = "noma nomod nu nobl nowrap ro" vim.g.netrw_banner = 0 vim.opt.signcolumn = "yes" vim.opt.list = true vim.o.exrc = true vim.keymap.set("n", "w", vim.cmd.write) vim.keymap.set({ "n", "v" }, "y", [["+y]]) vim.keymap.set("n", "Y", [["+Y]]) vim.keymap.set({ "n", "v" }, "p", [["+p]]) vim.keymap.set("n", "P", [["+P]]) vim.keymap.set({ "n", "v" }, "d", [["+d]]) vim.keymap.set("n", "D", [["+D]]) vim.keymap.set("t", "", "") vim.keymap.set("n", "", function() local win_number = vim.api.nvim_get_current_win() if vim.api.nvim_win_get_config(win_number).relative ~= "" then vim.cmd("q") else vim.cmd("noh") end end) vim.keymap.set("v", ">", ">gv") vim.keymap.set("v", "<", "", "0\"_d$?.noh0\"myw0\"_d$\"mpa") -- insert line break under cursor in normal mode vim.keymap.set("n", "", function() local col = vim.api.nvim_win_get_cursor(0)[2] local char = vim.api.nvim_get_current_line():sub(col + 1, col + 1) if char == " " then vim.fn.feedkeys(vim.api.nvim_replace_termcodes("\"_xif ", true, true, true)) else vim.fn.feedkeys(vim.api.nvim_replace_termcodes("if ", true, true, true)) end end) vim.keymap.set("n", "tt", function() -- idk it works if vim.opt.expandtab:get() then vim.opt.expandtab = false else vim.opt.expandtab = true end -- this is idiotic vim.fn.feedkeys(vim.api.nvim_replace_termcodes("", true, true, true)) end) vim.cmd([[set statusline=%<%f\ %h%m%r%=%-14.(%l,%c%V%)\ %P]]) --default vim.cmd([[set statusline+=\ ft=%{&filetype}]]) vim.cmd([[set statusline+=\ ff=%{&fileformat}]]) vim.cmd([[set statusline+=\ spaces=%{&expandtab}]]) vim.cmd([[set statusline+=%{get(b:,'\ \ gitsigns_status','')}]]) vim.keymap.set("n", "tf", function() local path = vim.api.nvim_buf_get_name(0) vim.cmd("silent !ctags -a " .. path) end) vim.keymap.set("n", "td", function() vim.cmd("silent !ctags -aR .") end) -- colorscheme vim.cmd("colorscheme industry") vim.opt.guicursor = "n-v-c-i-r:block"; vim.api.nvim_set_hl(0, "FloatBorder", { foreground = nil, background = nil }) vim.api.nvim_set_hl(0, "DiagnosticError", { foreground = "White", background = "DarkRed" }) vim.api.nvim_set_hl(0, "DiagnosticWarn", { foreground = "Yellow" }) vim.api.nvim_set_hl(0, "CmpItemAbbr", { foreground = "White" }) vim.api.nvim_set_hl(0, "CmpItemAbbrMatch", { foreground = "Yellow" }) vim.api.nvim_set_hl(0, "CmpItemAbbrMatchFuzzy", { foreground = "Yellow" }) vim.api.nvim_set_hl(0, "CmpItemKind", { foreground = "White" }) -- todo: specific kinds having different colors vim.api.nvim_set_hl(0, "LineNrAbove", { foreground = "LightYellow" }) vim.api.nvim_set_hl(0, "LineNr", { foreground = "White" }) vim.api.nvim_set_hl(0, "LineNrBelow", { foreground = "LightBlue" }) vim.api.nvim_set_hl(0, "MatchParen", { background = "#0000ff" }) -- contents[index] = string.format("%%#HarpoonNumberInactive# [%s] %%#HarpoonInactive#%s ", index, file_name) vim.api.nvim_set_hl(0, "HarpoonNumberActive", { background = "Gray", foreground = "White" }) vim.api.nvim_set_hl(0, "HarpoonActive", { background = "Gray", foreground = "White" }) vim.api.nvim_set_hl(0, "HarpoonNumberInactive", { background = "Black", foreground = "White" }) vim.api.nvim_set_hl(0, "HarpoonInactive", { background = "Black", foreground = "White" }) -- lazy.nvim local lazypath = vim.fn.stdpath("data") .. "/lazy/lazy.nvim" if not vim.uv.fs_stat(lazypath) then vim.fn.system({ "git", "clone", "--filter=blob:none", "https://github.com/folke/lazy.nvim.git", "--branch=stable", -- latest stable release lazypath, }) end vim.opt.rtp:prepend(lazypath) require("lazy").setup({ { "nvim-treesitter/nvim-treesitter", branch = "master", config = function() require("nvim-treesitter.configs").setup({ auto_install = true, highlight = { enable = true, }, }) vim.cmd("TSUpdate") end }, { "mbbill/undotree", keys = { { "u", "UndotreeTogglehhhh" } }, }, { "nvim-telescope/telescope.nvim", tag = "0.1.4", dependencies = { "nvim-lua/plenary.nvim" }, lazy = true, keys = { { "", "Telescope find_files" }, { "fg", "Telescope live_grep" }, { "fh", "Telescope help_tags" }, }, config = function() require("telescope").setup({ defaults = { preview = { treesitter = false, }, file_ignore_patterns = { ".git", -- i should probly make this less bad "zig-cache/", "zig-out/", "build/", "bin/", }, }, }) end }, "tpope/vim-repeat", "tpope/vim-surround", "tpope/vim-commentary", "tpope/vim-fugitive", { "neovim/nvim-lspconfig", dependencies = { "williamboman/mason.nvim", "williamboman/mason-lspconfig.nvim", "WhoIsSethDaniel/mason-tool-installer.nvim", { "j-hui/fidget.nvim", opts = {} }, { "folke/neodev.nvim", opts = {} }, }, config = function() vim.api.nvim_create_autocmd("LspAttach", { group = vim.api.nvim_create_augroup("kickstart-lsp-attach", { clear = true }), callback = function(event) local map = function(keys, func, desc) vim.keymap.set("n", keys, func, { buffer = event.buf, desc = "LSP: " .. desc }) end map("gd", require("telescope.builtin").lsp_definitions, "[G]oto [D]efinition") map("gr", require("telescope.builtin").lsp_references, "[G]oto [R]eferences") map("gi", require("telescope.builtin").lsp_implementations, "[G]oto [I]mplementation") map("gt", require("telescope.builtin").lsp_type_definitions, "Type [D]efinition") map("gh", vim.diagnostic.open_float, "[G]oto [H]ighlight Error (idk)") map("[d", vim.diagnostic.goto_next, "Next [D]iagnostic") map("]d", vim.diagnostic.goto_prev, "Prev [D]iagnostic") map("lr", vim.lsp.buf.rename, "[L]SP [R]ename") map("", vim.lsp.buf.code_action, "Code Action") map("K", vim.lsp.buf.hover, "Hover Documentation") map("gD", vim.lsp.buf.declaration, "[G]oto [D]eclaration") end, }) local capabilities = vim.lsp.protocol.make_client_capabilities() capabilities = vim.tbl_deep_extend("force", capabilities, require("cmp_nvim_lsp").default_capabilities()) local servers = { lua_ls = { settings = { Lua = { completion = { callSnippet = 'Replace', }, }, }, }, } require("mason").setup() local ensure_installed = vim.tbl_keys(servers or {}) vim.list_extend(ensure_installed, { "stylua", }) require("mason-tool-installer").setup({ ensure_installed = ensure_installed }) require("mason-lspconfig").setup { handlers = { function(server_name) local server = servers[server_name] or {} server.capabilities = vim.tbl_deep_extend("force", {}, capabilities, server.capabilities or {}) require("lspconfig")[server_name].setup(server) end, }, } end, }, { "hrsh7th/cmp-nvim-lsp" }, { "hrsh7th/nvim-cmp", dependencies = { "quangnguyen30192/cmp-nvim-tags", "L3MON4D3/LuaSnip", "saadparwaiz1/cmp_luasnip" }, config = function() local cmp = require("cmp") local luasnip = require("luasnip") cmp.setup({ snippet = { expand = function(args) luasnip.lsp_expand(args.body) end, }, sources = { { name = "nvim_lsp" }, { name = "luasnip" }, { name = "tags" }, }, mapping = cmp.mapping.preset.insert({ [""] = cmp.mapping.select_next_item(), [""] = cmp.mapping.select_prev_item(), [""] = cmp.mapping.confirm({ select = true }), }), [""] = cmp.mapping(function() if luasnip.expand_or_locally_jumpable() then luasnip.expand_or_jump() end end, { "i", "s" }), [""] = cmp.mapping(function() if luasnip.locally_jumpable(-1) then luasnip.jump(-1) end end, { "i", "s" }), }) end }, { "L3MON4D3/LuaSnip", version = "v2.*", }, { "ThePrimeagen/harpoon", branch = "harpoon2", dependencies = { "nvim-lua/plenary.nvim" }, config = function() local harpoon = require("harpoon") harpoon:setup({}) vim.keymap.set("n", "a", function() harpoon:list():add() vim.cmd(":do User") end) vim.keymap.set("n", "s", function() harpoon.ui:toggle_quick_menu(harpoon:list()) end) vim.keymap.set("n", "1", function() harpoon:list():select(1) end) vim.keymap.set("n", "2", function() harpoon:list():select(2) end) vim.keymap.set("n", "3", function() harpoon:list():select(3) end) vim.keymap.set("n", "4", function() harpoon:list():select(4) end) vim.keymap.set("n", "5", function() harpoon:list():select(5) end) vim.keymap.set("n", "6", function() harpoon:list():select(6) end) vim.keymap.set("n", "7", function() harpoon:list():select(7) end) vim.keymap.set("n", "8", function() harpoon:list():select(8) end) vim.keymap.set("n", "9", function() harpoon:list():select(9) end) -- thx @lokxii, exactly what i wanted (https://github.com/ThePrimeagen/harpoon/issues/352#issuecomment-1893131934) function Harpoon_files() local contents = {} local marks_length = harpoon:list():length() local current_file_path = vim.fn.fnamemodify(vim.fn.expand("%:p"), ":.") for index = 1, marks_length do -- https://github.com/ThePrimeagen/harpoon/issues/555 local success, harpoon_file_path = pcall(function() return harpoon:list():get(index).value end) if not success then return "" end local file_name = harpoon_file_path == "" and "(empty)" or vim.fn.fnamemodify(harpoon_file_path, ':t') if current_file_path == harpoon_file_path then contents[index] = string.format("%%#HarpoonNumberActive# [%s] %%#HarpoonActive#%s ", index, file_name) else contents[index] = string.format("%%#HarpoonNumberInactive# [%s] %%#HarpoonInactive#%s ", index, file_name) end end return table.concat(contents) end vim.opt.showtabline = 2 vim.api.nvim_create_autocmd({ "BufEnter", "BufAdd", "User" }, { callback = function(_) local result = Harpoon_files() if result == "" then vim.opt.showtabline = 1 else vim.opt.showtabline = 2 end vim.o.tabline = result end }) end, }, { "lewis6991/gitsigns.nvim", opts = { signs = { add = { text = '+' }, change = { text = '~' }, -- delete = { text = '_' }, -- topdelete = { text = '‾' }, -- changedelete = { text = '~' }, -- untracked = { text = '┆' }, }, on_attach = function() local gitsigns = require("gitsigns") vim.keymap.set("n", "K", gitsigns.preview_hunk) end }, }, { "stevearc/oil.nvim", opts = {}, config = function() local oil = require("oil") oil.setup({}) vim.keymap.set("n", "ff", oil.open) end } })