diff --git a/nvim/init.lua b/nvim/init.lua index d624999..5dca27b 100644 --- a/nvim/init.lua +++ b/nvim/init.lua @@ -1,41 +1,13 @@ -vim.g.base46_cache = vim.fn.stdpath "data" .. "/base46/" +-- Default my settings vim.g.mapleader = " " vim.wo.number = true vim.wo.relativenumber = true vim.opt.wrap = false --- bootstrap lazy and all plugins -local lazypath = vim.fn.stdpath "data" .. "/lazy/lazy.nvim" +-- Add basic configs +require("configs.lazy") +require("mappings") +require("options") +require("custom.init") -if not vim.uv.fs_stat(lazypath) then - local repo = "https://github.com/folke/lazy.nvim.git" - vim.fn.system { "git", "clone", "--filter=blob:none", repo, "--branch=stable", lazypath } -end - -vim.opt.rtp:prepend(lazypath) - -local lazy_config = require "configs.lazy" - --- load plugins -require("lazy").setup({ - { - "NvChad/NvChad", - lazy = false, - branch = "v2.5", - import = "nvchad.plugins", - }, - - { import = "plugins" }, -}, lazy_config) - --- load theme -dofile(vim.g.base46_cache .. "defaults") -dofile(vim.g.base46_cache .. "statusline") - -require "options" -require "autocmds" -require "custom.init" - -vim.schedule(function() - require "mappings" -end) +vim.cmd[[colorscheme darcula-dark]] diff --git a/nvim/lazy-lock.json b/nvim/lazy-lock.json index 40ce142..76b07d2 100644 --- a/nvim/lazy-lock.json +++ b/nvim/lazy-lock.json @@ -1,36 +1,36 @@ { - "LuaSnip": { "branch": "master", "commit": "f958d9837c8fa7816bb8fb54977e658affc63c31" }, - "NvChad": { "branch": "v2.5", "commit": "f107fabe11ac8013dc3435ecd5382bee872b1584" }, - "base46": { "branch": "v3.0", "commit": "db58475d3fd2a16f9b1467d6895e3c4c195ed7dd" }, - "cmp-async-path": { "branch": "main", "commit": "0ed1492f59e730c366d261a5ad822fa37e44c325" }, + "LuaSnip": { "branch": "master", "commit": "3732756842a2f7e0e76a7b0487e9692072857277" }, + "bufferline.nvim": { "branch": "main", "commit": "655133c3b4c3e5e05ec549b9f8cc2894ac6f51b3" }, + "cmp-async-path": { "branch": "main", "commit": "b8aade3a0626f2bc1d3cd79affcd7da9f47f7ab1" }, "cmp-buffer": { "branch": "main", "commit": "b74fab3656eea9de20a9b8116afa3cfc4ec09657" }, "cmp-nvim-lsp": { "branch": "main", "commit": "bd5a7d6db125d4654b50eeae9f5217f24bb22fd3" }, "cmp-nvim-lua": { "branch": "main", "commit": "f12408bdb54c39c23e67cab726264c10db33ada8" }, "cmp_luasnip": { "branch": "master", "commit": "98d9cb5c2c38532bd9bdb481067b20fea8f32e90" }, - "conform.nvim": { "branch": "master", "commit": "fbcb4fa7f34bfea9be702ffff481a8e336ebf6ed" }, + "conform.nvim": { "branch": "master", "commit": "cde4da5c1083d3527776fee69536107d98dae6c9" }, + "darcula-dark.nvim": { "branch": "main", "commit": "5e8edf8b2aff3bf3d5110799713d29649cb87bbb" }, "friendly-snippets": { "branch": "main", "commit": "572f5660cf05f8cd8834e096d7b4c921ba18e175" }, - "gitsigns.nvim": { "branch": "main", "commit": "1ee5c1fd068c81f9dd06483e639c2aa4587dc197" }, - "indent-blankline.nvim": { "branch": "master", "commit": "005b56001b2cb30bfa61b7986bc50657816ba4ba" }, - "lazy.nvim": { "branch": "main", "commit": "6c3bda4aca61a13a9c63f1c1d1b16b9d3be90d7a" }, - "mason-nvim-dap.nvim": { "branch": "main", "commit": "86389a3dd687cfaa647b6f44731e492970034baa" }, + "gitsigns.nvim": { "branch": "main", "commit": "20ad4419564d6e22b189f6738116b38871082332" }, + "lazy.nvim": { "branch": "main", "commit": "85c7ff3711b730b4030d03144f6db6375044ae82" }, + "lualine.nvim": { "branch": "master", "commit": "3946f0122255bc377d14a59b27b609fb3ab25768" }, + "marks.nvim": { "branch": "master", "commit": "f353e8c08c50f39e99a9ed474172df7eddd89b72" }, + "mason-lspconfig.nvim": { "branch": "main", "commit": "d7b5feb6e769e995f7fcf44d92f49f811c51d10c" }, "mason.nvim": { "branch": "main", "commit": "ad7146aa61dcaeb54fa900144d768f040090bff0" }, - "menu": { "branch": "main", "commit": "7a0a4a2896b715c066cfbe320bdc048091874cc6" }, - "minty": { "branch": "main", "commit": "aafc9e8e0afe6bf57580858a2849578d8d8db9e0" }, + "mini.pairs": { "branch": "main", "commit": "b316e68f2d242d5bd010deaab645daa27ed86297" }, + "noice.nvim": { "branch": "main", "commit": "7bfd942445fb63089b59f97ca487d605e715f155" }, + "nui.nvim": { "branch": "main", "commit": "de740991c12411b663994b2860f1a4fd0937c130" }, "nvim-autopairs": { "branch": "master", "commit": "7a2c97cccd60abc559344042fefb1d5a85b3e33b" }, - "nvim-cmp": { "branch": "main", "commit": "a7bcf1d88069fc67c9ace8a62ba480b8fe879025" }, - "nvim-dap": { "branch": "master", "commit": "881f7dc17c0b4204a1d844732f95539575350e5b" }, - "nvim-dap-ui": { "branch": "master", "commit": "cf91d5e2d07c72903d052f5207511bf7ecdb7122" }, - "nvim-dap-virtual-text": { "branch": "master", "commit": "fbdb48c2ed45f4a8293d0d483f7730d24467ccb6" }, - "nvim-lspconfig": { "branch": "master", "commit": "ac98db2f9f06a56498ec890a96928774eae412c3" }, - "nvim-nio": { "branch": "master", "commit": "21f5324bfac14e22ba26553caf69ec76ae8a7662" }, - "nvim-tree.lua": { "branch": "master", "commit": "e397756d2a79d74314ea4cd3efc41300e91c0ff0" }, + "nvim-cmp": { "branch": "main", "commit": "106c4bcc053a5da783bf4a9d907b6f22485c2ea0" }, + "nvim-lspconfig": { "branch": "master", "commit": "2010fc6ec03e2da552b4886fceb2f7bc0fc2e9c0" }, + "nvim-notify": { "branch": "master", "commit": "8701bece920b38ea289b457f902e2ad184131a5d" }, + "nvim-tree.lua": { "branch": "master", "commit": "64e2192f5250796aa4a7f33c6ad888515af50640" }, "nvim-treesitter": { "branch": "master", "commit": "42fc28ba918343ebfd5565147a42a26580579482" }, - "nvim-web-devicons": { "branch": "master", "commit": "b8221e42cf7287c4dcde81f232f58d7b947c210d" }, + "nvim-ufo": { "branch": "main", "commit": "72d54c31079d38d8dfc5456131b1d0fb5c0264b0" }, + "nvim-web-devicons": { "branch": "master", "commit": "8dcb311b0c92d460fac00eac706abd43d94d68af" }, + "persisted.nvim": { "branch": "main", "commit": "5063ee8e3589a43eefadcca57496aea01b6170fa" }, "plenary.nvim": { "branch": "master", "commit": "b9fd5226c2f76c951fc8ed5923d85e4de065e509" }, - "telescope.nvim": { "branch": "master", "commit": "b4da76be54691e854d3e0e02c36b0245f945c2c7" }, - "ui": { "branch": "v3.0", "commit": "03b9718140375e7f3f5e4f3e04bc2b6c907440ec" }, - "vim-devicons": { "branch": "master", "commit": "71f239af28b7214eebb60d4ea5bd040291fb7e33" }, + "promise-async": { "branch": "main", "commit": "119e8961014c9bfaf1487bf3c2a393d254f337e2" }, + "snacks.nvim": { "branch": "main", "commit": "9a15b317495cda991d3b4990f18aed47a9a9a891" }, + "telescope.nvim": { "branch": "master", "commit": "a0bbec21143c7bc5f8bb02e0005fa0b982edc026" }, "vim-highlightedyank": { "branch": "master", "commit": "285a61425e79742997bbde76a91be6189bc988fb" }, - "volt": { "branch": "main", "commit": "620de1321f275ec9d80028c68d1b88b409c0c8b1" }, - "which-key.nvim": { "branch": "main", "commit": "b4177e3eaf15fe5eb8357ebac2286d488be1ed00" } + "which-key.nvim": { "branch": "main", "commit": "3aab2147e74890957785941f0c1ad87d0a44c15a" } } diff --git a/nvim/lua/configs/bufferline.lua b/nvim/lua/configs/bufferline.lua new file mode 100644 index 0000000..f0a0c68 --- /dev/null +++ b/nvim/lua/configs/bufferline.lua @@ -0,0 +1,64 @@ +local bufferline = require('bufferline') +bufferline.setup { + options = { + mode = "buffers", -- set to "tabs" to only show tabpages instead + style_preset = bufferline.style_preset.default, + themable = true, + indicator = { + icon = '▎', + style = 'icon', + }, + buffer_close_icon = '󰅖', + modified_icon = '● ', + close_icon = ' ', + left_trunc_marker = ' ', + right_trunc_marker = ' ', + max_name_length = 18, + max_prefix_length = 15, + truncate_names = true, + tab_size = 18, + custom_filter = function(buf_number, buf_numbers) + if vim.bo[buf_number].filetype ~= "" then + return true + end + if vim.fn.bufname(buf_number) ~= "" then + return true + end + if vim.fn.getcwd() == "" and vim.bo[buf_number].filetype ~= "wiki" then + return true + end + if buf_numbers[1] ~= buf_number then + return true + end + end, + offsets = { + { + filetype = "NvimTree", + text = "File Explorer", + text_align = "left", + separator = true + } + }, + color_icons = true, + get_element_icon = function(element) + local icon, hl = require('nvim-web-devicons').get_icon_by_filetype(element.filetype, { default = false }) + return icon, hl + end, + show_buffer_icons = true, + show_buffer_close_icons = true, + show_close_icon = true, + show_tab_indicators = true, + separator_style = "slant", + enforce_regular_tabs = false, + always_show_bufferline = true, + auto_toggle_bufferline = true, + hover = { + enabled = true, + delay = 200, + reveal = {'close'} + }, + pick = { + alphabet = "abcdefghijklmopqrstuvwxyzABCDEFGHIJKLMOPQRSTUVWXYZ1234567890", + }, + } +} diff --git a/nvim/lua/configs/cmp.lua b/nvim/lua/configs/cmp.lua new file mode 100644 index 0000000..36bc96d --- /dev/null +++ b/nvim/lua/configs/cmp.lua @@ -0,0 +1,56 @@ + +local cmp = require "cmp" + +local options = { + completion = { completeopt = "menu,menuone" }, + + snippet = { + expand = function(args) + require("luasnip").lsp_expand(args.body) + end, + }, + + mapping = { + [""] = cmp.mapping.select_prev_item(), + [""] = cmp.mapping.select_next_item(), + [""] = cmp.mapping.scroll_docs(-4), + [""] = cmp.mapping.scroll_docs(4), + [""] = cmp.mapping.complete(), + [""] = cmp.mapping.close(), + + [""] = cmp.mapping.confirm { + behavior = cmp.ConfirmBehavior.Insert, + select = true, + }, + + [""] = cmp.mapping(function(fallback) + if cmp.visible() then + cmp.select_next_item() + elseif require("luasnip").expand_or_jumpable() then + require("luasnip").expand_or_jump() + else + fallback() + end + end, { "i", "s" }), + + [""] = cmp.mapping(function(fallback) + if cmp.visible() then + cmp.select_prev_item() + elseif require("luasnip").jumpable(-1) then + require("luasnip").jump(-1) + else + fallback() + end + end, { "i", "s" }), + }, + + sources = { + { name = "nvim_lsp" }, + { name = "luasnip" }, + { name = "buffer" }, + { name = "nvim_lua" }, + { name = "async_path" }, + }, +} + +return vim.tbl_deep_extend("force", options, {}) diff --git a/nvim/lua/configs/conform.lua b/nvim/lua/configs/conform.lua index 13561ed..ad34362 100644 --- a/nvim/lua/configs/conform.lua +++ b/nvim/lua/configs/conform.lua @@ -2,14 +2,12 @@ local options = { formatters_by_ft = { lua = { "stylua" }, cpp = { "clang-format" }, - -- html = { "prettier" }, }, - -- format_on_save = { - -- -- These options will be passed to conform.format() - -- timeout_ms = 500, - -- lsp_fallback = true, - -- }, + format_on_save = { + timeout_ms = 500, + lsp_fallback = true, + }, } return options diff --git a/nvim/lua/configs/gitsigns.lua b/nvim/lua/configs/gitsigns.lua new file mode 100644 index 0000000..8a697b5 --- /dev/null +++ b/nvim/lua/configs/gitsigns.lua @@ -0,0 +1,53 @@ +return { + signs = { + add = { text = "▎" }, + change = { text = "▎" }, + delete = { text = "" }, + topdelete = { text = "" }, + changedelete = { text = "▎" }, + untracked = { text = "▎" }, + }, + signs_staged = { + add = { text = "▎" }, + change = { text = "▎" }, + delete = { text = "" }, + topdelete = { text = "" }, + changedelete = { text = "▎" }, + }, + on_attach = function(buffer) + local gs = package.loaded.gitsigns + + local function map(mode, l, r, desc) + vim.keymap.set(mode, l, r, { buffer = buffer, desc = desc, silent = true }) + end + + -- stylua: ignore start + map("n", "]h", function() + if vim.wo.diff then + vim.cmd.normal({ "]c", bang = true }) + else + gs.nav_hunk("next") + end + end, "Next Hunk") + map("n", "[h", function() + if vim.wo.diff then + vim.cmd.normal({ "[c", bang = true }) + else + gs.nav_hunk("prev") + end + end, "Prev Hunk") + map("n", "]H", function() gs.nav_hunk("last") end, "Last Hunk") + map("n", "[H", function() gs.nav_hunk("first") end, "First Hunk") + map({ "n", "x" }, "ghs", ":Gitsigns stage_hunk", "Stage Hunk") + map({ "n", "x" }, "ghr", ":Gitsigns reset_hunk", "Reset Hunk") + map("n", "ghS", gs.stage_buffer, "Stage Buffer") + map("n", "ghu", gs.undo_stage_hunk, "Undo Stage Hunk") + map("n", "ghR", gs.reset_buffer, "Reset Buffer") + map("n", "ghp", gs.preview_hunk_inline, "Preview Hunk Inline") + map("n", "ghb", function() gs.blame_line({ full = true }) end, "Blame Line") + map("n", "ghB", function() gs.blame() end, "Blame Buffer") + map("n", "ghd", gs.diffthis, "Diff This") + map("n", "ghD", function() gs.diffthis("~") end, "Diff This ~") + map({ "o", "x" }, "ih", ":Gitsigns select_hunk", "GitSigns Select Hunk") + end, +} diff --git a/nvim/lua/configs/lazy.lua b/nvim/lua/configs/lazy.lua index cd170bd..e70e849 100644 --- a/nvim/lua/configs/lazy.lua +++ b/nvim/lua/configs/lazy.lua @@ -1,47 +1,26 @@ -return { - defaults = { lazy = true }, - install = { colorscheme = { "nvchad" } }, +local lazypath = vim.fn.stdpath("data") .. "/lazy/lazy.nvim" +if not (vim.uv or vim.loop).fs_stat(lazypath) then + local lazyrepo = "https://github.com/folke/lazy.nvim.git" + local out = vim.fn.system({ "git", "clone", "--filter=blob:none", "--branch=stable", lazyrepo, lazypath }) + if vim.v.shell_error ~= 0 then + vim.api.nvim_echo({ + { "Failed to clone lazy.nvim:\n", "ErrorMsg" }, + { out, "WarningMsg" }, + { "\nPress any key to exit..." }, + }, true, {}) + vim.fn.getchar() + os.exit(1) + end +end +vim.opt.rtp:prepend(lazypath) - ui = { - icons = { - ft = "", - lazy = "󰂠 ", - loaded = "", - not_loaded = "", - }, - }, +vim.g.mapleader = " " +vim.g.maplocalleader = "\\" - performance = { - rtp = { - disabled_plugins = { - "2html_plugin", - "tohtml", - "getscript", - "getscriptPlugin", - "gzip", - "logipat", - "netrw", - "netrwPlugin", - "netrwSettings", - "netrwFileHandlers", - "matchit", - "tar", - "tarPlugin", - "rrhelper", - "spellfile_plugin", - "vimball", - "vimballPlugin", - "zip", - "zipPlugin", - "tutor", - "rplugin", - "syntax", - "synmenu", - "optwin", - "compiler", - "bugreport", - "ftplugin", - }, - }, +require("lazy").setup({ + spec = { + { import = "plugins" }, }, -} + install = { colorscheme = { "darcula-dark" } }, + checker = { enabled = true }, +}) diff --git a/nvim/lua/configs/lsp/e-lspconfig.lua b/nvim/lua/configs/lsp/e-lspconfig.lua new file mode 100644 index 0000000..8edad00 --- /dev/null +++ b/nvim/lua/configs/lsp/e-lspconfig.lua @@ -0,0 +1,34 @@ +local M = {} +local api = vim.api + +local function check_triggeredChars(triggerChars) + local cur_line = api.nvim_get_current_line() + local pos = api.nvim_win_get_cursor(0)[2] + local prev_char = cur_line:sub(pos - 1, pos - 1) + local cur_char = cur_line:sub(pos, pos) + + for _, char in ipairs(triggerChars) do + if cur_char == char or prev_char == char then + return true + end + end +end + +M.setup = function(client, bufnr) + local group = api.nvim_create_augroup("LspSignature", { clear = false }) + api.nvim_clear_autocmds { group = group, buffer = bufnr } + + local triggerChars = client.server_capabilities.signatureHelpProvider.triggerCharacters + + api.nvim_create_autocmd("TextChangedI", { + group = group, + buffer = bufnr, + callback = function() + if check_triggeredChars(triggerChars) then + vim.lsp.buf.signature_help { focus = false, silent = true, max_height = 7, border = "single" } + end + end, + }) +end + +return M diff --git a/nvim/lua/configs/lsp/lspconfig.lua b/nvim/lua/configs/lsp/lspconfig.lua new file mode 100644 index 0000000..7e6e8fb --- /dev/null +++ b/nvim/lua/configs/lsp/lspconfig.lua @@ -0,0 +1,65 @@ +local on_attach = require("configs.lsp.e-lspconfig").on_attach +local on_init = require("configs.lsp.e-lspconfig").on_init +local capabilities = require("configs.lsp.e-lspconfig").capabilities + +-- clangd lsp server +vim.lsp.config('clangd', { + on_attach = on_attach, + on_init = on_init, + capabilities = capabilities, + cmd = { + "clangd", + "--background-index", + "--background-index-priority=normal", + "--clang-tidy", + "--experimental-modules-support", + "--all-scopes-completion", + "--completion-style=detailed", + "--header-insertion=iwyu", + "--limit-references=5", + "--malloc-trim", + "--pch-storage=disk", + }, + filetypes = { "c", "cpp", "objc", "objcpp" }, + init_options = { + fallbackFlags = {'-std=c++20'}, + } +}) +vim.lsp.enable('clangd') + +-- Lua +vim.lsp.config('lua_ls', { + cmd = { 'lua-language-server' }, + filetypes = { 'lua' }, + root_markers = { '.luarc.json', '.luarc.jsonc', '.git' }, + single_file_support = true, + settings = { + Lua = { + telemetry = { enable = false }, + runtime = { version = 'LuaJIT' }, + diagnostics = { globals = { 'vim' } }, + workspace = { + checkThirdParty = false, + library = { + vim.env.VIMRUNTIME, + vim.fn.stdpath('config'), + }, + }, + }, + } +}) +vim.lsp.enable('lua_ls') + +-- Bash +vim.lsp.config('bashls', { + cmd = { 'bash-language-server', 'start' }, + filetypes = { 'sh', 'bash' }, + root_markers = { '.git' }, + single_file_support = true, +}) +vim.lsp.enable('bashls') + +-- For all +vim.diagnostic.config({ + virtual_text = false, +}) diff --git a/nvim/lua/configs/lualine.lua b/nvim/lua/configs/lualine.lua new file mode 100644 index 0000000..e83b767 --- /dev/null +++ b/nvim/lua/configs/lualine.lua @@ -0,0 +1,54 @@ +require('lualine').setup { + options = { + icons_enabled = true, + theme = 'auto', + component_separators = { left = '', right = ''}, + section_separators = { left = '', right = ''}, + disabled_filetypes = { + statusline = {}, + winbar = {}, + }, + ignore_focus = {}, + always_divide_middle = true, + always_show_tabline = true, + globalstatus = false, + refresh = { + statusline = 1000, + tabline = 1000, + winbar = 1000, + refresh_time = 16, -- ~60fps + events = { + 'WinEnter', + 'BufEnter', + 'BufWritePost', + 'SessionLoadPost', + 'FileChangedShellPost', + 'VimResized', + 'Filetype', + 'CursorMoved', + 'CursorMovedI', + 'ModeChanged', + }, + } + }, + sections = { + lualine_a = {'mode'}, + lualine_b = {'branch', 'diff', 'diagnostics'}, + lualine_c = {'filename'}, + lualine_x = {'fileformat', 'filetype'}, + lualine_y = {'lsp_status'}, + lualine_z = {'location'} + }, + inactive_sections = { + lualine_a = {}, + lualine_b = {}, + lualine_c = {'filename'}, + lualine_x = {'location'}, + lualine_y = {}, + lualine_z = {} + }, + tabline = {}, + winbar = {}, + inactive_winbar = {}, + extensions = {} +} diff --git a/nvim/lua/configs/luasnip.lua b/nvim/lua/configs/luasnip.lua new file mode 100644 index 0000000..f6f61c0 --- /dev/null +++ b/nvim/lua/configs/luasnip.lua @@ -0,0 +1,23 @@ +-- vscode format +require("luasnip.loaders.from_vscode").lazy_load { exclude = vim.g.vscode_snippets_exclude or {} } +require("luasnip.loaders.from_vscode").lazy_load { paths = vim.g.vscode_snippets_path or "" } + +-- snipmate format +require("luasnip.loaders.from_snipmate").load() +require("luasnip.loaders.from_snipmate").lazy_load { paths = vim.g.snipmate_snippets_path or "" } + +-- lua format +require("luasnip.loaders.from_lua").load() +require("luasnip.loaders.from_lua").lazy_load { paths = vim.g.lua_snippets_path or "" } + +-- fix luasnip #258 +vim.api.nvim_create_autocmd("InsertLeave", { + callback = function() + if + require("luasnip").session.current_nodes[vim.api.nvim_get_current_buf()] + and not require("luasnip").session.jump_active + then + require("luasnip").unlink_current() + end + end, +}) diff --git a/nvim/lua/configs/nvimtree.lua b/nvim/lua/configs/nvimtree.lua new file mode 100644 index 0000000..64e57e8 --- /dev/null +++ b/nvim/lua/configs/nvimtree.lua @@ -0,0 +1,32 @@ +return { + filters = { dotfiles = false }, + disable_netrw = true, + hijack_cursor = true, + sync_root_with_cwd = true, + update_focused_file = { + enable = true, + update_root = false, + }, + view = { + width = 30, + preserve_window_proportions = true, + }, + renderer = { + root_folder_label = false, + highlight_git = true, + indent_markers = { enable = true }, + icons = { + glyphs = { + default = "󰈚", + folder = { + default = "", + empty = "", + empty_open = "", + open = "", + symlink = "", + }, + git = { unmerged = "" }, + }, + }, + }, +} diff --git a/nvim/lua/configs/telescope.lua b/nvim/lua/configs/telescope.lua new file mode 100644 index 0000000..7e7c475 --- /dev/null +++ b/nvim/lua/configs/telescope.lua @@ -0,0 +1,22 @@ +return { + defaults = { + prompt_prefix = "  ", + selection_caret = " ", + entry_prefix = " ", + sorting_strategy = "ascending", + layout_config = { + horizontal = { + prompt_position = "top", + preview_width = 0.55, + }, + width = 0.87, + height = 0.80, + }, + mappings = { + n = { ["q"] = require("telescope.actions").close }, + }, + }, + + extensions_list = { "themes", "terms" }, + extensions = {}, +} diff --git a/nvim/lua/configs/treesitter.lua b/nvim/lua/configs/treesitter.lua new file mode 100644 index 0000000..7a7b1f9 --- /dev/null +++ b/nvim/lua/configs/treesitter.lua @@ -0,0 +1,47 @@ +return { + ensure_installed = { + "bash", + "c", + "cpp", + "cmake", + "diff", + "doxygen", + "git_config", + "gitcommit", + "gitignore", + "html", + "javadoc", + "javascript", + "jsdoc", + "json", + "jsonc", + "lua", + "luadoc", + "luap", + "make", + "markdown", + "markdown_inline", + "meson", + "printf", + "python", + "query", + "regex", + "sql", + "toml", + "tsx", + "typescript", + "vim", + "vimdoc", + "xml", + "yaml", + }, + + highlight = { + enable = true, + use_languagetree = true, + }, + + indent = { + enable = true, + }, +} diff --git a/nvim/lua/configs/ufo.lua b/nvim/lua/configs/ufo.lua new file mode 100644 index 0000000..f542c31 --- /dev/null +++ b/nvim/lua/configs/ufo.lua @@ -0,0 +1,19 @@ +vim.o.foldcolumn = '1' +vim.o.foldlevel = 99 +vim.o.foldlevelstart = 99 +vim.o.foldenable = true + +vim.keymap.set('n', 'zR', require('ufo').openAllFolds) +vim.keymap.set('n', 'zM', require('ufo').closeAllFolds) +vim.keymap.set('n', 'zP', function () + local winid = require('ufo').peekFoldedLinesUnderCursor() + if not winid then + vim.lsp.buf.hover() + end +end, {desc = "Peek folder"}) + +require("ufo").setup({ + provider_selector = function (bufnr, filetype, buftype) + return { 'lsp', 'indent' } + end +}) diff --git a/nvim/lua/custom/init.lua b/nvim/lua/custom/init.lua index ae11a42..0d181f2 100644 --- a/nvim/lua/custom/init.lua +++ b/nvim/lua/custom/init.lua @@ -1,4 +1,8 @@ --- форматирование при сохранении для C/C++ +-- ========== Formating =========== -- +require("telescope").load_extension("noice") +require("telescope.themes").get_dropdown() + +-- ========== Formating =========== -- vim.api.nvim_create_autocmd("BufWritePre", { pattern = { "*.c", "*.cpp", "*.h", "*.hpp" }, callback = function() @@ -6,15 +10,14 @@ vim.api.nvim_create_autocmd("BufWritePre", { end, }) --- настройки clipboard -vim.g.clipboard = { - name = 'OSC 52', - copy = { - ['+'] = require('vim.ui.clipboard.osc52').copy('+'), - ['*'] = require('vim.ui.clipboard.osc52').copy('*'), - }, - paste = { - ['+'] = require('vim.ui.clipboard.osc52').paste('+'), - ['*'] = require('vim.ui.clipboard.osc52').paste('*'), - }, -} +-- ========== Formating =========== -- +vim.o.clipboard ="unnamedplus" +vim.api.nvim_create_autocmd("TextYankPost", { + callback = function() + local copy_to_unnamedplus = require("vim.ui.clipboard.osc52").copy("+") + copy_to_unnamedplus(vim.v.event.regcontents) + local copy_to_unnamed = require("vim.ui.clipboard.osc52").copy("*") + copy_to_unnamed(vim.v.event.regcontents) + end, +}) + diff --git a/nvim/lua/mappings.lua b/nvim/lua/mappings.lua index 0147a14..649d6f6 100644 --- a/nvim/lua/mappings.lua +++ b/nvim/lua/mappings.lua @@ -1,13 +1,10 @@ -require "nvchad.mappings" --- add yours here - local map = vim.keymap.set +-- ========== Basics =========== -- map("n", ";", ":", { desc = "CMD enter command mode" }) map("i", "jk", "") --- map({ "n", "i", "v" }, "", " w ") --- Debbuger mappings +-- ========== Debug =========== -- map('n', 'db', 'DapToggleBreakpoint', { desc = 'Toggle breakpoint' }) map('n', 'dr', 'DapContinue', { desc = 'Start/continue debug' }) map('n', 'ds', 'DapStepOver', { desc = 'Step over' }) @@ -16,14 +13,65 @@ map('n', 'do', 'DapStepOut', { desc = 'Step out' }) map('n', 'dq', 'DapTerminate', { desc = 'Stop debug' }) map('n', 'du', 'lua require("dapui").toggle()', { desc = 'Toggle DAP UI' }) --- LSP +-- ========== LSP =========== -- map('n', 'lo', 'lua vim.diagnostic.open_float()', { noremap = true, silent = true, desc = 'Open diagnostic' }) map('n', '[l', 'DapContinue', { noremap = true, silent = true, desc = 'Go to prev diagnostic' }) map('n', ']l', 'DapStepOver', { noremap = true, silent = true, desc = 'Go to next diagnostic' }) map('n', 'lt', 'DapStepInto', { noremap = true, silent = true, desc = 'Open toggle' }) +map("n", "ds", vim.diagnostic.setloclist, { desc = "LSP diagnostic loclist" }) +map("n", "", "noh", { desc = "general clear highlights" }) --- Tabs +-- ========== Tabs ========== -- map('n', 'tn', ':tabnew', { noremap = true, silent = true, desc = 'Open new tab' }) map('n', 'tc', ':tabclose', { noremap = true, silent = true, desc = 'Close this tab' }) map('n', 'tl', ':tabnext', { noremap = true, silent = true, desc = 'Go to next tab' }) map('n', 'th', ':tabprevious', { noremap = true, silent = true, desc = 'Go to previous tab' }) + +-- ========== Sessions ============= -- +map("n", "ss", ":SessionSave", {noremap = true, silent = true}) +map("n", "sl", ":SessionLoad", {noremap = true, silent = true}) +map("n", "st", ":Telescope persisted", {noremap = true, silent = true}) + +-- ========== Window moves ============= -- +map("n", "", "h", { desc = "switch window left" }) +map("n", "", "l", { desc = "switch window right" }) +map("n", "", "j", { desc = "switch window down" }) +map("n", "", "k", { desc = "switch window up" }) + +-- ========== Line moves ============= -- +map("i", "", "^i", { desc = "move beginning of line" }) +map("i", "", "", { desc = "move end of line" }) +map("i", "", "", { desc = "move left" }) +map("i", "", "", { desc = "move right" }) +map("i", "", "", { desc = "move down" }) +map("i", "", "", { desc = "move up" }) + +-- ========== Comments ============= -- +map("n", "/", "gcc", { desc = "toggle comment", remap = true }) +map("v", "/", "gc", { desc = "toggle comment", remap = true }) + +-- ========== Nvim-tree ============= -- +map("n", "", "NvimTreeToggle", { desc = "nvimtree toggle window" }) +map("n", "e", "NvimTreeFocus", { desc = "nvimtree focus window" }) + +-- ========== Telescope ============= -- +map("n", "fw", "Telescope live_grep", { desc = "telescope live grep" }) +map("n", "fb", "Telescope buffers", { desc = "telescope find buffers" }) +map("n", "fh", "Telescope help_tags", { desc = "telescope help page" }) +map("n", "ma", "Telescope marks", { desc = "telescope find marks" }) +map("n", "fo", "Telescope oldfiles", { desc = "telescope find oldfiles" }) +map("n", "fz", "Telescope current_buffer_fuzzy_find", { desc = "telescope find in current buffer" }) +map("n", "cm", "Telescope git_commits", { desc = "telescope git commits" }) +map("n", "gt", "Telescope git_status", { desc = "telescope git status" }) +map("n", "pt", "Telescope terms", { desc = "telescope pick hidden term" }) +map("n", "ff", "Telescope find_files", { desc = "telescope find files" }) +map("n", "fa", "Telescope find_files follow=true no_ignore=true hidden=true", { desc = "telescope find all files" }) + +-- ========== Which-key ============= -- +map("n", "wK", "WhichKey ", { desc = "whichkey all keymaps" }) + +-- ========== Buffers ============= -- +map("n", "x", "bp | sp | bn | bd", {desc = "Close buffer"}) +map("n", "e", "enew", {desc = "Create buffer"}) +map("n", "", "BufferLineCycleNext", {desc = "Go to next buffer"}) +map("n", "", "BufferLineCyclePrev", {desc = "Go to prev buffer"}) diff --git a/nvim/lua/options.lua b/nvim/lua/options.lua index 738f20b..47c9476 100644 --- a/nvim/lua/options.lua +++ b/nvim/lua/options.lua @@ -1,6 +1,57 @@ -require "nvchad.options" +local opt = vim.opt +local o = vim.o +local g = vim.g --- add yours here! +-------------------------------------- options ------------------------------------------ +o.laststatus = 3 +o.showmode = false +o.splitkeep = "screen" --- local o = vim.o --- o.cursorlineopt ='both' -- to enable cursorline! +o.clipboard = "unnamedplus" +o.cursorline = true +o.cursorlineopt = "number" + +-- Indenting +o.expandtab = true +o.shiftwidth = 2 +o.smartindent = true +o.tabstop = 2 +o.softtabstop = 2 + +opt.fillchars = { eob = " " } +o.ignorecase = true +o.smartcase = true +o.mouse = "a" + +-- Numbers +o.number = true +o.numberwidth = 2 +o.ruler = false + +-- disable nvim intro +opt.shortmess:append "sI" + +o.signcolumn = "yes" +o.splitbelow = true +o.splitright = true +o.timeoutlen = 400 +o.undofile = true + +-- interval for writing swap file to disk, also used by gitsigns +o.updatetime = 250 + +-- go to previous/next line with h,l,left arrow and right arrow +-- when cursor reaches end/beginning of line +opt.whichwrap:append "<>[]hl" + +-- disable some default providers +g.loaded_node_provider = 0 +g.loaded_python3_provider = 0 +g.loaded_perl_provider = 0 +g.loaded_ruby_provider = 0 + +-- add binaries installed by mason.nvim to path +local is_windows = vim.fn.has "win32" ~= 0 +local sep = is_windows and "\\" or "/" +local delim = is_windows and ";" or ":" +vim.env.PATH = table.concat({ vim.fn.stdpath "data", "mason", "bin" }, sep) .. delim .. vim.env.PATH diff --git a/nvim/lua/plugins/common.lua b/nvim/lua/plugins/common.lua new file mode 100644 index 0000000..d14d593 --- /dev/null +++ b/nvim/lua/plugins/common.lua @@ -0,0 +1,73 @@ +return { + -- Dev icons + { + "nvim-tree/nvim-web-devicons", + opts = {}, + }, + -- Marks + { + "chentoast/marks.nvim", + event = "VeryLazy", + opts = {}, + }, + -- Gitsigns + { + "lewis6991/gitsigns.nvim", + event = {"BufReadPre", "BufNewFile"}, + opts = function () + require("configs.gitsigns") + end + }, + -- Theme + { + "xiantang/darcula-dark.nvim", + dependencies = { + "nvim-treesitter/nvim-treesitter", + }, + }, + -- Nvim tree + { + "nvim-tree/nvim-tree.lua", + cmd = {'NvimTreeToggle', 'NvimTreeFocus'}, + opts = function () + require("configs.nvimtree") + end, + }, + -- Pairs + { + 'nvim-mini/mini.pairs', + event = {"BufReadPre", "BufNewFile"}, + opts = { + modes = { insert = true, command = true, terminal = false }, + skip_next = [=[[%w%%%'%[%"%.%`%$]]=], + skip_ts = { "string" }, + skip_unbalanced = true, + markdown = true, + }, + }, + -- Formating + { + "stevearc/conform.nvim", + event = 'BufWritePre', + config = function () + require("configs.nvimtree") + end, + }, + -- Yank Highlight + { + "machakann/vim-highlightedyank", + event = "VeryLazy", + }, + -- Sessions + { + "olimorris/persisted.nvim", + event = "BufReadPre", + opts = { + autostart = true, + autosave = true, + save_dir = vim.fn.expand(vim.fn.stdpath("data") .. "/sessions/"), + use_git_branch = true, + autoload = false, + }, + }, +} diff --git a/nvim/lua/plugins/dev.lua b/nvim/lua/plugins/dev.lua new file mode 100644 index 0000000..88743e5 --- /dev/null +++ b/nvim/lua/plugins/dev.lua @@ -0,0 +1,89 @@ +return { + -- Nvim lspconfig + { + "neovim/nvim-lspconfig", + config = function() + require "configs.lsp.lspconfig" + end, + }, + -- Mason + { + "mason-org/mason.nvim", + opts = {} + }, + -- Mason lspconfig + { + "mason-org/mason-lspconfig.nvim", + opts = {}, + dependencies = { + "mason-org/mason.nvim", + "neovim/nvim-lspconfig", + }, + }, + -- Nvim complete + { + "hrsh7th/nvim-cmp", + event = "InsertEnter", + dependencies = { + { + -- snippet plugin + "L3MON4D3/LuaSnip", + dependencies = "rafamadriz/friendly-snippets", + opts = { history = true, updateevents = "TextChanged,TextChangedI" }, + config = function(_, opts) + require("luasnip").config.set_config(opts) + require "configs.luasnip" + end, + }, + + -- autopairing of (){}[] etc + { + "windwp/nvim-autopairs", + opts = { + fast_wrap = {}, + disable_filetype = { "TelescopePrompt", "vim" }, + }, + config = function(_, opts) + require("nvim-autopairs").setup(opts) + + -- setup cmp for autopairs + local cmp_autopairs = require "nvim-autopairs.completion.cmp" + require("cmp").event:on("confirm_done", cmp_autopairs.on_confirm_done()) + end, + }, + + -- cmp sources plugins + { + "saadparwaiz1/cmp_luasnip", + "hrsh7th/cmp-nvim-lua", + "hrsh7th/cmp-nvim-lsp", + "hrsh7th/cmp-buffer", + "https://codeberg.org/FelipeLema/cmp-async-path.git" + } + }, + opts = function() + return require "configs.cmp" + end, + }, + -- Treesitter + { + "nvim-treesitter/nvim-treesitter", + event = { "BufReadPost", "BufNewFile" }, + cmd = { "TSInstall", "TSBufEnable", "TSBufDisable", "TSModuleInfo" }, + build = ":TSUpdate", + opts = function() + return require "configs.treesitter" + end, + config = function(_, opts) + require("nvim-treesitter.configs").setup(opts) + end, + }, + -- Ufo folders + { + 'kevinhwang91/nvim-ufo', + dependencies = 'kevinhwang91/promise-async', + event = "VeryLazy", + config = function () + end, + }, +} diff --git a/nvim/lua/plugins/lines.lua b/nvim/lua/plugins/lines.lua new file mode 100644 index 0000000..b476932 --- /dev/null +++ b/nvim/lua/plugins/lines.lua @@ -0,0 +1,17 @@ +return { + { + 'nvim-lualine/lualine.nvim', + dependencies = 'nvim-tree/nvim-web-devicons', + config = function () + require("configs.lualine") + end, + }, + { + 'akinsho/bufferline.nvim', + version = "*", + dependencies = 'nvim-tree/nvim-web-devicons', + config = function () + require("configs.bufferline") + end, + } +} diff --git a/nvim/lua/plugins/noice.lua b/nvim/lua/plugins/noice.lua new file mode 100644 index 0000000..66d2ed1 --- /dev/null +++ b/nvim/lua/plugins/noice.lua @@ -0,0 +1,30 @@ +return { + "folke/noice.nvim", + event = "VeryLazy", + opts = { + }, + dependencies = { + "MunifTanjim/nui.nvim", + "rcarriga/nvim-notify", + }, + config = { + lsp = { + signature = { + enabled = false, + }, + hover = { + enabled = false, + }, + override = { + ["vim.lsp.util.convert_input_to_markdown_lines"] = true, + ["vim.lsp.util.stylize_markdown"] = true, + ["cmp.entry.get_documentation"] = true, + }, + }, + presets = { + long_message_to_split = true, + inc_rename = false, + lsp_doc_border = false, + }, + } +} diff --git a/nvim/lua/plugins/snacks.lua b/nvim/lua/plugins/snacks.lua new file mode 100644 index 0000000..140ad26 --- /dev/null +++ b/nvim/lua/plugins/snacks.lua @@ -0,0 +1,19 @@ +return { + "folke/snacks.nvim", + priority = 1000, + lazy = false, + ---@type snacks.Config + opts = { + bigfile = { enabled = true }, + dashboard = { enabled = true }, + indent = { enabled = true }, + input = { enabled = true }, + picker = { enabled = true }, + notifier = { enabled = true }, + quickfile = { enabled = true }, + scope = { enabled = true }, + scroll = { enabled = true }, + statuscolumn = { enabled = true }, + words = { enabled = true }, + }, +} diff --git a/nvim/lua/plugins/telescope.lua b/nvim/lua/plugins/telescope.lua new file mode 100644 index 0000000..79ca9a8 --- /dev/null +++ b/nvim/lua/plugins/telescope.lua @@ -0,0 +1,9 @@ +return { + 'nvim-telescope/telescope.nvim', + tag = '0.1.8', + dependencies = {'nvim-lua/plenary.nvim', 'nvim-treesitter/nvim-treesitter'}, + cmd = "Telescope", + configs =function () + return require("configs.telescope") + end, +} diff --git a/nvim/lua/plugins/whichkey.lua b/nvim/lua/plugins/whichkey.lua new file mode 100644 index 0000000..9400187 --- /dev/null +++ b/nvim/lua/plugins/whichkey.lua @@ -0,0 +1,67 @@ +return { + "folke/which-key.nvim", + event = "VeryLazy", + opts_extend = { "spec" }, + opts = { + preset = "helix", + defaults = {}, + spec = { + { + mode = { "n", "x" }, + { "", group = "tabs" }, + { "c", group = "code" }, + { "d", group = "debug" }, + { "dp", group = "profiler" }, + { "f", group = "file/find" }, + { "g", group = "git" }, + { "gh", group = "hunks" }, + { "q", group = "quit/session" }, + { "s", group = "search" }, + { "u", group = "ui" }, + { "x", group = "diagnostics/quickfix" }, + { "[", group = "prev" }, + { "]", group = "next" }, + { "g", group = "goto" }, + { "gs", group = "surround" }, + { "z", group = "fold" }, + { + "b", + group = "buffer", + expand = function() + return require("which-key.extras").expand.buf() + end, + }, + { + "w", + group = "windows", + proxy = "", + expand = function() + return require("which-key.extras").expand.win() + end, + }, + -- better descriptions + { "gx", desc = "Open with system app" }, + }, + }, + }, + keys = { + { + "?", + function() + require("which-key").show({ global = false }) + end, + desc = "Buffer Keymaps (which-key)", + }, + { + "", + function() + require("which-key").show({ keys = "", loop = true }) + end, + desc = "Window Hydra Mode (which-key)", + }, + }, + config = function(_, opts) + local wk = require("which-key") + wk.setup(opts) + end, +}