From e056fe78a29edbe377445c0fcb5854bec122dee8 Mon Sep 17 00:00:00 2001 From: Aleksa Vučković Date: Tue, 18 Jan 2022 01:31:23 +0100 Subject: ccls fixed, bufferline, nvim-tree --- init.lua | 2 + lua/user/bufferline.lua | 167 +++++++++++++++++++++++++++++++++++++++++ lua/user/keymaps.lua | 15 ++-- lua/user/lsp/ccls.lua | 37 +++++++++ lua/user/lsp/init.lua | 2 +- lua/user/lsp/settings/ccls.lua | 34 --------- lua/user/nvim-tree.lua | 112 +++++++++++++++++++++++++++ 7 files changed, 328 insertions(+), 41 deletions(-) create mode 100644 lua/user/bufferline.lua create mode 100644 lua/user/lsp/ccls.lua delete mode 100644 lua/user/lsp/settings/ccls.lua create mode 100644 lua/user/nvim-tree.lua diff --git a/init.lua b/init.lua index ed12066..62b4a51 100644 --- a/init.lua +++ b/init.lua @@ -4,3 +4,5 @@ require "user.plugins" require "user.cmp" require "user.autopairs" require "user.lsp" +require "user.nvim-tree" +require "user.bufferline" diff --git a/lua/user/bufferline.lua b/lua/user/bufferline.lua new file mode 100644 index 0000000..74cdd33 --- /dev/null +++ b/lua/user/bufferline.lua @@ -0,0 +1,167 @@ +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 = "Bdelete! %d", -- can be a string | function, see "Mouse actions" + left_mouse_command = "buffer %d", -- 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 = "", + -- buffer_close_icon = '', + modified_icon = "●", + close_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 ~= "" then + -- return true + -- end + -- -- filter out by buffer name + -- if vim.fn.bufname(buf_number) ~= "" 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() == "" 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 = true, + show_close_icon = true, + 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/user/keymaps.lua b/lua/user/keymaps.lua index be9bb45..48aa005 100644 --- a/lua/user/keymaps.lua +++ b/lua/user/keymaps.lua @@ -25,6 +25,13 @@ keymap("n", "", "j", opts) keymap("n", "", "k", opts) keymap("n", "", "l", opts) +-- Navigate buffers +keymap("n", "", ":bnext", opts) +keymap("n", "", ":bprevious", opts) + +-- NvimTree +keymap("n", "e", ":NvimTreeToggle", opts) + -- Resize with arrows keymap("n", "", ":resize -2", opts) keymap("n", "", ":resize +2", opts) @@ -35,10 +42,6 @@ keymap("n", "", ":vertical resize +2", opts) keymap("n", "", ":bnext", opts) keymap("n", "", ":bprevious", opts) --- Move text up and down -keymap("n", "", ":m .+1==gi", opts) -keymap("n", "", ":m .-2==gi", opts) - -- Insert -- -- Press jk fast to enter -- keymap("i", "jk", "", opts) @@ -49,8 +52,8 @@ keymap("v", "<", "", ">gv", opts) -- Move text up and down -keymap("v", "", ":m .+1==", opts) -keymap("v", "", ":m .-2==", opts) +keymap("v", "", ":m .+1==gi", opts) +keymap("v", "", ":m .-2==gi", opts) keymap("v", "p", '"_dP', opts) -- Visual Block -- diff --git a/lua/user/lsp/ccls.lua b/lua/user/lsp/ccls.lua new file mode 100644 index 0000000..9127e5b --- /dev/null +++ b/lua/user/lsp/ccls.lua @@ -0,0 +1,37 @@ +local status, lspconfig = pcall(require, "lspconfig") +if not status then + return +end + + +vim.notify(vim.fn.expand('%:p')); +local extraArgs_opt = {}; + +if string.match(vim.fn.expand('%:p'),"/home/aleksa/mygit/mykernel/") then + extraArgs_opt = { "--sysroot=/opt/aleksa", "--gcc-toolchain=/opt/aleksa/usr/bin/i686-aleksa-gcc", }; +else +end + + +lspconfig.ccls.setup { + + on_attach = require("user.lsp.handlers").on_attach, + capabilities = require("user.lsp.handlers").capabilities, + + flags = { + debounce_text_changes = 150, + }; + init_options = { + compilationDatabaseDirectory = "build"; + cache = { + directory = "/tmp/ccls-cache"; + }; + index = { + threads = 0; + }; + clang = { + excludeArgs = { "-frounding-math"}; + extraArgs = extraArgs_opt; + } + }; +} diff --git a/lua/user/lsp/init.lua b/lua/user/lsp/init.lua index c218647..744c4ec 100644 --- a/lua/user/lsp/init.lua +++ b/lua/user/lsp/init.lua @@ -6,4 +6,4 @@ end require "user.lsp.lsp-installer" require("user.lsp.handlers").setup() -require "user.lsp.settings.ccls" +require "user.lsp.ccls" diff --git a/lua/user/lsp/settings/ccls.lua b/lua/user/lsp/settings/ccls.lua deleted file mode 100644 index f182d8a..0000000 --- a/lua/user/lsp/settings/ccls.lua +++ /dev/null @@ -1,34 +0,0 @@ -local status, lspconfig = pcall(require, "lspconfig") -if not status then - return -end - - -vim.notify(vim.fn.expand('%:p')); -local extraArgs_opt = {}; - -if string.match(vim.fn.expand('%:p'),"/home/aleksa/mygit/mykernel/") then - extraArgs_opt = { "--sysroot=/opt/aleksa", "--gcc-toolchain=/opt/aleksa/usr/bin/i686-aleksa-gcc", }; -else -end - - -lspconfig.ccls.setup { - on_attach = on_attach, - flags = { - debounce_text_changes = 150, - }; - init_options = { - compilationDatabaseDirectory = "build"; - cache = { - directory = "/tmp/ccls-cache"; - }; - index = { - threads = 0; - }; - clang = { - excludeArgs = { "-frounding-math"}; - extraArgs = extraArgs_opt; - } - }; -} diff --git a/lua/user/nvim-tree.lua b/lua/user/nvim-tree.lua new file mode 100644 index 0000000..abcdb49 --- /dev/null +++ b/lua/user/nvim-tree.lua @@ -0,0 +1,112 @@ +-- following options are the default +-- each of these are documented in `:help nvim-tree.OPTION_NAME` +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 = {}, + }, + system_open = { + cmd = nil, + args = {}, + }, + filters = { + dotfiles = false, + custom = {}, + }, + 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", "", "o" }, cb = tree_cb "edit" }, + { key = "h", cb = tree_cb "close_node" }, + { key = "v", cb = tree_cb "vsplit" }, + }, + }, + number = false, + relativenumber = false, + }, + trash = { + cmd = "trash", + require_confirm = true, + }, + 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, + }, +} -- cgit v1.2.3