From 606b0572d2cd4e1a1820aa9d20fb4571ababe306 Mon Sep 17 00:00:00 2001 From: PeteChu Date: Thu, 6 Apr 2023 01:29:34 +0700 Subject: [PATCH] Add bufferline options to always show the bufferline, use ordinal numbers, and sort by insert position in the current setup --- after/plugin/defaults.lua | 2 ++ after/plugin/grep.vim | 17 ++++++++++++++++ after/plugin/nvim-tree.lua | 9 ++++----- after/plugin/quickloc-fix.lua | 32 ++----------------------------- init.lua | 2 +- lua/custom/plugins/bufferline.lua | 2 ++ 6 files changed, 28 insertions(+), 36 deletions(-) create mode 100644 after/plugin/grep.vim diff --git a/after/plugin/defaults.lua b/after/plugin/defaults.lua index 44a578c5..c10e22fe 100644 --- a/after/plugin/defaults.lua +++ b/after/plugin/defaults.lua @@ -10,3 +10,5 @@ vim.opt.scrolloff = 8 vim.opt.colorcolumn = "80" vim.opt.swapfile = false + +vim.o.cmdheight = 2 diff --git a/after/plugin/grep.vim b/after/plugin/grep.vim new file mode 100644 index 00000000..a6ea06bb --- /dev/null +++ b/after/plugin/grep.vim @@ -0,0 +1,17 @@ +set grepprg=rg\ --vimgrep + +function! Grep(...) + return system(join([&grepprg] + [expandcmd(join(a:000, ' '))], ' ')) +endfunction + +command! -nargs=+ -complete=file_in_path -bar Grep cgetexpr Grep() +command! -nargs=+ -complete=file_in_path -bar LGrep lgetexpr Grep() + +cnoreabbrev grep (getcmdtype() ==# ':' && getcmdline() ==# 'grep') ? 'Grep' : 'grep' +cnoreabbrev lgrep (getcmdtype() ==# ':' && getcmdline() ==# 'lgrep') ? 'LGrep' : 'lgrep' + +augroup quickfix + autocmd! + autocmd QuickFixCmdPost cgetexpr TroubleToggle quickfix + autocmd QuickFixCmdPost lgetexpr TroubleToggle loclist +augroup END diff --git a/after/plugin/nvim-tree.lua b/after/plugin/nvim-tree.lua index 7e0ef1be..d9547473 100644 --- a/after/plugin/nvim-tree.lua +++ b/after/plugin/nvim-tree.lua @@ -1,5 +1,4 @@ local function open_nvim_tree(data) - -- buffer is a real file on the disk local real_file = vim.fn.filereadable(data.file) == 1 @@ -18,8 +17,8 @@ end -- vim.api.nvim_create_autocmd({ "VimEnter" }, { callback = open_nvim_tree }) -- Auto close -vim.api.nvim_create_autocmd({"QuitPre"}, { - callback = function() vim.cmd("NvimTreeClose") end, +vim.api.nvim_create_autocmd({ "QuitPre" }, { + callback = function() vim.cmd("NvimTreeClose") end, }) -- Go to last used hidden buffer when deleting a buffer @@ -32,9 +31,9 @@ vim.api.nvim_create_autocmd("BufEnter", { -- Required to let the close event complete. An error is thrown without this. vim.defer_fn(function() -- close nvim-tree: will go to the last hidden buffer used before closing - api.tree.toggle({find_file = true, focus = true}) + api.tree.toggle({ find_file = true, focus = true }) -- re-open nivm-tree - api.tree.toggle({find_file = true, focus = true}) + api.tree.toggle({ find_file = true, focus = true }) -- nvim-tree is still the active window. Go to the previous window. vim.cmd("wincmd p") end, 0) diff --git a/after/plugin/quickloc-fix.lua b/after/plugin/quickloc-fix.lua index 3856a111..a0b7d11c 100644 --- a/after/plugin/quickloc-fix.lua +++ b/after/plugin/quickloc-fix.lua @@ -1,39 +1,11 @@ local keymap = vim.keymap.set -local trouble = require("trouble") - -vim.api.nvim_create_autocmd('DiagnosticChanged', { - callback = function() - vim.diagnostic.setqflist({ open = false }) - vim.diagnostic.setloclist({ open = false }) - end, -}) - -function QuickFixToggle() - if trouble.is_open() then - trouble.close() - else - trouble.open({ - mode = "quickfix" - }) - end -end - -function LocationListToggle() - if trouble.is_open() then - trouble.close() - else - trouble.open({ - mode = "loclist" - }) - end -end -- Quickfix -keymap("n", "qq", ":lua QuickFixToggle()", { desc = "[Q]uickfix [Q]uick" }) +keymap("n", "qq", ":TroubleToggle quickfix", { desc = "[Q]uickfix [Q]uick" }) keymap("n", "qn", "cnextzz", { desc = "[Q]uick [N]ext" }) keymap("n", "qp", "cprevzz", { desc = "[Q]uick [P]revious" }) -- Location List -keymap("n", "ll", ":lua LocationListToggle()", { desc = "[L]ocation [L]ist" }) +keymap("n", "ll", ":TroubleToggle loclist", { desc = "[L]ocation [L]ist" }) keymap("n", "ln", "lnextzz", { desc = "[L]ocation [N]ext" }) keymap("n", "lp", "lprevzz", { desc = "[L]ocation [P]revious" }) diff --git a/init.lua b/init.lua index d9bd1881..d0585b88 100644 --- a/init.lua +++ b/init.lua @@ -399,7 +399,7 @@ local on_attach = function(_, bufnr) -- See `:help K` for why this keymap nmap('K', vim.lsp.buf.hover, 'Hover Documentation') - nmap('', vim.lsp.buf.signature_help, 'Signature Documentation') + -- nmap('', vim.lsp.buf.signature_help, 'Signature Documentation') -- Lesser used LSP functionality nmap('gD', vim.lsp.buf.declaration, '[G]oto [D]eclaration') diff --git a/lua/custom/plugins/bufferline.lua b/lua/custom/plugins/bufferline.lua index 0eaf145e..70847ba4 100644 --- a/lua/custom/plugins/bufferline.lua +++ b/lua/custom/plugins/bufferline.lua @@ -4,12 +4,14 @@ return { config = function() require("bufferline").setup { options = { + numbers = "ordinal", indicator = { style = "icon", icon = "▎" }, diagnostics = 'nvim_lsp', -- | "nvim_lsp" | "coc", diagnostics_update_in_insert = false, offsets = { { filetype = "NvimTree", text = "File Explorer", padding = 1 } }, separator_style = "thin", -- | "thick" | "thin" | { 'any', 'any' }, always_show_bufferline = true, + sort_by = "insert_after_current" } } end