From e8169ca91c167c48647e467565d3edf97361ecc2 Mon Sep 17 00:00:00 2001 From: fiplox Date: Sat, 31 Dec 2022 17:43:31 +0100 Subject: [PATCH] mv from dotfiles --- init.lua | 19 ++ lazy-lock.json | 32 +++ lua/config/autocmd.lua | 45 ++++ lua/config/lazy.lua | 31 +++ lua/config/mappings.lua | 95 +++++++ lua/config/plugins/autopairs.lua | 28 ++ lua/config/plugins/cmp.lua | 189 ++++++++++++++ lua/config/plugins/colorizer.lua | 23 ++ lua/config/plugins/feline.lua | 244 ++++++++++++++++++ lua/config/plugins/init.lua | 17 ++ lua/config/plugins/lsp/handlers.lua | 106 ++++++++ lua/config/plugins/lsp/init.lua | 152 +++++++++++ .../plugins/lsp/settings/sumneko_lua.lua | 21 ++ lua/config/plugins/mason.lua | 49 ++++ lua/config/plugins/mini.lua | 127 +++++++++ lua/config/plugins/null-ls.lua | 69 +++++ lua/config/plugins/telescope.lua | 112 ++++++++ lua/config/plugins/theme.lua | 14 + lua/config/plugins/toggleterm.lua | 47 ++++ lua/config/plugins/tresitter.lua | 50 ++++ lua/config/plugins/trouble.lua | 61 +++++ lua/config/plugins/which-key.lua | 138 ++++++++++ lua/config/settings.lua | 89 +++++++ 23 files changed, 1758 insertions(+) create mode 100644 init.lua create mode 100644 lazy-lock.json create mode 100644 lua/config/autocmd.lua create mode 100644 lua/config/lazy.lua create mode 100644 lua/config/mappings.lua create mode 100644 lua/config/plugins/autopairs.lua create mode 100644 lua/config/plugins/cmp.lua create mode 100644 lua/config/plugins/colorizer.lua create mode 100644 lua/config/plugins/feline.lua create mode 100644 lua/config/plugins/init.lua create mode 100644 lua/config/plugins/lsp/handlers.lua create mode 100644 lua/config/plugins/lsp/init.lua create mode 100644 lua/config/plugins/lsp/settings/sumneko_lua.lua create mode 100644 lua/config/plugins/mason.lua create mode 100644 lua/config/plugins/mini.lua create mode 100644 lua/config/plugins/null-ls.lua create mode 100644 lua/config/plugins/telescope.lua create mode 100644 lua/config/plugins/theme.lua create mode 100644 lua/config/plugins/toggleterm.lua create mode 100644 lua/config/plugins/tresitter.lua create mode 100644 lua/config/plugins/trouble.lua create mode 100644 lua/config/plugins/which-key.lua create mode 100644 lua/config/settings.lua diff --git a/init.lua b/init.lua new file mode 100644 index 0000000..9b2f8f7 --- /dev/null +++ b/init.lua @@ -0,0 +1,19 @@ +local lazypath = vim.fn.stdpath("data") .. "/lazy/lazy.nvim" +if not vim.loop.fs_stat(lazypath) then + vim.fn.system({ + "git", + "clone", + "--filter=blob:none", + "--single-branch", + "https://github.com/folke/lazy.nvim.git", + lazypath, + }) +end +vim.opt.runtimepath:prepend(lazypath) + +require 'config.settings' +require 'config.lazy' +require 'config.mappings' +require 'config.autocmd' + +vim.cmd 'colorscheme tokyonight' diff --git a/lazy-lock.json b/lazy-lock.json new file mode 100644 index 0000000..550b9ab --- /dev/null +++ b/lazy-lock.json @@ -0,0 +1,32 @@ +{ + "cmp-buffer": { "branch": "main", "commit": "3022dbc9166796b644a841a02de8dd1cc1d311fa" }, + "cmp-cmdline": { "branch": "main", "commit": "23c51b2a3c00f6abc4e922dbd7c3b9aca6992063" }, + "cmp-nvim-lsp": { "branch": "main", "commit": "59224771f91b86d1de12570b4070fe4ad7cd1eeb" }, + "cmp-path": { "branch": "main", "commit": "91ff86cd9c29299a64f968ebb45846c485725f23" }, + "cmp-snippy": { "branch": "master", "commit": "9af1635fe40385ffa3dabf322039cb5ae1fd7d35" }, + "feline.nvim": { "branch": "master", "commit": "d48b6f92c6ccdd6654c956f437be49ea160b5b0c" }, + "hop.nvim": { "branch": "master", "commit": "90db1b2c61b820e230599a04fedcd2679e64bd07" }, + "lazy.nvim": { "branch": "main", "commit": "8d452e37bbf16cfd8841cca4286c2b0f7c8db669" }, + "lazygit.nvim": { "branch": "main", "commit": "32bffdebe273e571588f25c8a708ca7297928617" }, + "lsp": { "branch": "master", "commit": "9c73b57ed03ad0a906e2cdc2fc348bf86ae53e3a" }, + "mason-lspconfig.nvim": { "branch": "main", "commit": "698713735933a5891080fc3d87a687f90b9d2aee" }, + "mason.nvim": { "branch": "main", "commit": "1592493e3406c271e9128b4d424731e25f1ff2a1" }, + "mini.nvim": { "branch": "main", "commit": "06eddfd8d6341e6c4f53ec9ae109a376a566329d" }, + "null-ls.nvim": { "branch": "main", "commit": "647a1eeeefc43ce15d941972642210637c370471" }, + "nvim-autopairs": { "branch": "master", "commit": "03580d758231956d33c8dd91e2be195106a79fa4" }, + "nvim-bqf": { "branch": "main", "commit": "b418b0a241d36509196944a6f6bee886c775d54f" }, + "nvim-cmp": { "branch": "main", "commit": "e55033fce468c9c578b946948807f2ac48a6ee08" }, + "nvim-colorizer.lua": { "branch": "master", "commit": "36c610a9717cc9ec426a07c8e6bf3b3abcb139d6" }, + "nvim-snippy": { "branch": "master", "commit": "47def62945611212a242657cc414dac91ca0453a" }, + "nvim-treesitter": { "branch": "master", "commit": "ee3e9f4dc0e5ee9e2bfb1ee47638375840b8fe0f" }, + "nvim-ts-context-commentstring": { "branch": "main", "commit": "32d9627123321db65a4f158b72b757bcaef1a3f4" }, + "nvim-web-devicons": { "branch": "master", "commit": "05e1072f63f6c194ac6e867b567e6b437d3d4622" }, + "plenary.nvim": { "branch": "master", "commit": "4b7e52044bbb84242158d977a50c4cbcd85070c7" }, + "telescope-file-browser.nvim": { "branch": "master", "commit": "eb4f026735f781ea5749331a5059021328d6eee8" }, + "telescope.nvim": { "branch": "master", "commit": "a606bd10c79ec5989c76c49cc6f736e88b63f0da" }, + "toggleterm.nvim": { "branch": "main", "commit": "b02a1674bd0010d7982b056fd3df4f717ff8a57a" }, + "tokyonight.nvim": { "branch": "main", "commit": "8a619f0cf3ed9051081d9fc0cd4f852a7355f546" }, + "trouble.nvim": { "branch": "main", "commit": "897542f90050c3230856bc6e45de58b94c700bbf" }, + "vim-snippets": { "branch": "master", "commit": "8c917944354552c1263159a4a218ad924969be0c" }, + "which-key.nvim": { "branch": "main", "commit": "8682d3003595017cd8ffb4c860a07576647cc6f8" } +} \ No newline at end of file diff --git a/lua/config/autocmd.lua b/lua/config/autocmd.lua new file mode 100644 index 0000000..60b5f59 --- /dev/null +++ b/lua/config/autocmd.lua @@ -0,0 +1,45 @@ +-- Use 'q' to quit from common plugins +vim.api.nvim_create_autocmd({ 'FileType' }, { + pattern = { 'qf', 'help', 'man', 'lspinfo', 'spectre_panel', 'lir' }, + callback = function() + vim.cmd [[ + nnoremap q :close + set nobuflisted + ]] + end, +}) + +-- use 2 spaces for cpp +vim.api.nvim_create_autocmd({ 'FileType' }, { + pattern = { 'cpp', 'cc', 'hpp', 'hh', 'md', 'markdown' }, + callback = function() + vim.opt.ts = 2 + vim.opt.sw = 2 + vim.opt.expandtab = true + end, +}) + +vim.cmd "autocmd BufEnter * ++nested if winnr('$') == 1 && bufname() == 'NvimTree_' . tabpagenr() | quit | endif" + +-- Fixes Autocomment +vim.api.nvim_create_autocmd({ 'BufWinEnter' }, { + callback = function() + vim.cmd 'set formatoptions-=cro' + end, +}) + +-- Highlight Yanked Text +vim.api.nvim_create_autocmd({ 'TextYankPost' }, { + callback = function() + vim.highlight.on_yank { higroup = 'Visual', timeout = 200 } + end, +}) + +vim.api.nvim_create_augroup('diagnostics', { clear = true }) + +vim.api.nvim_create_autocmd({ 'DiagnosticChanged' }, { + group = 'diagnostics', + callback = function() + vim.diagnostic.setloclist { open = false } + end, +}) diff --git a/lua/config/lazy.lua b/lua/config/lazy.lua new file mode 100644 index 0000000..7e84b2e --- /dev/null +++ b/lua/config/lazy.lua @@ -0,0 +1,31 @@ +require("lazy").setup("config.plugins", +{ + defaults = { lazy = true }, + checker = { enabled = false }, + diff = { + cmd = "terminal_git", + }, + change_detection = { + enabled = false + }, + performance = { + cache = { + enabled = true, + -- disable_events = {}, + }, + rtp = { + disabled_plugins = { + "gzip", + "matchit", + -- "matchparen", + "netrwPlugin", + "tarPlugin", + "tohtml", + "tutor", + "zipPlugin", + "nvim-treesitter-textobjects", + }, + }, + }, + debug = false, +}) diff --git a/lua/config/mappings.lua b/lua/config/mappings.lua new file mode 100644 index 0000000..bedc4d3 --- /dev/null +++ b/lua/config/mappings.lua @@ -0,0 +1,95 @@ +-- Set leader {{{ +vim.api.nvim_set_keymap('n', '', '', { noremap = true, silent = true }) +vim.g.mapleader = ' ' +-- }}} +-- resize {{{ +vim.api.nvim_set_keymap('n', '', 'resize -2', { noremap = true, silent = true }) +vim.api.nvim_set_keymap('n', '', 'resize +2', { noremap = true, silent = true }) +vim.api.nvim_set_keymap('n', '', 'vertical resize -2', { noremap = true, silent = true }) +vim.api.nvim_set_keymap('n', '', 'vertical resize -2', { noremap = true, silent = true }) +-- }}} +-- indent {{{ +vim.api.nvim_set_keymap('v', '<', '', '>gv', { noremap = true, silent = true }) +-- }}} +-- open/close folds with enter key {{{ +vim.api.nvim_set_keymap('n', '', "@=(foldlevel('.')?'za':\"\")", { noremap = true, silent = true }) +-- }}} +-- terminal {{{ +vim.api.nvim_set_keymap('n', '', 'ToggleTerm', { noremap = true, silent = true }) +vim.api.nvim_set_keymap('t', '', 'ToggleTerm', { noremap = true, silent = true }) +vim.api.nvim_set_keymap('v', '', 'ToggleTerm', { noremap = true, silent = true }) +vim.api.nvim_set_keymap('i', '', 'ToggleTerm', { noremap = true, silent = true }) +-- }}} +-- misc {{{ +vim.api.nvim_set_keymap('n', '', 'nohlsearch', { noremap = true, silent = true }) +vim.api.nvim_set_keymap('v', '', '"_dp', { noremap = true, silent = true }) +vim.api.nvim_set_keymap('x', 'E', ":move '<-2gv-gv", { noremap = true, silent = true }) +vim.api.nvim_set_keymap('x', 'N', ":move '>+1gv-gv", { noremap = true, silent = true }) +vim.api.nvim_set_keymap('n', '', 'z=1', { noremap = true, silent = true }) +-- vim.api.nvim_set_keymap( +-- 'n', +-- 'lf', +-- 'lua vim.lsp.buf.format { async = true }', +-- { noremap = true, silent = true } +-- ) + +-- }}} +-- vim.api.nvim_set_keymap("n", "", "", { noremap = true, silent = true }) + +vim.api.nvim_set_keymap('n', '', ':', { noremap = true }) +-- vim.api.nvim_set_keymap('n', ';', ':', { noremap = true }) +vim.api.nvim_set_keymap('n', 'rs', ':s///gI', { noremap = true }) +vim.api.nvim_set_keymap('n', 'rr', ':%s///gI', { noremap = true }) +vim.api.nvim_set_keymap('v', 'r', ':s///gI', { noremap = true }) + +vim.api.nvim_set_keymap('n', 'xl', 'TroubleToggle loclist', { silent = true, noremap = true }) +vim.api.nvim_set_keymap('n', 'xq', 'TroubleToggle quickfix', { silent = true, noremap = true }) +vim.api.nvim_set_keymap('n', 'gR', 'TroubleToggle lsp_references', { silent = true, noremap = true }) +vim.api.nvim_set_keymap('n', 'xx', 'TroubleToggle', { silent = true, noremap = true }) +vim.api.nvim_set_keymap( + 'n', + 'xw', + 'TroubleToggle workspace_diagnostics', + { silent = true, noremap = true } +) +vim.api.nvim_set_keymap( + 'n', + 'xd', + 'TroubleToggle document_diagnostics', + { silent = true, noremap = true } +) + +function MapDHM() + vim.api.nvim_set_keymap('n', 'i', 'l', { noremap = true }) + vim.api.nvim_set_keymap('n', 'n', 'j', { noremap = true }) + vim.api.nvim_set_keymap('n', 'e', 'k', { noremap = true }) + vim.api.nvim_set_keymap('v', 'i', 'l', { noremap = true }) + vim.api.nvim_set_keymap('v', 'n', 'j', { noremap = true }) + vim.api.nvim_set_keymap('v', 'e', 'k', { noremap = true }) + vim.api.nvim_set_keymap('n', 'l', 'i', { noremap = true }) + vim.api.nvim_set_keymap('n', 'N', 'J', { noremap = true }) + vim.api.nvim_set_keymap('n', 'j', 'n', { noremap = true }) + vim.api.nvim_set_keymap('n', 'J', 'N', { noremap = true }) + vim.api.nvim_set_keymap('n', '', 'I', { noremap = true }) +end + +function UnMapDHM() + vim.api.nvim_del_keymap('n', 'l') + vim.api.nvim_del_keymap('n', 'j') + vim.api.nvim_del_keymap('v', 'l') + vim.api.nvim_del_keymap('v', 'j') + vim.api.nvim_del_keymap('v', 'k') + vim.api.nvim_del_keymap('n', 'i') + vim.api.nvim_del_keymap('n', 'J') + vim.api.nvim_del_keymap('n', 'n') + vim.api.nvim_del_keymap('n', 'N') +end + +-- local handle = io.popen 'lsusb | grep -c Sofle' +-- local automap = handle:read '*n' +-- handle:close() + +-- if os.getenv("SSH_TTY") then +MapDHM() +-- end diff --git a/lua/config/plugins/autopairs.lua b/lua/config/plugins/autopairs.lua new file mode 100644 index 0000000..823be36 --- /dev/null +++ b/lua/config/plugins/autopairs.lua @@ -0,0 +1,28 @@ +local M = { + 'windwp/nvim-autopairs', + event = 'InsertEnter' +} + +function M.config() + local npairs = require 'nvim-autopairs' + + npairs.setup { + check_ts = true, -- treesitter integration + fast_wrap = { + map = '', + highlight = 'Search', + highlight_grey = 'Comment', + }, + map_c_w = true, + -- disable_filetype = { "TelescopePrompt" }, + } + + local cmp_autopairs = require 'nvim-autopairs.completion.cmp' + local cmp_status_ok, cmp = pcall(require, 'cmp') + if not cmp_status_ok then + return + end + cmp.event:on('confirm_done', cmp_autopairs.on_confirm_done {}) +end + +return M diff --git a/lua/config/plugins/cmp.lua b/lua/config/plugins/cmp.lua new file mode 100644 index 0000000..862c626 --- /dev/null +++ b/lua/config/plugins/cmp.lua @@ -0,0 +1,189 @@ +local M = { + 'hrsh7th/nvim-cmp', + lazy = false, + dependencies = { + 'hrsh7th/cmp-nvim-lsp', + 'hrsh7th/cmp-buffer', + 'hrsh7th/cmp-cmdline', + 'hrsh7th/cmp-path', + }, +} + +function M.config() + local cmp = require 'cmp' + local snippy = require 'snippy' + + local ELLIPSIS_CHAR = '…' + local MAX_LABEL_WIDTH = 20 + + --[[ local winhighlight = 'NormalFloat:Pmenu,NormalFloat:Pmenu,CursorLine:PmenuSel,Search:None' ]] + + local has_words_before = function() + local line, col = unpack(vim.api.nvim_win_get_cursor(0)) + return col ~= 0 and vim.api.nvim_buf_get_lines(0, line - 1, line, true)[1]:sub(col, col):match '%s' == nil + end + + cmp.setup { + view = { + entries = { + name = 'custom', -- can be "custom", "wildmenu" or "native" + -- separator = ' | ', + }, + }, + completion = { + autocomplete = false, + }, + snippet = { + expand = function(args) + require('snippy').expand_snippet(args.body) + end, + }, + window = { + --[[ completion = { + border = 'rounded', + winhighlight = winhighlight, + }, + documentation = { + border = 'rounded', + winhighlight = winhighlight, + }, ]] + completion = cmp.config.window.bordered(), + documentation = cmp.config.window.bordered(), + }, + experimental = { + ghost_text = true, + }, + formatting = { + fields = { 'menu', 'abbr', 'kind' }, + format = function(entry, item) + local menu_icon = { + nvim_lsp = 'λ', + snippy = '⋗', + buffer = 'Ω', + path = '🖫', + } + + item.menu = menu_icon[entry.source.name] + local label = item.abbr + local truncated_label = vim.fn.strcharpart(label, 0, MAX_LABEL_WIDTH) + if truncated_label ~= label then + item.abbr = truncated_label .. ELLIPSIS_CHAR + end + return item + end, + }, + mapping = { + [''] = cmp.mapping.select_prev_item(), + [''] = cmp.mapping.select_next_item(), + [''] = cmp.mapping(cmp.mapping.scroll_docs(-4), { 'i', 'c' }), + [''] = cmp.mapping(cmp.mapping.scroll_docs(4), { 'i', 'c' }), + [''] = cmp.mapping(cmp.mapping.complete(), { 'i', 'c' }), + [''] = cmp.mapping { + i = cmp.mapping.abort(), + c = cmp.mapping.close(), + }, + [''] = cmp.mapping.confirm { select = true }, + [''] = cmp.mapping(function(fallback) + if cmp.visible() then + cmp.select_next_item { behavior = cmp.SelectBehavior.Insert } + elseif snippy.can_expand_or_advance() then + snippy.expand_or_advance() + elseif has_words_before() then + cmp.complete() + else + fallback() + end + end, { 'i', 'c', 's' }), + + [''] = cmp.mapping(function(fallback) + if cmp.visible() then + cmp.select_prev_item { behavior = cmp.SelectBehavior.Insert } + elseif snippy.can_jump(-1) then + snippy.previous() + else + fallback() + end + end, { 'i', 's', 'c' }), + }, + sources = cmp.config.sources { + { name = 'nvim_lsp' }, + { name = 'snippy' }, + { name = 'buffer' }, + { name = 'path' }, + }, + } + + cmp.setup.cmdline(':', { + completion = { autocomplete = true }, + mapping = { + [''] = cmp.mapping(function(fallback) + if cmp.visible() then + cmp.select_next_item { behavior = cmp.SelectBehavior.Insert } + else + cmp.complete() + cmp.select_next_item { behavior = cmp.SelectBehavior.Insert } + end + end, { 'i', 's', 'c' }), + [''] = cmp.mapping(function(fallback) + if cmp.visible() then + cmp.select_prev_item { behavior = cmp.SelectBehavior.Insert } + else + cmp.complete() + end + end, { 'i', 's', 'c' }), + [''] = cmp.mapping { i = cmp.mapping.confirm { select = true } }, + }, + sources = { + { name = 'cmdline' }, + { name = 'path' }, + }, + view = { + entries = { name = 'wildmenu', separator = ' · ' }, + }, + }) + + cmp.setup.cmdline('/', { + completion = { autocomplete = true }, + sources = { + { + name = 'buffer', + }, + }, + view = { + entries = { name = 'wildmenu', separator = ' · ' }, + }, + }) + + local config = { + virtual_text = true, + signs = false, + underline = true, + update_in_insert = true, + severity_sort = true, + float = { + focusable = true, + style = 'minimal', + border = 'rounded', + source = 'always', + header = '', + prefix = '', + }, + } + vim.diagnostic.config(config) + + vim.lsp.handlers['textDocument/hover'] = vim.lsp.with(vim.lsp.handlers.hover, { + border = 'rounded', + }) + + vim.lsp.handlers['textDocument/signatureHelp'] = vim.lsp.with(vim.lsp.handlers.signature_help, { + border = 'rounded', + }) + + --[[ local on_references = vim.lsp.handlers['textDocument/references'] ]] + --[[ vim.lsp.handlers['textDocument/references'] = vim.lsp.with(on_references, { ]] + --[[ -- Use location list instead of quickfix list ]] + --[[ loclist = true, ]] + --[[ }) ]] +end + +return M diff --git a/lua/config/plugins/colorizer.lua b/lua/config/plugins/colorizer.lua new file mode 100644 index 0000000..8223fec --- /dev/null +++ b/lua/config/plugins/colorizer.lua @@ -0,0 +1,23 @@ +return { + 'NvChad/nvim-colorizer.lua', + event = 'BufReadPre', + config = { + filetypes = { '*', '!lazy' }, + buftype = { '*', '!prompt', '!nofile' }, + user_default_options = { + RGB = true, -- #RGB hex codes + RRGGBB = true, -- #RRGGBB hex codes #ffffff + names = false, -- "Name" codes like Blue + RRGGBBAA = true, -- #RRGGBBAA hex codes + AARRGGBB = false, -- 0xAARRGGBB hex codes + rgb_fn = true, -- CSS rgb() and rgba() functions + hsl_fn = true, -- CSS hsl() and hsla() functions + css = false, -- Enable all CSS features: rgb_fn, hsl_fn, names, RGB, RRGGBB + css_fn = true, -- Enable all CSS *functions*: rgb_fn, hsl_fn + -- Available modes: foreground, background + -- Available modes for `mode`: foreground, background, virtualtext + -- mode = "background", -- Set the display mode. + -- virtualtext = "■", + }, + }, +} diff --git a/lua/config/plugins/feline.lua b/lua/config/plugins/feline.lua new file mode 100644 index 0000000..718668c --- /dev/null +++ b/lua/config/plugins/feline.lua @@ -0,0 +1,244 @@ +local M = { + 'feline-nvim/feline.nvim', + -- lazy = false + event = 'UIEnter', + dependencies = { + 'nvim-tree/nvim-web-devicons', + }, +} + +function M.config() + local feline = require 'feline' + + local theme = { + fg = '#abb2bf', + bg = '#1e2024', + green = '#98c379', + yellow = '#e5c07b', + purple = '#c678dd', + orange = '#d19a66', + peanut = '#f6d5a4', + red = '#e06c75', + aqua = '#61afef', + darkblue = '#282c34', + dark_red = '#f75f5f', + } + + local vi_mode_colors = { + NORMAL = 'green', + OP = 'green', + INSERT = 'yellow', + VISUAL = 'purple', + LINES = 'orange', + BLOCK = 'dark_red', + REPLACE = 'red', + COMMAND = 'aqua', + } + + local c = { + vim_mode = { + provider = { + name = 'vi_mode', + opts = { + show_mode_name = true, + -- padding = "center", -- Uncomment for extra padding. + }, + }, + hl = function() + return { + fg = require('feline.providers.vi_mode').get_mode_color(), + bg = 'darkblue', + style = 'bold', + name = 'NeovimModeHLColor', + } + end, + left_sep = 'block', + right_sep = 'block', + }, + gitBranch = { + provider = 'git_branch', + hl = { + fg = 'peanut', + bg = 'darkblue', + style = 'bold', + }, + left_sep = 'block', + right_sep = 'block', + }, + gitDiffAdded = { + provider = 'git_diff_added', + hl = { + fg = 'green', + bg = 'darkblue', + }, + left_sep = 'block', + right_sep = 'block', + }, + gitDiffRemoved = { + provider = 'git_diff_removed', + hl = { + fg = 'red', + bg = 'darkblue', + }, + left_sep = 'block', + right_sep = 'block', + }, + gitDiffChanged = { + provider = 'git_diff_changed', + hl = { + fg = 'fg', + bg = 'darkblue', + }, + left_sep = 'block', + right_sep = 'right_filled', + }, + separator = { + provider = '', + }, + fileinfo = { + provider = { + name = 'file_info', + opts = { + type = 'relative-short', + }, + }, + hl = { + style = 'bold', + }, + left_sep = ' ', + right_sep = ' ', + }, + diagnostic_errors = { + provider = 'diagnostic_errors', + hl = { + fg = 'red', + }, + }, + diagnostic_warnings = { + provider = 'diagnostic_warnings', + hl = { + fg = 'yellow', + }, + }, + diagnostic_hints = { + provider = 'diagnostic_hints', + hl = { + fg = 'aqua', + }, + }, + diagnostic_info = { + provider = 'diagnostic_info', + }, + lsp_client_names = { + provider = 'lsp_client_names', + hl = { + fg = 'purple', + bg = 'darkblue', + style = 'bold', + }, + left_sep = 'left_filled', + right_sep = 'right_filled', + }, + file_type = { + provider = { + name = 'file_type', + opts = { + filetype_icon = true, + case = 'titlecase', + }, + }, + hl = { + fg = 'red', + bg = 'darkblue', + style = 'bold', + }, + left_sep = 'left_filled', + right_sep = 'block', + }, + file_encoding = { + provider = 'file_encoding', + hl = { + fg = 'orange', + bg = 'darkblue', + -- style = 'italic', + }, + left_sep = 'block', + right_sep = 'block', + }, + position = { + provider = 'position', + hl = { + fg = 'green', + bg = 'darkblue', + style = 'bold', + }, + left_sep = 'block', + right_sep = 'block', + }, + line_percentage = { + provider = 'line_percentage', + hl = { + fg = 'aqua', + bg = 'darkblue', + style = 'bold', + }, + left_sep = 'block', + right_sep = 'block', + }, + scroll_bar = { + provider = 'scroll_bar', + hl = { + fg = 'yellow', + style = 'bold', + }, + }, + } + + local left = { + c.vim_mode, + c.fileinfo, + -- c.gitBranch, + -- c.gitDiffAdded, + -- c.gitDiffRemoved, + -- c.gitDiffChanged, + -- c.separator, + c.diagnostic_errors, + c.diagnostic_warnings, + c.diagnostic_info, + c.diagnostic_hints, + } + + local middle = { + c.lsp_client_names, + c.separator, + } + + local right = { + c.file_type, + c.file_encoding, + c.position, + c.line_percentage, + c.scroll_bar, + } + + local components = { + active = { + left, + middle, + right, + }, + inactive = { + left, + middle, + right, + }, + } + + feline.setup { + components = components, + theme = theme, + vi_mode_colors = vi_mode_colors, + } +end + +return M diff --git a/lua/config/plugins/init.lua b/lua/config/plugins/init.lua new file mode 100644 index 0000000..f1664d2 --- /dev/null +++ b/lua/config/plugins/init.lua @@ -0,0 +1,17 @@ +return { + 'nvim-lua/plenary.nvim', + { 'honza/vim-snippets', lazy = false }, + { 'dcampos/nvim-snippy', lazy = false }, + { 'dcampos/cmp-snippy', lazy = false }, + { 'kdheepak/lazygit.nvim', cmd = 'LazyGit' }, + 'williamboman/mason-lspconfig.nvim', + { + 'phaazon/hop.nvim', + event = 'BufRead', + config = function() + require('hop').setup() + vim.api.nvim_set_keymap('n', 's', ':HopChar2', { silent = true }) + vim.api.nvim_set_keymap('n', 'S', ':HopWord', { silent = true }) + end, + }, +} diff --git a/lua/config/plugins/lsp/handlers.lua b/lua/config/plugins/lsp/handlers.lua new file mode 100644 index 0000000..f75612a --- /dev/null +++ b/lua/config/plugins/lsp/handlers.lua @@ -0,0 +1,106 @@ +local M = {} + +local cmp_nvim_lsp = require 'cmp_nvim_lsp' + +M.capabilities = vim.lsp.protocol.make_client_capabilities() +M.capabilities.textDocument.completion.completionItem.snippetSupport = true +-- M.capabilities.offsetEncoding = { "utf-16" } +M.capabilities = cmp_nvim_lsp.default_capabilities(M.capabilities) + +-- vim.cmd [[autocmd CursorHold,CursorHoldI * lua vim.diagnostic.open_float(nil, {focus=false, scope="cursor"})]] + +M.setup = function() + local config = { + virtual_text = true, + signs = false, + underline = true, + update_in_insert = true, + severity_sort = true, + float = { + focusable = true, + style = 'minimal', + border = 'rounded', + source = 'always', + header = '', + prefix = '', + }, + } + vim.diagnostic.config(config) + + vim.lsp.handlers['textDocument/hover'] = vim.lsp.with(vim.lsp.handlers.hover, { + border = 'rounded', + }) + + vim.lsp.handlers['textDocument/signatureHelp'] = vim.lsp.with(vim.lsp.handlers.signature_help, { + border = 'rounded', + }) + + --[[ local on_references = vim.lsp.handlers['textDocument/references'] ]] + --[[ vim.lsp.handlers['textDocument/references'] = vim.lsp.with(on_references, { ]] + --[[ -- Use location list instead of quickfix list ]] + --[[ loclist = true, ]] + --[[ }) ]] +end + +local function lsp_keymaps(bufnr) + local opts = { noremap = true, silent = true } + local keymap = vim.api.nvim_buf_set_keymap + keymap(bufnr, 'n', 'gD', 'lua vim.lsp.buf.declaration()', opts) + keymap(bufnr, 'n', 'gd', 'lua vim.lsp.buf.definition()', opts) + keymap(bufnr, 'n', 'K', 'lua vim.lsp.buf.hover()', opts) + keymap(bufnr, 'n', 'gI', 'lua vim.lsp.buf.implementation()', opts) + keymap(bufnr, 'n', 'gr', 'lua vim.lsp.buf.references()', opts) + keymap(bufnr, 'n', 'gl', 'lua vim.diagnostic.open_float()', opts) + keymap(bufnr, 'n', 'lf', 'lua vim.lsp.buf.format { async = true }', opts) + keymap(bufnr, 'n', 'li', 'LspInfo', opts) + keymap(bufnr, 'n', 'lI', 'LspInstallInfo', opts) + keymap(bufnr, 'n', 'la', 'lua vim.lsp.buf.code_action()', opts) + keymap(bufnr, 'n', 'lj', 'lua vim.diagnostic.goto_next({buffer=0})', opts) + keymap(bufnr, 'n', 'lk', 'lua vim.diagnostic.goto_prev({buffer=0})', opts) + keymap(bufnr, 'n', 'lr', 'lua vim.lsp.buf.rename()', opts) + keymap(bufnr, 'n', 'ls', 'lua vim.lsp.buf.signature_help()', opts) + keymap(bufnr, 'n', 'lq', 'lua vim.diagnostic.setloclist()', opts) + keymap(bufnr, 'n', 'e', 'lua vim.diagnostic.open_float()', opts) +end + +M.on_attach = function(client, bufnr) + --[[ vim.api.nvim_buf_set_option(bufnr, 'omnifunc', 'v:lua.vim.lsp.omnifunc') ]] + lsp_keymaps(bufnr) + if client.name == 'sumneko_lua' then + client.server_capabilities.documentFormattingProvider = false + end + if client.name == 'clangd' then + client.server_capabilities.documentFormattingProvider = false + end + if client.name == 'gopls' then + client.server_capabilities.documentFormattingProvider = false + end + if client.name == 'jdtls' then + client.server_capabilities.documentFormattingProvider = false + end + if client.name == 'jdt.ls' then + client.server_capabilities.documentFormattingProvider = false + vim.lsp.codelens.refresh() + if JAVA_DAP_ACTIVE then + require('jdtls').setup_dap { hotcodereplace = 'auto' } + require('jdtls.dap').setup_dap_main_class_configs() + end + end + local ft = vim.api.nvim_buf_get_option(bufnr, 'filetype') + local nls = require 'config.plugins.null-ls' + + local enable = false + if nls.has_formatter(ft) then + enable = client.name == 'null-ls' + else + enable = not (client.name == 'null-ls') + end + + if client.name == 'tsserver' then + enable = false + end + -- util.info(client.name .. " " .. (enable and "yes" or "no"), "format") + client.server_capabilities.documentFormattingProvider = enable +end + +return M diff --git a/lua/config/plugins/lsp/init.lua b/lua/config/plugins/lsp/init.lua new file mode 100644 index 0000000..41293c4 --- /dev/null +++ b/lua/config/plugins/lsp/init.lua @@ -0,0 +1,152 @@ +local M = { + 'neovim/nvim-lspconfig', + name = 'lsp', + event = 'BufReadPre', + dependencies = { 'hrsh7th/cmp-nvim-lsp' }, +} + +M.tools = { + 'clangd', + 'gopls', + 'sumneko_lua', +} + +function M.config() + require 'mason' + local lspconfig = require 'lspconfig' + local opts = {} + local cmp_nvim_lsp = require 'cmp_nvim_lsp' + local capabilities = vim.lsp.protocol.make_client_capabilities() + capabilities.textDocument.completion.completionItem.snippetSupport = true + capabilities = cmp_nvim_lsp.default_capabilities(capabilities) + + local function lsp_keymaps(bufnr) + local opt = { noremap = true, silent = true } + local keymap = vim.api.nvim_buf_set_keymap + keymap(bufnr, 'n', 'gD', 'lua vim.lsp.buf.declaration()', opt) + keymap(bufnr, 'n', 'gd', 'lua vim.lsp.buf.definition()', opt) + keymap(bufnr, 'n', 'K', 'lua vim.lsp.buf.hover()', opt) + keymap(bufnr, 'n', 'gI', 'lua vim.lsp.buf.implementation()', opt) + keymap(bufnr, 'n', 'gr', 'TroubleToggle lsp_references', opt) + keymap(bufnr, 'n', 'gl', 'lua vim.diagnostic.open_float()', opt) + keymap(bufnr, 'n', 'lf', 'lua vim.lsp.buf.format { async = true }', opt) + keymap(bufnr, 'n', 'li', 'LspInfo', opt) + keymap(bufnr, 'n', 'lI', 'LspInstallInfo', opt) + keymap(bufnr, 'n', 'la', 'lua vim.lsp.buf.code_action()', opt) + keymap(bufnr, 'n', 'lj', 'lua vim.diagnostic.goto_next({buffer=0})', opt) + keymap(bufnr, 'n', 'lk', 'lua vim.diagnostic.goto_prev({buffer=0})', opt) + keymap(bufnr, 'n', 'lr', 'lua vim.lsp.buf.rename()', opt) + keymap(bufnr, 'n', 'ls', 'lua vim.lsp.buf.signature_help()', opt) + keymap(bufnr, 'n', 'lq', 'lua vim.diagnostic.setloclist()', opt) + keymap(bufnr, 'n', 'e', 'lua vim.diagnostic.open_float()', opt) + end + + local on_attach = function(client, bufnr) + --[[ vim.api.nvim_buf_set_option(bufnr, 'omnifunc', 'v:lua.vim.lsp.omnifunc') ]] + lsp_keymaps(bufnr) + if client.name == 'sumneko_lua' then + client.server_capabilities.documentFormattingProvider = false + end + if client.name == 'clangd' then + client.server_capabilities.documentFormattingProvider = false + end + if client.name == 'gopls' then + client.server_capabilities.documentFormattingProvider = false + end + if client.name == 'jdtls' then + client.server_capabilities.documentFormattingProvider = false + end + if client.name == 'jdt.ls' then + client.server_capabilities.documentFormattingProvider = false + vim.lsp.codelens.refresh() + if JAVA_DAP_ACTIVE then + require('jdtls').setup_dap { hotcodereplace = 'auto' } + require('jdtls.dap').setup_dap_main_class_configs() + end + end + local ft = vim.api.nvim_buf_get_option(bufnr, 'filetype') + local nls = require 'config.plugins.null-ls' + + local enable = false + if nls.has_formatter(ft) then + enable = client.name == 'null-ls' + else + enable = not (client.name == 'null-ls') + end + + if client.name == 'tsserver' then + enable = false + end + -- util.info(client.name .. " " .. (enable and "yes" or "no"), "format") + client.server_capabilities.documentFormattingProvider = enable + end + for _, tool in ipairs(M.tools) do + opts = { + on_attach = on_attach, + capabilities = capabilities, + } + local server = vim.split(tool, '@')[1] + + if server == 'sumneko_lua' then + local sumneko_opts = require 'config.plugins.lsp.settings.sumneko_lua' + opts = vim.tbl_deep_extend('force', sumneko_opts, opts) + end + if server == 'clangd' then + local clangd_flags = { + '--all-scopes-completion', + '--suggest-missing-includes', + '--background-index', + '--pch-storage=disk', + '--cross-file-rename', + '--log=info', + '--completion-style=detailed', + '--enable-config', -- clangd 11+ supports reading from .clangd configuration file + '--clang-tidy', + -- "--clang-tidy-checks=-*,llvm-*,clang-analyzer-*,modernize-*,-modernize-use-trailing-return-type", + -- "--fallback-style=Google", + -- "--header-insertion=never", + -- "--query-driver=" + } + local clang_opts = { + arg = { unpack(clangd_flags) }, + } + opts = vim.tbl_deep_extend('force', clang_opts, opts) + end + lspconfig[server].setup(opts) + end + + local config = { + virtual_text = { + prefix = '●', + }, + signs = false, + underline = true, + update_in_insert = true, + severity_sort = true, + float = { + focusable = true, + style = 'minimal', + border = 'rounded', + source = 'always', + header = '', + prefix = '', + }, + } + vim.diagnostic.config(config) + + vim.lsp.handlers['textDocument/hover'] = vim.lsp.with(vim.lsp.handlers.hover, { + border = 'rounded', + }) + + vim.lsp.handlers['textDocument/signatureHelp'] = vim.lsp.with(vim.lsp.handlers.signature_help, { + border = 'rounded', + }) + + --[[ local on_references = vim.lsp.handlers['textDocument/references'] ]] + --[[ vim.lsp.handlers['textDocument/references'] = vim.lsp.with(on_references, { ]] + --[[ -- Use location list instead of quickfix list ]] + --[[ loclist = true, ]] + --[[ }) ]] +end + +return M diff --git a/lua/config/plugins/lsp/settings/sumneko_lua.lua b/lua/config/plugins/lsp/settings/sumneko_lua.lua new file mode 100644 index 0000000..8c669c3 --- /dev/null +++ b/lua/config/plugins/lsp/settings/sumneko_lua.lua @@ -0,0 +1,21 @@ +return { + flags = { + debounce_text_changes = 150, + }, + settings = { + Lua = { + diagnostics = { + globals = { 'vim' }, + }, + -- workspace = { + -- library = { + -- [vim.fn.expand '$VIMRUNTIME/lua'] = true, + -- [vim.fn.stdpath 'config' .. '/lua'] = true, + -- }, + -- }, + telemetry = { + enable = false, + }, + }, + }, +} diff --git a/lua/config/plugins/mason.lua b/lua/config/plugins/mason.lua new file mode 100644 index 0000000..89201ee --- /dev/null +++ b/lua/config/plugins/mason.lua @@ -0,0 +1,49 @@ +local M = { + 'williamboman/mason.nvim', +} + +M.tools = { + 'clang-format', + 'clangd', + 'gopls', + -- 'lua-language-server', + 'rust-analyzer', + 'prettierd', + -- 'stylua', + 'shellcheck', + 'shfmt', + 'black', +} + +function M.check() + local mr = require 'mason-registry' + for _, tool in ipairs(M.tools) do + local p = mr.get_package(tool) + if not p:is_installed() then + p:install() + end + end +end + +function M.config() + require('mason').setup { + settings = { + ui = { + border = 'rounded', + icons = { + package_installed = '◍', + package_pending = '◍', + package_uninstalled = '◍', + }, + }, + log_level = vim.log.levels.INFO, + max_concurrent_installers = 4, + }, + } + M.check() + require('mason-lspconfig').setup { + automatic_installation = false, + } +end + +return M diff --git a/lua/config/plugins/mini.lua b/lua/config/plugins/mini.lua new file mode 100644 index 0000000..897b439 --- /dev/null +++ b/lua/config/plugins/mini.lua @@ -0,0 +1,127 @@ +local mini = { + 'echasnovski/mini.nvim', + event = 'VeryLazy', +} + +local specs = { mini, 'JoosepAlviste/nvim-ts-context-commentstring' } + +function mini.surround() + require('mini.surround').setup { + mappings = { + add = 'gza', -- Add surrounding in Normal and Visual modes + delete = 'gzd', -- Delete surrounding + find = 'gzf', -- Find surrounding (to the right) + find_left = 'gzF', -- Find surrounding (to the left) + highlight = 'gzh', -- Highlight surrounding + replace = 'gzr', -- Replace surrounding + update_n_lines = 'gzn', -- Update `n_lines` + }, + } +end + +function mini.jump() + require('mini.jump').setup {} +end + +function mini.pairs() + require('mini.pairs').setup {} +end + +function mini.comment() + require('mini.comment').setup { + hooks = { + pre = function() + require('ts_context_commentstring.internal').update_commentstring {} + end, + }, + } +end + +function mini.ai() + local ai = require 'mini.ai' + require('mini.ai').setup { + n_lines = 500, + -- search_method = "cover_or_next", + custom_textobjects = { + o = ai.gen_spec.treesitter({ + a = { '@block.outer', '@conditional.outer', '@loop.outer' }, + i = { '@block.inner', '@conditional.inner', '@loop.inner' }, + }, {}), + f = ai.gen_spec.treesitter({ a = '@function.outer', i = '@function.inner' }, {}), + c = ai.gen_spec.treesitter({ a = '@class.outer', i = '@class.inner' }, {}), + }, + } + + local map = function(text_obj, desc) + for _, side in ipairs { 'left', 'right' } do + for dir, d in pairs { prev = '[', next = ']' } do + local lhs = d .. (side == 'right' and text_obj:upper() or text_obj:lower()) + for _, mode in ipairs { 'n', 'x', 'o' } do + vim.keymap.set(mode, lhs, function() + ai.move_cursor(side, 'a', text_obj, { search_method = dir }) + end, { + desc = dir .. ' ' .. desc, + }) + end + end + end + end + + map('f', 'function') + map('c', 'class') + map('o', 'block') +end + +function mini.config() + -- M.jump() + mini.surround() + -- mini.ai() + -- mini.pairs() + mini.comment() + mini.jump() + -- mini.animate() +end + +function mini.animate() + local mouse_scrolled = false + for _, scroll in ipairs { 'Up', 'Down' } do + local key = '' + vim.keymap.set('', key, function() + mouse_scrolled = true + return key + end, { remap = true, expr = true }) + end + + local animate = require 'mini.animate' + vim.go.winwidth = 20 + vim.go.winminwidth = 5 + + animate.setup { + resize = { + timing = animate.gen_timing.linear { duration = 50, unit = 'total' }, + }, + scroll = { + timing = animate.gen_timing.linear { duration = 100, unit = 'total' }, + subscroll = animate.gen_subscroll.equal { + predicate = function(total_scroll) + if mouse_scrolled then + mouse_scrolled = false + return false + end + return total_scroll > 1 + end, + }, + }, + } +end + +function mini.init() + vim.keymap.set('n', 'bd', function() + require('mini.bufremove').delete(0, false) + end) + vim.keymap.set('n', 'bD', function() + require('mini.bufremove').delete(0, true) + end) +end + +return specs diff --git a/lua/config/plugins/null-ls.lua b/lua/config/plugins/null-ls.lua new file mode 100644 index 0000000..6090071 --- /dev/null +++ b/lua/config/plugins/null-ls.lua @@ -0,0 +1,69 @@ +local M = { + 'jose-elias-alvarez/null-ls.nvim', +} + +function M.config() + local null_ls = require 'null-ls' + + -- https://github.com/jose-elias-alvarez/null-ls.nvim/tree/main/lua/null-ls/builtins/formatting + local formatting = null_ls.builtins.formatting + -- https://github.com/jose-elias-alvarez/null-ls.nvim/tree/main/lua/null-ls/builtins/diagnostics + local diagnostics = null_ls.builtins.diagnostics + + null_ls.setup { + debug = false, + on_init = function(new_client, _) + new_client.offset_encoding = 'utf-16' + end, + sources = { + formatting.prettier.with { extra_args = { '--no-semi', '--single-quote', '--jsx-single-quote' } }, + formatting.black.with { extra_args = { '--fast' } }, + formatting.stylua.with { extra_args = { '--quote-style=AutoPreferSingle', '--call-parentheses=None' } }, + formatting.clang_format.with { + filetypes = { 'c' }, + extra_args = { + '--style', + '{AccessModifierOffset : -2, AllowShortIfStatementsOnASingleLine : Never, AlignConsecutiveMacros : true, AllowShortLoopsOnASingleLine : false, AlwaysBreakTemplateDeclarations : true, Standard : c++20, NamespaceIndentation : All, IndentWidth : 4, TabWidth : 4, BreakBeforeBraces : Linux, AllowShortFunctionsOnASingleLine : Empty, AllowShortBlocksOnASingleLine : Never, FixNamespaceComments : true, PointerAlignment : Right, ColumnLimit : 120, ContinuationIndentWidth : 2, UseTab : Always }', + }, + }, + formatting.clang_format.with { + filetypes = { 'cpp' }, + extra_args = { + '--style', + 'google', + }, + }, + formatting.beautysh, + formatting.google_java_format, + formatting.goimports, + formatting.gofumpt, + formatting.sql_formatter, + diagnostics.golangci_lint.with { + extra_args = { + '-E', + 'revive', + '-E', + 'errcheck', + '-E', + 'gosec', + '-E', + 'nilerr', + '-E', + 'nlreturn', + }, + }, + formatting.asmfmt.with { + filetypes = { 'asm', 's' }, + }, + -- diagnostics.flake8 + }, + } +end + +function M.has_formatter(ft) + local sources = require 'null-ls.sources' + local available = sources.get_available(ft, 'NULL_LS_FORMATTING') + return #available > 0 +end + +return M diff --git a/lua/config/plugins/telescope.lua b/lua/config/plugins/telescope.lua new file mode 100644 index 0000000..2bb3c8c --- /dev/null +++ b/lua/config/plugins/telescope.lua @@ -0,0 +1,112 @@ +local function project_files() + local opts = {} + if vim.loop.fs_stat '.git' then + opts.show_untracked = true + require('telescope.builtin').git_files(opts) + else + local client = vim.lsp.get_active_clients()[1] + if client then + opts.cwd = client.config.root_dir + end + -- require('telescope.builtin').find_files(opts) + require('telescope').extensions.file_browser.file_browser() + end +end + +local M = { + 'nvim-telescope/telescope.nvim', + cmd = { 'Telescope' }, + keys = { + { '', project_files, desc = 'Find File' }, + }, + dependencies = { + 'nvim-telescope/telescope-file-browser.nvim', + }, +} + +function M.config() + local telescope = require 'telescope' + local actions = require 'telescope.actions' + local previewers = require 'telescope.previewers' + local Job = require 'plenary.job' + local new_maker = function(filepath, bufnr, opts) + filepath = vim.fn.expand(filepath) + Job:new({ + command = 'file', + args = { '--mime-type', '-b', filepath }, + on_exit = function(j) + local mime_type = vim.split(j:result()[1], '/')[1] + if mime_type == 'text' then + previewers.buffer_previewer_maker(filepath, bufnr, opts) + else + -- maybe we want to write something to the buffer here + vim.schedule(function() + vim.api.nvim_buf_set_lines(bufnr, 0, -1, false, { 'BINARY' }) + end) + end + end, + }):sync() + end + + -- local fb_actions = require "telescope".extensions.file_browser.actions + telescope.setup { + extensions = { + file_browser = { + theme = 'ivy', + -- disables netrw and use telescope-file-browser in its place + hijack_netrw = true, + mappings = { + ['i'] = { + }, + ['n'] = { + -- your custom normal mode mappings + }, + }, + }, + }, + pickers = { + find_files = { + theme = 'dropdown', + }, + live_grep = { + theme = 'dropdown', + }, + buffers = { + theme = 'dropdown', + }, + }, + defaults = { + layout_config = { + vertical = { width = 0.5 }, + -- other layout configuration here + }, + buffer_previewer_maker = new_maker, + prompt_prefix = ' ', + selection_caret = ' ', + path_display = { 'smart' }, + file_ignore_patterns = { '.git/', 'node_modules' }, + + mappings = { + i = { + [''] = actions.move_selection_next, + [''] = actions.move_selection_previous, + [''] = actions.cycle_history_next, + [''] = actions.cycle_history_prev, + [''] = actions.close, + }, + }, + vimgrep_arguments = { + 'rg', + '--color=never', + '--no-heading', + '--with-filename', + '--line-number', + '--column', + '--smart-case', + '--trim', -- add this value + }, + }, + } +end + +return M diff --git a/lua/config/plugins/theme.lua b/lua/config/plugins/theme.lua new file mode 100644 index 0000000..a9e25ec --- /dev/null +++ b/lua/config/plugins/theme.lua @@ -0,0 +1,14 @@ +local M = { + 'folke/tokyonight.nvim', + lazy = true, -- make sure we load this during startup if it is your main colorscheme + priority = 1000, -- make sure to load this before all the other start plugins +} + +function M.config() + require('tokyonight').setup { + transparent = true, + style = 'night', -- The theme comes in three styles, `storm`, `moon`, a darker variant `night` and `day` + } +end + +return M diff --git a/lua/config/plugins/toggleterm.lua b/lua/config/plugins/toggleterm.lua new file mode 100644 index 0000000..3a03035 --- /dev/null +++ b/lua/config/plugins/toggleterm.lua @@ -0,0 +1,47 @@ +local M = { + 'akinsho/toggleterm.nvim', + cmd = 'ToggleTerm', +} + +function M.config() + local toggleterm = require 'toggleterm' + + toggleterm.setup { + -- size can be a number or function which is passed the current terminal + size = function(term) + if term.direction == 'horizontal' then + return 15 + elseif term.direction == 'vertical' then + return vim.o.columns * 0.4 + end + end, + shade_filetypes = { 'none', 'fzf' }, + open_mapping = [[]], + hide_numbers = true, -- hide the number column in toggleterm buffers + shade_terminals = true, + shading_factor = '2', -- the degree by which to darken to terminal colour, default: 1 for dark backgrounds, 3 for light + start_in_insert = true, + insert_mappings = true, -- whether or not the open mapping applies in insert mode + persist_size = true, + direction = 'float', -- 'vertical' | 'horizontal' | 'window' | 'float', + close_on_exit = true, -- close the terminal window when the process exits + shell = vim.o.shell, -- change the default shell + -- This field is only relevant if direction is set to 'float' + float_opts = { + -- The border key is *almost* the same as 'nvim_win_open' + -- see :h nvim_win_open for details on borders however + -- the 'curved' border is a custom border type + -- not natively supported but implemented in this plugin. + border = 'curved', -- | 'double' | 'shadow' | 'curved' --| ... other options supported by win open + width = 100, + height = 30, + winblend = 0, + highlights = { + border = 'Normal', + background = 'Normal', + }, + }, + } +end + +return M diff --git a/lua/config/plugins/tresitter.lua b/lua/config/plugins/tresitter.lua new file mode 100644 index 0000000..c235897 --- /dev/null +++ b/lua/config/plugins/tresitter.lua @@ -0,0 +1,50 @@ +local M = { + 'nvim-treesitter/nvim-treesitter', + -- lazy = false, + event = 'BufReadPost', +} + +function M.config() + local configs = require 'nvim-treesitter.configs' + + configs.setup { + ensure_installed = { + 'bash', + 'c', + 'cpp', + 'go', + 'javascript', + 'typescript', + 'json', + 'lua', + 'python', + 'rust', + 'html', + 'css', + 'toml', + 'latex', + 'markdown', + 'vim', + 'dot', + }, + ignore_install = { 'haskell' }, + -- matchup = { + -- enable = true -- mandatory, false will disable the whole extension + -- -- disable = { "c", "ruby" }, -- optional, list of language that will be disabled + -- }, + highlight = { + enable = true, -- false will disable the whole extension + disable = { 'html' }, + }, + context_commentstring = { enable = true, config = { css = '// %s' } }, + -- indent = {enable = true, disable = {"python", "html", "javascript"}}, + -- TODO seems to be broken + indent = { enable = true, disable = { 'python', 'css' } }, + autotag = { enable = true }, + autopairs = { + enable = true, + }, + } +end + +return M diff --git a/lua/config/plugins/trouble.lua b/lua/config/plugins/trouble.lua new file mode 100644 index 0000000..93b4a29 --- /dev/null +++ b/lua/config/plugins/trouble.lua @@ -0,0 +1,61 @@ +local M = { + 'folke/trouble.nvim', + dependencies = { + 'nvim-tree/nvim-web-devicons', + }, + cmd = { 'TroubleToggle', 'Trouble' }, +} + +function M.config() + local trouble = require 'trouble' + + trouble.setup { + position = 'bottom', -- position of the list can be: bottom, top, left, right + height = 10, -- height of the trouble list when position is top or bottom + width = 50, -- width of the list when position is left or right + icons = true, -- use devicons for filenames + mode = 'document_diagnostics', -- "workspace_diagnostics", "document_diagnostics", "quickfix", "lsp_references", "loclist" + fold_open = '', -- icon used for open folds + fold_closed = '', -- icon used for closed folds + group = true, -- group results by file + padding = true, -- add an extra new line on top of the list + action_keys = { -- key mappings for actions in the trouble list + -- map to {} to remove a mapping, for example: + -- close = {}, + close = 'q', -- close the list + cancel = '', -- cancel the preview and get back to your last window / buffer / cursor + refresh = 'r', -- manually refresh + jump_close = { '', '' }, -- jump to the diagnostic or open / close folds + open_split = { '' }, -- open buffer in new split + open_vsplit = { '' }, -- open buffer in new vsplit + open_tab = { '' }, -- open buffer in new tab + jump = { 'o' }, -- jump to the diagnostic and close the list + toggle_mode = 'm', -- toggle between "workspace" and "document" diagnostics mode + toggle_preview = 'P', -- toggle auto_preview + hover = 'K', -- opens a small popup with the full multiline message + preview = 'p', -- preview the diagnostic location + close_folds = { 'zM', 'zm' }, -- close all folds + open_folds = { 'zR', 'zr' }, -- open all folds + toggle_fold = { 'zA', 'za' }, -- toggle fold of current file + previous = 'k', -- preview item + next = 'j', -- next item + }, + indent_lines = true, -- add an indent guide below the fold icons + auto_open = false, -- automatically open the list when you have diagnostics + auto_close = false, -- automatically close the list when you have no diagnostics + auto_preview = false, -- automatically preview the location of the diagnostic. to close preview and go back to last window + auto_fold = false, -- automatically fold a file trouble list at creation + auto_jump = { 'lsp_definitions' }, -- for the given modes, automatically jump if there is only a single result + signs = { + -- icons / text used for a diagnostic + error = '', + warning = '', + hint = '', + information = '', + other = '﫠', + }, + use_diagnostic_signs = false, -- enabling this will use the signs defined in your lsp client + } +end + +return M diff --git a/lua/config/plugins/which-key.lua b/lua/config/plugins/which-key.lua new file mode 100644 index 0000000..1c4c8c4 --- /dev/null +++ b/lua/config/plugins/which-key.lua @@ -0,0 +1,138 @@ +local M = { + 'folke/which-key.nvim', + lazy = false, + -- event = "VeryLazy", +} + +function M.config() + local wk = require 'which-key' + + -- which-key {{{ + wk.setup { + plugins = { + marks = true, -- shows a list of your marks on ' and ` + registers = true, -- shows your registers on " in NORMAL or in INSERT mode + -- the presets plugin, adds help for a bunch of default keybindings in Neovim + -- No actual key bindings are created + presets = { + operators = true, -- adds help for operators like d, y, ... + motions = true, -- adds help for motions + text_objects = false, -- help for text objects triggered after entering an operator + windows = true, -- default bindings on + nav = true, -- misc bindings to work with windows + z = true, -- bindings for folds, spelling and others prefixed with z + g = true, -- bindings for prefixed with g + }, + }, + icons = { + breadcrumb = '»', -- symbol used in the command line area that shows your active key combo + separator = '➜ ', -- symbol used between a key and it's label + group = '+', -- symbol prepended to a group + }, + window = { + border = 'none', -- none, single, double, shadow + position = 'bottom', -- bottom, top + margin = { 1, 0, 1, 0 }, -- extra window margin [top, right, bottom, left] + padding = { 1, 1, 1, 1 }, -- extra window padding [top, right, bottom, left] + }, + layout = { + height = { min = 4, max = 25 }, -- min and max height of the columns + width = { min = 20, max = 50 }, -- min and max width of the columns + spacing = 3, -- spacing between columns + }, + hidden = { '', '', '', '', 'call', 'lua', '^:', '^ ' }, -- hide mapping boilerplate + show_help = true, -- show help message on the command line when the popup is visible + } + + local opts = { + mode = 'n', -- NORMAL mode + prefix = '', + buffer = nil, -- Global mappings. Specify a buffer number for buffer local mappings + silent = true, -- use `silent` when creating keymaps + noremap = true, -- use `noremap` when creating keymaps + nowait = false, -- use `nowait` when creating keymaps + } + -- }}} + -- leader mappings {{{ + -- TODO create entire treesitter section + local mappings = { + ['rr'] = 'Search and replace all', + ['rs'] = 'Search and replace', + -- ["b"] = {"FindrBuffers", "List buffers"}, + ['k'] = { 'bd!', 'Kill buffer' }, + ['n'] = { 'bn', 'Next buffer' }, + ['p'] = { 'bp', 'Next buffer' }, + ['h'] = { 'TSBufToggle highlight', 'Enable TS highlight' }, + -- ['t'] = { 'ToggleTerm direction=horizontal', 'HTerminal' }, + ['T'] = { 'ToggleTerm direction=vertical', 'VTerminal' }, + ['D'] = 'Type definition', + ['rn'] = 'Rename', + ['ca'] = 'Code action', + ['1'] = { 'b 1', 'Buffer 1' }, + ['2'] = { 'b 2', 'Buffer 2' }, + ['3'] = { 'b 3', 'Buffer 3' }, + ['4'] = { 'b 4', 'Buffer 4' }, + ['5'] = { 'b 5', 'Buffer 5' }, + ['g'] = { 'LazyGit', 'Lazygit' }, + l = { + name = 'LSP', + f = 'Format', + i = 'Lsp Info', + I = 'Lsp Install Info', + a = 'Code action', + j = 'Next diagnostic', + k = 'Prev diagnostic', + r = 'Rename', + s = 'Signature Help', + q = 'Set LocList', + }, + [''] = { + name = 'Tab', + n = { 'tabnew', 'New' }, + p = { 'tabp', 'Previous' }, + d = { 'tabclose', 'Close' }, + [''] = { 'tabnext', 'Next' }, + ['1'] = { '1gt', 'Go to tab 1' }, + ['2'] = { '2gt', 'Go to tab 2' }, + ['3'] = { '3gt', 'Go to tab 3' }, + ['4'] = { '4gt', 'Go to tab 4' }, + ['5'] = { '5gt', 'Go to tab 5' }, + ['6'] = { '6gt', 'Go to tab 6' }, + ['7'] = { '7gt', 'Go to tab 7' }, + ['8'] = { '8gt', 'Go to tab 8' }, + ['9'] = { '9gt', 'Go to tab 9' }, + }, + w = { + name = 'Window', + v = { 'v', 'Vertical split' }, + h = { 's', 'Horizontal split' }, + a = 'Add workspace folder', + r = 'Remove workspace folder', + l = 'List workspace folders', + }, + t = { + name = 'Telescope', + f = { 'Telescope find_files', 'Files' }, + g = { 'Telescope live_grep', 'Grep' }, + b = { 'Telescope buffers', 'Buffers' }, + t = { 'Telescope', 'Pickers' }, + r = { 'Telescope lsp_references', 'Lsp references' }, + }, + -- d = { + -- name = 'DAP', + -- b = { "lua require'dap'.toggle_breakpoint()", 'Toggle breakpoint' }, + -- c = { "lua require'dap'.continue()", 'Continue' }, + -- i = { "lua require'dap'.step_into()", 'Step into' }, + -- o = { "lua require'dap'.step_over()", 'Step over' }, + -- O = { "lua require'dap'.step_out()", 'Step out' }, + -- r = { "lua require'dap'.repl_toggle()", 'Toggle repl' }, + -- l = { "lua require'dap'.run_last()", 'Run last' }, + -- u = { "lua require'dapui'.toggle()", 'UI' }, + -- t = { "lua require'dap'.terminate()", 'Terminate' }, + -- }, + } + -- }}} + wk.register(mappings, opts) +end + +return M diff --git a/lua/config/settings.lua b/lua/config/settings.lua new file mode 100644 index 0000000..8e2f881 --- /dev/null +++ b/lua/config/settings.lua @@ -0,0 +1,89 @@ +local g = vim.g +local opt = vim.opt +local function add(value, str, sep) + sep = sep or ',' + str = str or '' + value = type(value) == 'table' and table.concat(value, sep) or value + return str ~= '' and table.concat({ value, str }, sep) or value +end +-- local disabled_built_ins = { +-- -- 'netrw', +-- -- 'netrwPlugin', +-- -- 'netrwSettings', +-- -- 'netrwFileHandlers', +-- -- 'getscript', +-- -- 'getscriptPlugin', +-- 'vimball', +-- 'vimballPlugin', +-- '2html_plugin', +-- 'logipat', +-- 'rrhelper', +-- -- 'spellfile_plugin', +-- 'matchit', +-- } +-- for _, plugin in pairs(disabled_built_ins) do +-- g['loaded_' .. plugin] = 1 +-- end + +-- Globals {{{ +-- g.do_filetype_lua = 1 +-- g.did_load_filetypes = 0 +g.netrw_liststyle = 1 +g.netrw_banner = 0 +g.mapleader = ' ' +g.tex_flavor = 'latex' +-- }}} +-- Opts {{{ +-- opt.formatoptions = "" +opt.termguicolors = true +opt.guifont = 'JetBrainsMono Nerd Font' +opt.guicursor = 'n-v-c-sm:hor20,i-ci-ve:ver20,r-cr-o:Block' +opt.mouse = 'vn' +opt.path = '.,,**h' +opt.pumheight = 10 +opt.fileencoding = 'utf-8' +--opt.cmdheight = 2 " More space for displaying messages +opt.splitbelow = true +opt.splitright = true +opt.ts = 4 +opt.sw = 4 +opt.smartindent = true +--opt.expandtab " Converts tabs to spaces +opt.showmode = false +opt.undofile = true +opt.updatetime = 300 +opt.backup = false +opt.clipboard:prepend { 'unnamedplus' } +opt.smartcase = true +opt.cursorline = true +opt.viewoptions = 'folds,cursor' +opt.sessionoptions = 'folds' +opt.foldmethod = 'marker' +opt.foldlevel = 0 +opt.number = true +opt.hidden = true +--opt.shortmess+ = c " Don't pass messages to ins-completion-menu. +opt.scrolloff = 15 +opt.iskeyword:prepend { '-' } +opt.inccommand = 'nosplit' +opt.completeopt = { 'menu', 'menuone', 'noselect' } +opt.timeoutlen = 300 +opt.conceallevel = 0 +opt.concealcursor = 'n' +opt['foldenable'] = false +-- opt.fillchars = 'vert:▏' +opt.fillchars.eob = ' ' +-- opt.fillchars.vert="▏" +opt.sessionoptions = add { 'options', 'resize', 'winpos', 'terminal' } +opt.autochdir = false +-- }}} +-- Commands and autocommands {{{ +vim.api.nvim_create_user_command('Pdf', '!pandoc % -o %:r.pdf', { nargs = 0 }) +vim.api.nvim_create_user_command('Slide', '!pandoc -t beamer % -o %:r.pdf', { nargs = 0 }) +vim.api.nvim_create_user_command('Cd', 'lcd %:p:h', { nargs = 0 }) + +vim.api.nvim_create_autocmd({ 'BufReadPost' }, { pattern = { '*' }, command = 'silent! g`"zz' }) +vim.api.nvim_create_autocmd({ 'BufWinLeave' }, { pattern = { '?*' }, command = 'mkview' }) +vim.api.nvim_create_autocmd({ 'BufReadPost' }, { pattern = { '?*' }, command = 'silent! loadview' }) +-- }}} +