diff options
author | Gustaf Rydholm <gustaf.rydholm@gmail.com> | 2022-01-12 21:22:47 +0100 |
---|---|---|
committer | Gustaf Rydholm <gustaf.rydholm@gmail.com> | 2022-01-12 21:22:47 +0100 |
commit | 7cf73775036c3424dd5e2a85effe3883cf0b0ca8 (patch) | |
tree | 61d7584b44d0c8074676bb2a1cfba00dc3a6babc | |
parent | b42618906aad70a735ea9272403e5e2657230fcc (diff) |
Refactor the file structure
-rw-r--r-- | lua/config/autopairs.lua | 34 | ||||
-rw-r--r-- | lua/config/bufferline.lua | 167 | ||||
-rw-r--r-- | lua/config/cmp.lua (renamed from lua/plugins/config/cmp.lua) | 0 | ||||
-rw-r--r-- | lua/config/colorscheme.lua (renamed from lua/plugins/config/colorscheme.lua) | 0 | ||||
-rw-r--r-- | lua/config/comment.lua | 24 | ||||
-rw-r--r-- | lua/config/gitsigns.lua | 50 | ||||
-rw-r--r-- | lua/config/init.lua | 12 | ||||
-rw-r--r-- | lua/config/lsp/handlers.lua (renamed from lua/plugins/lsp/handlers.lua) | 0 | ||||
-rw-r--r-- | lua/config/lsp/init.lua (renamed from lua/plugins/lsp/init.lua) | 4 | ||||
-rw-r--r-- | lua/config/lsp/lsp-installer.lua (renamed from lua/plugins/lsp/lsp-installer.lua) | 0 | ||||
-rw-r--r-- | lua/config/lsp/settings/jsonls.lua (renamed from lua/plugins/lsp/settings/jsonls.lua) | 0 | ||||
-rw-r--r-- | lua/config/lsp/settings/pyright.lua (renamed from lua/plugins/lsp/settings/pyright.lua) | 0 | ||||
-rw-r--r-- | lua/config/lsp/settings/sumneko_lua.lua (renamed from lua/plugins/lsp/settings/sumneko_lua.lua) | 0 | ||||
-rw-r--r-- | lua/config/nvim-tree.lua | 100 | ||||
-rw-r--r-- | lua/config/telescope.lua (renamed from lua/plugins/config/telescope.lua) | 0 | ||||
-rw-r--r-- | lua/config/treesitter.lua (renamed from lua/plugins/config/treesitter.lua) | 3 | ||||
-rw-r--r-- | lua/installer.lua (renamed from lua/plugins/installer.lua) | 0 | ||||
-rw-r--r-- | lua/plugins.lua (renamed from lua/plugins/plugins.lua) | 17 | ||||
-rw-r--r-- | lua/plugins/config/init.lua | 6 |
19 files changed, 409 insertions, 8 deletions
diff --git a/lua/config/autopairs.lua b/lua/config/autopairs.lua new file mode 100644 index 0000000..027135b --- /dev/null +++ b/lua/config/autopairs.lua @@ -0,0 +1,34 @@ +-- Autopair for brackets and quote symbols. + +local status_ok, npairs = pcall(require, "nvim-autopairs") +if not status_ok then + return +end + +npairs.setup({ + check_ts = true, + ts_config = { + lua = { "string", "source" }, + javascript = { "string", "template_string" }, + java = false, + }, + disable_filetype = { "TelescopePrompt", "spectre_panel" }, + fast_wrap = { + map = "<M-e>", + chars = { "{", "[", "(", '"', "'" }, + pattern = string.gsub([[ [%'%"%)%>%]%)%}%,] ]], "%s+", ""), + offset = 0, -- Offset from pattern match + end_key = "$", + keys = "qwertyuiopzxcvbnmasdfghjkl", + check_comma = true, + highlight = "PmenuSel", + highlight_grey = "LineNr", + }, +}) + +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({ map_char = { tex = "" } })) diff --git a/lua/config/bufferline.lua b/lua/config/bufferline.lua new file mode 100644 index 0000000..1259af3 --- /dev/null +++ b/lua/config/bufferline.lua @@ -0,0 +1,167 @@ +-- Adds a bar that displays open buffers. + +local status_ok, bufferline = pcall(require, "bufferline") +if not status_ok then + return +end + +bufferline.setup({ + options = { + numbers = "none", -- | "ordinal" | "buffer_id" | "both" | function({ ordinal, id, lower, raise }): string, + close_command = "Bdelete! %d", -- can be a string | function, see "Mouse actions" + right_mouse_command = nil, -- can be a string | function, see "Mouse actions" + left_mouse_command = nil, -- can be a string | function, see "Mouse actions" + middle_mouse_command = nil, -- can be a string | function, see "Mouse actions" + -- NOTE: this plugin is designed with this icon in mind, + -- and so changing this is NOT recommended, this is intended + -- as an escape hatch for people who cannot bear it for whatever reason + indicator_icon = "▎", + buffer_close_icon = "", + modified_icon = "●", + close_icon = "", + left_trunc_marker = "", + right_trunc_marker = "", + --- name_formatter can be used to change the buffer's label in the bufferline. + --- Please note some names can/will break the + --- bufferline so use this at your discretion knowing that it has + --- some limitations that will *NOT* be fixed. + -- name_formatter = function(buf) -- buf contains a "name", "path" and "bufnr" + -- -- remove extension from markdown files for example + -- if buf.name:match('%.md') then + -- return vim.fn.fnamemodify(buf.name, ':t:r') + -- end + -- end, + max_name_length = 30, + max_prefix_length = 30, -- prefix used when a buffer is de-duplicated + tab_size = 21, + diagnostics = false, -- | "nvim_lsp" | "coc", + diagnostics_update_in_insert = false, + -- diagnostics_indicator = function(count, level, diagnostics_dict, context) + -- return "("..count..")" + -- end, + -- NOTE: this will be called a lot so don't do any heavy processing here + -- custom_filter = function(buf_number) + -- -- filter out filetypes you don't want to see + -- if vim.bo[buf_number].filetype ~= "<i-dont-want-to-see-this>" then + -- return true + -- end + -- -- filter out by buffer name + -- if vim.fn.bufname(buf_number) ~= "<buffer-name-I-dont-want>" then + -- return true + -- end + -- -- filter out based on arbitrary rules + -- -- e.g. filter out vim wiki buffer from tabline in your work repo + -- if vim.fn.getcwd() == "<work-repo>" and vim.bo[buf_number].filetype ~= "wiki" then + -- return true + -- end + -- end, + offsets = { { filetype = "NvimTree", text = "", padding = 1 } }, + show_buffer_icons = true, + show_buffer_close_icons = false, + show_close_icon = false, + show_tab_indicators = true, + persist_buffer_sort = true, -- whether or not custom sorted buffers should persist + -- can also be a table containing 2 custom separators + -- [focused and unfocused]. eg: { '|', '|' } + separator_style = "thin", -- | "thick" | "thin" | { 'any', 'any' }, + enforce_regular_tabs = true, + always_show_bufferline = true, + -- sort_by = 'id' | 'extension' | 'relative_directory' | 'directory' | 'tabs' | function(buffer_a, buffer_b) + -- -- add custom logic + -- return buffer_a.modified > buffer_b.modified + -- end + }, + highlights = { + fill = { + guifg = { attribute = "fg", highlight = "#ff0000" }, + guibg = { attribute = "bg", highlight = "TabLine" }, + }, + background = { + guifg = { attribute = "fg", highlight = "TabLine" }, + guibg = { attribute = "bg", highlight = "TabLine" }, + }, + + -- buffer_selected = { + -- guifg = {attribute='fg',highlight='#ff0000'}, + -- guibg = {attribute='bg',highlight='#0000ff'}, + -- gui = 'none' + -- }, + buffer_visible = { + guifg = { attribute = "fg", highlight = "TabLine" }, + guibg = { attribute = "bg", highlight = "TabLine" }, + }, + + close_button = { + guifg = { attribute = "fg", highlight = "TabLine" }, + guibg = { attribute = "bg", highlight = "TabLine" }, + }, + close_button_visible = { + guifg = { attribute = "fg", highlight = "TabLine" }, + guibg = { attribute = "bg", highlight = "TabLine" }, + }, + -- close_button_selected = { + -- guifg = {attribute='fg',highlight='TabLineSel'}, + -- guibg ={attribute='bg',highlight='TabLineSel'} + -- }, + + tab_selected = { + guifg = { attribute = "fg", highlight = "Normal" }, + guibg = { attribute = "bg", highlight = "Normal" }, + }, + tab = { + guifg = { attribute = "fg", highlight = "TabLine" }, + guibg = { attribute = "bg", highlight = "TabLine" }, + }, + tab_close = { + -- guifg = {attribute='fg',highlight='LspDiagnosticsDefaultError'}, + guifg = { attribute = "fg", highlight = "TabLineSel" }, + guibg = { attribute = "bg", highlight = "Normal" }, + }, + + duplicate_selected = { + guifg = { attribute = "fg", highlight = "TabLineSel" }, + guibg = { attribute = "bg", highlight = "TabLineSel" }, + gui = "italic", + }, + duplicate_visible = { + guifg = { attribute = "fg", highlight = "TabLine" }, + guibg = { attribute = "bg", highlight = "TabLine" }, + gui = "italic", + }, + duplicate = { + guifg = { attribute = "fg", highlight = "TabLine" }, + guibg = { attribute = "bg", highlight = "TabLine" }, + gui = "italic", + }, + + modified = { + guifg = { attribute = "fg", highlight = "TabLine" }, + guibg = { attribute = "bg", highlight = "TabLine" }, + }, + modified_selected = { + guifg = { attribute = "fg", highlight = "Normal" }, + guibg = { attribute = "bg", highlight = "Normal" }, + }, + modified_visible = { + guifg = { attribute = "fg", highlight = "TabLine" }, + guibg = { attribute = "bg", highlight = "TabLine" }, + }, + + separator = { + guifg = { attribute = "bg", highlight = "TabLine" }, + guibg = { attribute = "bg", highlight = "TabLine" }, + }, + separator_selected = { + guifg = { attribute = "bg", highlight = "Normal" }, + guibg = { attribute = "bg", highlight = "Normal" }, + }, + -- separator_visible = { + -- guifg = {attribute='bg',highlight='TabLine'}, + -- guibg = {attribute='bg',highlight='TabLine'} + -- }, + indicator_selected = { + guifg = { attribute = "fg", highlight = "LspDiagnosticsDefaultHint" }, + guibg = { attribute = "bg", highlight = "Normal" }, + }, + }, +}) diff --git a/lua/plugins/config/cmp.lua b/lua/config/cmp.lua index 27114ca..27114ca 100644 --- a/lua/plugins/config/cmp.lua +++ b/lua/config/cmp.lua diff --git a/lua/plugins/config/colorscheme.lua b/lua/config/colorscheme.lua index 5f0654d..5f0654d 100644 --- a/lua/plugins/config/colorscheme.lua +++ b/lua/config/colorscheme.lua diff --git a/lua/config/comment.lua b/lua/config/comment.lua new file mode 100644 index 0000000..740697e --- /dev/null +++ b/lua/config/comment.lua @@ -0,0 +1,24 @@ +-- Language aware commenting. + +local status_ok, comment = pcall(require, "Comment") +if not status_ok then + return +end + +comment.setup({ + pre_hook = function(ctx) + local U = require("Comment.utils") + + local location = nil + if ctx.ctype == U.ctype.block then + location = require("ts_context_commentstring.utils").get_cursor_location() + elseif ctx.cmotion == U.cmotion.v or ctx.cmotion == U.cmotion.V then + location = require("ts_context_commentstring.utils").get_visual_start_location() + end + + return require("ts_context_commentstring.internal").calculate_commentstring({ + key = ctx.ctype == U.ctype.line and "__default" or "__multiline", + location = location, + }) + end, +}) diff --git a/lua/config/gitsigns.lua b/lua/config/gitsigns.lua new file mode 100644 index 0000000..05aa495 --- /dev/null +++ b/lua/config/gitsigns.lua @@ -0,0 +1,50 @@ +-- Add git signs to source files. + +local status_ok, gitsigns = pcall(require, "gitsigns") +if not status_ok then + return +end + +gitsigns.setup({ + signs = { + add = { hl = "GitSignsAdd", text = "▎", numhl = "GitSignsAddNr", linehl = "GitSignsAddLn" }, + change = { hl = "GitSignsChange", text = "▎", numhl = "GitSignsChangeNr", linehl = "GitSignsChangeLn" }, + delete = { hl = "GitSignsDelete", text = "契", numhl = "GitSignsDeleteNr", linehl = "GitSignsDeleteLn" }, + topdelete = { hl = "GitSignsDelete", text = "契", numhl = "GitSignsDeleteNr", linehl = "GitSignsDeleteLn" }, + changedelete = { hl = "GitSignsChange", text = "▎", numhl = "GitSignsChangeNr", linehl = "GitSignsChangeLn" }, + }, + signcolumn = true, -- Toggle with `:Gitsigns toggle_signs` + numhl = false, -- Toggle with `:Gitsigns toggle_numhl` + linehl = false, -- Toggle with `:Gitsigns toggle_linehl` + word_diff = false, -- Toggle with `:Gitsigns toggle_word_diff` + watch_gitdir = { + interval = 1000, + follow_files = true, + }, + attach_to_untracked = true, + current_line_blame = false, -- Toggle with `:Gitsigns toggle_current_line_blame` + current_line_blame_opts = { + virt_text = true, + virt_text_pos = "eol", -- 'eol' | 'overlay' | 'right_align' + delay = 1000, + ignore_whitespace = false, + }, + current_line_blame_formatter_opts = { + relative_time = false, + }, + sign_priority = 6, + update_debounce = 100, + status_formatter = nil, -- Use default + max_file_length = 40000, + preview_config = { + -- Options passed to nvim_open_win + border = "single", + style = "minimal", + relative = "cursor", + row = 0, + col = 1, + }, + yadm = { + enable = false, + }, +}) diff --git a/lua/config/init.lua b/lua/config/init.lua new file mode 100644 index 0000000..31a1aa9 --- /dev/null +++ b/lua/config/init.lua @@ -0,0 +1,12 @@ +-- Loads all plugin configs. + +require("config.colorscheme") +require("config.cmp") +require("config.lsp") +require("config.telescope") +require("config.treesitter") +require("config.autopairs") +require("config.comment") +require("config.gitsigns") +require("config.nvim-tree") +require("config.bufferline") diff --git a/lua/plugins/lsp/handlers.lua b/lua/config/lsp/handlers.lua index 3dcf0dc..3dcf0dc 100644 --- a/lua/plugins/lsp/handlers.lua +++ b/lua/config/lsp/handlers.lua diff --git a/lua/plugins/lsp/init.lua b/lua/config/lsp/init.lua index 0b8db93..b231014 100644 --- a/lua/plugins/lsp/init.lua +++ b/lua/config/lsp/init.lua @@ -5,5 +5,5 @@ if not status_ok then return end -require("plugins.lsp.lsp-installer") -require("plugins.lsp.handlers").setup() +require("config.lsp.lsp-installer") +require("config.lsp.handlers").setup() diff --git a/lua/plugins/lsp/lsp-installer.lua b/lua/config/lsp/lsp-installer.lua index 876adad..876adad 100644 --- a/lua/plugins/lsp/lsp-installer.lua +++ b/lua/config/lsp/lsp-installer.lua diff --git a/lua/plugins/lsp/settings/jsonls.lua b/lua/config/lsp/settings/jsonls.lua index bcc5f65..bcc5f65 100644 --- a/lua/plugins/lsp/settings/jsonls.lua +++ b/lua/config/lsp/settings/jsonls.lua diff --git a/lua/plugins/lsp/settings/pyright.lua b/lua/config/lsp/settings/pyright.lua index d07ae8c..d07ae8c 100644 --- a/lua/plugins/lsp/settings/pyright.lua +++ b/lua/config/lsp/settings/pyright.lua diff --git a/lua/plugins/lsp/settings/sumneko_lua.lua b/lua/config/lsp/settings/sumneko_lua.lua index d7957c1..d7957c1 100644 --- a/lua/plugins/lsp/settings/sumneko_lua.lua +++ b/lua/config/lsp/settings/sumneko_lua.lua diff --git a/lua/config/nvim-tree.lua b/lua/config/nvim-tree.lua new file mode 100644 index 0000000..c48a8e4 --- /dev/null +++ b/lua/config/nvim-tree.lua @@ -0,0 +1,100 @@ +-- A file explorer. + +vim.g.nvim_tree_icons = { + default = "", + symlink = "", + git = { + unstaged = "", + staged = "S", + unmerged = "", + renamed = "➜", + deleted = "", + untracked = "U", + ignored = "◌", + }, + folder = { + default = "", + open = "", + empty = "", + empty_open = "", + symlink = "", + }, +} + +local status_ok, nvim_tree = pcall(require, "nvim-tree") +if not status_ok then + return +end + +local config_status_ok, nvim_tree_config = pcall(require, "nvim-tree.config") +if not config_status_ok then + return +end + +local tree_cb = nvim_tree_config.nvim_tree_callback + +nvim_tree.setup({ + disable_netrw = true, + hijack_netrw = true, + open_on_setup = false, + ignore_ft_on_setup = { + "startify", + "dashboard", + "alpha", + }, + auto_close = true, + open_on_tab = false, + hijack_cursor = false, + update_cwd = true, + update_to_buf_dir = { + enable = true, + auto_open = true, + }, + diagnostics = { + enable = true, + icons = { + hint = "", + info = "", + warning = "", + error = "", + }, + }, + update_focused_file = { + enable = true, + update_cwd = true, + ignore_list = {}, + }, + git = { + enable = true, + ignore = true, + timeout = 500, + }, + view = { + width = 30, + height = 30, + hide_root_folder = false, + side = "left", + auto_resize = true, + mappings = { + custom_only = false, + list = { + { key = { "l", "<CR>", "o" }, cb = tree_cb("edit") }, + { key = "h", cb = tree_cb("close_node") }, + { key = "v", cb = tree_cb("vsplit") }, + }, + }, + number = false, + relativenumber = false, + }, + quit_on_open = 0, + git_hl = 1, + disable_window_picker = 0, + root_folder_modifier = ":t", + show_icons = { + git = 1, + folders = 1, + files = 1, + folder_arrows = 1, + tree_width = 30, + }, +}) diff --git a/lua/plugins/config/telescope.lua b/lua/config/telescope.lua index ff65505..ff65505 100644 --- a/lua/plugins/config/telescope.lua +++ b/lua/config/telescope.lua diff --git a/lua/plugins/config/treesitter.lua b/lua/config/treesitter.lua index 8feffc9..0e1fe07 100644 --- a/lua/plugins/config/treesitter.lua +++ b/lua/config/treesitter.lua @@ -10,6 +10,9 @@ treesitter.setup({ ensure_installed = "maintained", sync_install = false, ignore_install = { "" }, -- List of parsers to ignore installing + autopairs = { + enable = true, + }, highlight = { enable = true, -- false will disable the whole extension disable = { "" }, -- list of language that will be disabled diff --git a/lua/plugins/installer.lua b/lua/installer.lua index 6c3b14a..6c3b14a 100644 --- a/lua/plugins/installer.lua +++ b/lua/installer.lua diff --git a/lua/plugins/plugins.lua b/lua/plugins.lua index 2998fb9..8789397 100644 --- a/lua/plugins/plugins.lua +++ b/lua/plugins.lua @@ -33,4 +33,21 @@ return { run = ":TSUpdate", }, + -- Autopairs -- + { "windwp/nvim-autopairs" }, -- Autopairs, integrates with both cmp and treesitter + + -- Comments -- + { "numToStr/Comment.nvim" }, -- Easily comment stuff + { "JoosepAlviste/nvim-ts-context-commentstring" }, + + -- Gitsigns -- + { "lewis6991/gitsigns.nvim" }, + + -- Nvim tree -- + { "kyazdani42/nvim-web-devicons" }, + { "kyazdani42/nvim-tree.lua" }, + + -- Buffer handler + { "akinsho/bufferline.nvim" }, + { "moll/vim-bbye" }, } diff --git a/lua/plugins/config/init.lua b/lua/plugins/config/init.lua deleted file mode 100644 index bfbf750..0000000 --- a/lua/plugins/config/init.lua +++ /dev/null @@ -1,6 +0,0 @@ --- Loads all plugin configs. - -require("plugins.config.colorscheme") -require("plugins.config.cmp") -require("plugins.config.telescope") -require("plugins.config.treesitter") |