Add bufferline options to always show the bufferline, use ordinal numbers, and sort by insert position in the current setup

This commit is contained in:
PeteChu 2023-04-06 01:29:34 +07:00
parent e7b27047e2
commit 606b0572d2
6 changed files with 28 additions and 36 deletions

View File

@ -10,3 +10,5 @@ vim.opt.scrolloff = 8
vim.opt.colorcolumn = "80"
vim.opt.swapfile = false
vim.o.cmdheight = 2

17
after/plugin/grep.vim Normal file
View File

@ -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(<f-args>)
command! -nargs=+ -complete=file_in_path -bar LGrep lgetexpr Grep(<f-args>)
cnoreabbrev <expr> grep (getcmdtype() ==# ':' && getcmdline() ==# 'grep') ? 'Grep' : 'grep'
cnoreabbrev <expr> lgrep (getcmdtype() ==# ':' && getcmdline() ==# 'lgrep') ? 'LGrep' : 'lgrep'
augroup quickfix
autocmd!
autocmd QuickFixCmdPost cgetexpr TroubleToggle quickfix
autocmd QuickFixCmdPost lgetexpr TroubleToggle loclist
augroup END

View File

@ -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,7 +17,7 @@ end
-- vim.api.nvim_create_autocmd({ "VimEnter" }, { callback = open_nvim_tree })
-- Auto close
vim.api.nvim_create_autocmd({"QuitPre"}, {
vim.api.nvim_create_autocmd({ "QuitPre" }, {
callback = function() vim.cmd("NvimTreeClose") end,
})
@ -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)

View File

@ -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", "<leader>qq", ":lua QuickFixToggle()<CR>", { desc = "[Q]uickfix [Q]uick" })
keymap("n", "<leader>qq", ":TroubleToggle quickfix<CR>", { desc = "[Q]uickfix [Q]uick" })
keymap("n", "<leader>qn", "<cmd>cnext<CR>zz", { desc = "[Q]uick [N]ext" })
keymap("n", "<leader>qp", "<cmd>cprev<CR>zz", { desc = "[Q]uick [P]revious" })
-- Location List
keymap("n", "<leader>ll", ":lua LocationListToggle()<CR>", { desc = "[L]ocation [L]ist" })
keymap("n", "<leader>ll", ":TroubleToggle loclist<CR>", { desc = "[L]ocation [L]ist" })
keymap("n", "<leader>ln", "<cmd>lnext<CR>zz", { desc = "[L]ocation [N]ext" })
keymap("n", "<leader>lp", "<cmd>lprev<CR>zz", { desc = "[L]ocation [P]revious" })

View File

@ -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('<C-K>', vim.lsp.buf.signature_help, 'Signature Documentation')
-- nmap('<C-K>', vim.lsp.buf.signature_help, 'Signature Documentation')
-- Lesser used LSP functionality
nmap('gD', vim.lsp.buf.declaration, '[G]oto [D]eclaration')

View File

@ -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