From 11cba124b96ee0cf0f267513716da687f37aaff8 Mon Sep 17 00:00:00 2001 From: fiplox Date: Tue, 20 Jun 2023 19:01:48 +0200 Subject: [PATCH] feat!: remove trouble, use nvim-bqf trouble, after a :grep jumps to a first result. Did not find how to not jump... --- lua/config/autocmd.lua | 13 ---- lua/config/mappings.lua | 37 ++++++------ lua/config/settings.lua | 4 +- lua/plugins/bqf.lua | 23 +++++++ lua/plugins/init.lua | 130 +++------------------------------------- 5 files changed, 50 insertions(+), 157 deletions(-) create mode 100644 lua/plugins/bqf.lua diff --git a/lua/config/autocmd.lua b/lua/config/autocmd.lua index 9f75d1d..6b9c62d 100644 --- a/lua/config/autocmd.lua +++ b/lua/config/autocmd.lua @@ -67,19 +67,6 @@ vim.api.nvim_create_autocmd('FileType', { vim.opt_local.textwidth = 80 end, }) -function ToggleTroubleAuto() - local ok, trouble = pcall(require, 'trouble') - if ok then - vim.defer_fn(function() - vim.cmd 'lcl' - vim.cmd 'cclose' - trouble.open 'loclist' - end, 0) - end -end - --- vim.cmd "autocmd VimLeave * call os.execute("mkdir /tmp/nvim"), writefile([getcwd()], expand('/tmp/nvim/cwd'))" -vim.cmd [[autocmd BufWinEnter quickfix silent :lua ToggleTroubleAuto()]] vim.cmd [[ augroup change_cursor au! diff --git a/lua/config/mappings.lua b/lua/config/mappings.lua index de5f670..9b24328 100644 --- a/lua/config/mappings.lua +++ b/lua/config/mappings.lua @@ -32,30 +32,12 @@ keymap('n', 'rs', ':s///gI', { norem keymap('n', 'rr', ':%s///gI', { noremap = true }) keymap('v', 'r', ':s///gI', { noremap = true }) -keymap('n', 'xl', 'TroubleToggle loclist', { silent = true, noremap = true }) -keymap('n', 'xq', 'TroubleToggle quickfix', { silent = true, noremap = true }) -keymap('n', 'gR', 'TroubleToggle lsp_references', { silent = true, noremap = true }) -keymap('n', 'xx', 'TroubleToggle', { silent = true, noremap = true }) -keymap( - 'n', - 'xw', - 'TroubleToggle workspace_diagnostics', - { silent = true, noremap = true } -) -keymap( - 'n', - 'xd', - 'TroubleToggle document_diagnostics', - { silent = true, noremap = true } -) - keymap('n', 'D', '"_d', { noremap = true }) keymap('n', 'gD', 'lua vim.lsp.buf.declaration()', opt) keymap('n', 'gd', 'lua vim.lsp.buf.definition()', opt) keymap('n', '', 'lua vim.lsp.buf.hover()', opt) keymap('n', 'gI', 'lua vim.lsp.buf.implementation()', opt) -keymap('n', 'gr', 'TroubleToggle lsp_references', opt) keymap('n', 'gl', 'lua vim.diagnostic.open_float()', opt) keymap('n', 'lf', 'lua vim.lsp.buf.format { async = true }', opt) keymap('n', 'li', 'LspInfo', opt) @@ -101,7 +83,9 @@ local function file_exists(name) if f ~= nil then io.close(f) return true - else return false end + else + return false + end end if file_exists('/tmp/colemak') then @@ -155,6 +139,19 @@ local opts = { noremap = true, -- use `noremap` when creating keymaps nowait = false, -- use `nowait` when creating keymaps } + +vim.keymap.set('n', 'L', function() + local win = vim.api.nvim_get_current_win() + local qf_winid = vim.fn.getloclist(win, { winid = 0 }).winid + local action = qf_winid > 0 and 'lclose' or 'lopen' + vim.cmd(action) +end, { noremap = true, silent = true }) + +vim.keymap.set('n', 'X', function() + local qf_winid = vim.fn.getqflist({ winid = 0 }).winid + local action = qf_winid > 0 and 'cclose' or 'copen' + vim.cmd('botright ' .. action) +end, { noremap = true, silent = true }) -- }}} -- leader mappings {{{ -- TODO create entire treesitter section @@ -169,7 +166,7 @@ local mappings = { ['f'] = { 'e ~/.config/nvim/ ', 'Neovim config' }, ['rr'] = 'Search and replace all', ['rs'] = 'Search and replace', - ['c'] = { 'lua UnMapDHM()', 'Qwerty' }, + ['q'] = { 'lua UnMapDHM()', 'Qwerty' }, ['b'] = { function() require('buffer_manager.ui').toggle_quick_menu() diff --git a/lua/config/settings.lua b/lua/config/settings.lua index 26f28fa..e8225d6 100644 --- a/lua/config/settings.lua +++ b/lua/config/settings.lua @@ -23,7 +23,7 @@ opt.shortmess:append('I', 'W', 's') opt.iskeyword:prepend { '-' } opt.timeoutlen = 300 opt.fillchars = 'eob: ' -opt.cmdheight = 0 +opt.cmdheight = 1 opt.grepprg = 'rg --vimgrep --no-heading --smart-case --hidden' opt.grepformat = '%f:%l:%c:%m' @@ -74,3 +74,5 @@ vim.api.nvim_create_autocmd({ 'BufWinEnter', 'FileType' }, { group = vim.api.nvim_create_augroup('nvim-lastplace', {}), callback = run, }) + +vim.cmd("command! -nargs=+ Grep execute 'silent grep! ' | copen") diff --git a/lua/plugins/bqf.lua b/lua/plugins/bqf.lua new file mode 100644 index 0000000..9a851f1 --- /dev/null +++ b/lua/plugins/bqf.lua @@ -0,0 +1,23 @@ +return { + 'kevinhwang91/nvim-bqf', + lazy = false, + opts = { + -- description = [[Give the window magic, when the window is splited horizontally, keep + -- the distance between the current line and the top/bottom border of neovim unchanged. + -- It's a bit like a floating window, but the window is indeed a normal window, without + -- any floating attributes.]], + magic_window = true, + preview = { + auto_preview = true, + show_title = true, + show_scroll_bar = true, + winblend = 12, + wrap = false, + buf_label = true, + }, + func_map = { + openc = '', + open = 'o', + } + } +} diff --git a/lua/plugins/init.lua b/lua/plugins/init.lua index 0ec7d6b..b7be47e 100644 --- a/lua/plugins/init.lua +++ b/lua/plugins/init.lua @@ -1,75 +1,21 @@ return { 'folke/which-key.nvim', 'nvim-lua/plenary.nvim', --- 'mfussenegger/nvim-jdtls', --- 'simrat39/rust-tools.nvim', --- 'MunifTanjim/nui.nvim', - {'rush-rs/tree-sitter-asm', ft = 'asm'}, - { 'jghauser/mkdir.nvim', lazy = false }, + -- 'mfussenegger/nvim-jdtls', + -- 'simrat39/rust-tools.nvim', + { 'rush-rs/tree-sitter-asm', ft = 'asm' }, + { 'jghauser/mkdir.nvim', lazy = false }, { url = 'https://git.filnar.com/fiplox/neogruber.git', -- dir = '~/dev/neogruber.nvim/', lazy = false, -- event = 'VeryLazy' }, - -- 'rcarriga/cmp-dap', { 'phaazon/hop.nvim', -- event = 'BufRead', keys = { { 's', ':HopChar2' }, { 'S', ':HopWord' } }, config = true, }, ---[[ { - 'stevearc/dressing.nvim', - lazy = true, - init = function() - vim.ui.select = function(...) - require('lazy').load { plugins = { 'dressing.nvim' } } - return vim.ui.select(...) - end - vim.ui.input = function(...) - require('lazy').load { plugins = { 'dressing.nvim' } } - return vim.ui.input(...) - end - end, - opts = { - select = { - trim_prompt = false, - }, - }, - },]] ---[[ { - 'folke/noice.nvim', - opts = { - messages = { - view_search = false, - }, - cmdline = { - enabled = true, - view = 'cmdline', -- view for rendering the cmdline. Change to `cmdline` to get a classic cmdline at the bottom - }, - presets = { - bottom_search = true, -- use a classic bottom cmdline for search - command_palette = false, -- position the cmdline and popupmenu together - long_message_to_split = true, -- long messages will be sent to a split - inc_rename = false, -- enables an input dialog for inc-rename.nvim - lsp_doc_border = false, -- add a border to hover docs and signature help - }, - lsp = { - -- override markdown rendering so that **cmp** and other plugins use **Treesitter** - override = { - ['vim.lsp.util.convert_input_to_markdown_lines'] = true, - ['vim.lsp.util.stylize_markdown'] = true, - ['cmp.entry.get_documentation'] = true, - }, - hover = { - enabled = false, - }, - signature = { - enabled = false, - }, - }, - }, - },]] { 'numToStr/Comment.nvim', -- event = 'VeryLazy', @@ -114,7 +60,8 @@ return { if ctx.ctype == U.ctype.blockwise 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() + location = require('ts_context_commentstring.utils') + .get_visual_start_location() end return require('ts_context_commentstring.internal').calculate_commentstring { @@ -210,14 +157,6 @@ return { -- The diffview integration enables the diff popup, which is a wrapper around `sindrets/diffview.nvim`. -- -- Requires you to have `sindrets/diffview.nvim` installed. - -- use { - -- 'TimUntersberger/neogit', - -- requires = { - -- 'nvim-lua/plenary.nvim', - -- 'sindrets/diffview.nvim' - -- } - -- } - -- diffview = true, }, -- Setting any section to `false` will make the section not render at all @@ -371,7 +310,7 @@ return { }, }, }, -{ + { 'nvim-treesitter/nvim-treesitter', -- lazy = false, -- dependencies = { 'nvim-treesitter/playground' }, @@ -400,61 +339,6 @@ return { } end, }, - { - 'folke/trouble.nvim', - -- dependencies = { - -- 'nvim-tree/nvim-web-devicons', - -- }, - cmd = { 'TroubleToggle', 'Trouble' }, - opts = { - 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 = 'loclist', -- "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 = true, -- 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 - }, - }, { 'j-morano/buffer_manager.nvim', opts = {