Skip to content

Commit

Permalink
neovim: better diag (trouble), quickfix and testing
Browse files Browse the repository at this point in the history
  • Loading branch information
appaquet committed Jan 16, 2025
1 parent d5c1d1a commit e0d345b
Show file tree
Hide file tree
Showing 10 changed files with 98 additions and 29 deletions.
25 changes: 16 additions & 9 deletions README.nvim.md
Original file line number Diff line number Diff line change
Expand Up @@ -11,10 +11,9 @@
* `<leader>]` to switch to next buffer
* `<leader>[` to switch to previous buffer
* `<leader>s` to save current buffer
* `<leader>x` to save and then execute current buffer (as long as it's chmod +x)
* `<leader>z` to execute current visual selection in a shell
* `<leader>w` to close the current buffer by trying not to mess up the layout
* `<leader>o` to close all buffers except the current one
* `<leader>wo` to close all buffers except the current one
* `<leader>wa` to close all buffers

## Fzf
* `<ctrl>p` or `<leader>ff` fuzzy finding file names
Expand Down Expand Up @@ -44,8 +43,11 @@
* `<space>ca` code action on code or block (ex: extract function)
* `gr` list all references of a symbol (to quickfix)
* `<space>f` format code
* `]d` go to next diagnostic
* `[d` go to prev diagnostic

## Diagnostics
* `<leader>db` Open diagnostic float
* `<leader>dn` or `]d` Go to next diagnostic
* `<leader>dp` or `[d` Go to previous diagnostic

## Nvim tree
* `<ctrl>e` to toggle filetree
Expand Down Expand Up @@ -74,10 +76,11 @@
* `:Gblame` to show blame

## Quickfix
* `<leader>qo` to open quickfix
* `<leader>qc` to close quickfix
* `<leader>qn` to go to next quickfix
* `<leader>qp` to go to prev quickfix
* `<leader>xo` to open quickfix
* `<leader>xq` to close quickfix
* `<leader>xn` or `]d` to go to next quickfix
* `<leader>xp` or `[d` to go to prev quickfix
* `<leader>xf` to find in quickfix

## Testing
* `<leader>tc` to run nearest / under cursor
Expand All @@ -91,6 +94,10 @@
* `<leader>tk` to clear output panel
* `<leader>tq` to close output panel

## Misc
* `<leader>r` to execute current buffer in a shell (normal mode)
* `<leader>r` to execute current visual selection in a shell (visual mode)

## Commands
* `Rename <file name>` to rename current file
* `Edit <file name>` to create a file in current buffer dir
Expand Down
1 change: 1 addition & 0 deletions home-manager/modules/neovim/conf/base.vim
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@ set showmatch " show matching brackets/parenthesis
set incsearch " find as you type search
set hlsearch " highlight search terms
set relativenumber " relative line numbers
set number " show current absolute number instead of 0
set smartcase " case sensitive when uc present
set ignorecase " case insensitive search
set hidden " buffer switching without saving
Expand Down
30 changes: 19 additions & 11 deletions home-manager/modules/neovim/conf/keymap.lua
Original file line number Diff line number Diff line change
@@ -1,4 +1,10 @@


-- Buffer navigation & control
require('bufdel').setup {
quit = false, -- don't quit on last close
}

vim.keymap.set('n', '<Leader>1', ':br!<CR>', { silent = true, desc = "Switch to buffer 1" })
vim.keymap.set('n', '<Leader>2', ':br!<CR>:bn!<CR>', { silent = true, desc = "Switch to buffer 2" })
vim.keymap.set('n', '<Leader>3', ':br!<CR>:bn!<CR>', { silent = true, desc = "Switch to buffer 3" })
Expand All @@ -10,13 +16,9 @@ vim.keymap.set('n', '<Leader>8', ':br!<CR>:bn!<CR>', { silent = true, desc = "Sw
vim.keymap.set('n', '<Leader>9', ':br!<CR>:bn!<CR>', { silent = true, desc = "Switch to buffer 9" })
vim.keymap.set('n', '<Leader>]', ':bn!<CR>', { silent = true, desc = "Next buffer" })
vim.keymap.set('n', '<Leader>[', ':bp!<CR>', { silent = true, desc = "Previous buffer" })
vim.keymap.set('n', '<Leader>w', ':BufDel<CR>', { desc = "Delete current buffer" })
vim.keymap.set('n', '<Leader>ww', ':BufDel<CR>', { desc = "Delete current buffer" })
vim.keymap.set('n', '<Leader>wo', ':BufDelOthers<CR>', { desc = "Delete other buffers" })

-- Execute current file or selection
vim.keymap.set('n', '<Leader>x', ':w<CR>:!./%<CR>', { desc = "Save and execute current file" })
vim.keymap.set('v', '<Leader>z', ':w !sh<CR>', { desc = "Execute selected lines in shell" })
vim.keymap.set('n', '<Leader>w', ':BufDel<CR>', { silent = true, desc = "Close current buffer" })
vim.keymap.set('n', '<Leader>wo', ':BufDelOthers<CR>', { silent = true, desc = "Close other buffers" })
vim.keymap.set('n', '<Leader>wa', ':BufDelAll<CR>', { silent = true, desc = "Close all buffers" })

-- Clipboard operations
vim.keymap.set('v', '<Leader>y', ':w !pbcopy<CR><CR>', { desc = "Copy current file content to system clipboard" })
Expand All @@ -28,6 +30,10 @@ vim.keymap.set('n', '<Leader>s', ':w<CR>', { silent = true, desc = "Save file (L
vim.keymap.set('n', '<Leader>qq', ':q<CR>', { silent = true, desc = "Quit current buffer" })
vim.keymap.set('n', '<Leader>qa', ':qa<CR>', { silent = true, desc = "Quit all buffers" })

-- Misc
vim.keymap.set('n', '<Leader>r', ':w<CR>:!./%<CR>', { silent = true, desc = "Save and execute current file" })
vim.keymap.set('v', '<Leader>r', ':w !sh<CR>', { silent = true, desc = "Execute selected lines in shell" })

-- Command-line mappings for "sudo save" and quick quit commands
vim.cmd([[
cnoremap w!! w !sudo tee % >/dev/null
Expand All @@ -54,7 +60,9 @@ vim.keymap.set('n', '<Leader>m', function()
end, { silent = true, desc = "Toggle mouse support" })

-- Quickfix
vim.keymap.set("n", "<leader>qo", "<cmd>copen<cr>", { desc = "Quickfix: Open" })
vim.keymap.set("n", "<leader>qc", "<cmd>cclose<cr>", { desc = "Quickfix: Close" })
vim.keymap.set("n", "<leader>qn", "<cmd>cnext<cr>", { desc = "Quickfix: Next" })
vim.keymap.set("n", "<leader>qp", "<cmd>cprev<cr>", { desc = "Quickfix: Previous" })
vim.keymap.set("n", "<leader>xo", "<cmd>copen<cr>", { desc = "Quickfix: Open" })
vim.keymap.set("n", "<leader>xq", "<cmd>cclose<cr>", { desc = "Quickfix: Close" })
vim.keymap.set("n", "<leader>xn", "<cmd>cnext<cr>", { desc = "Quickfix: Next" })
vim.keymap.set("n", "[x", "<cmd>cprev<cr>", { desc = "Quickfix: Prev" })
vim.keymap.set("n", "]x", "<cmd>cnext<cr>", { desc = "Quickfix: Next" })
vim.keymap.set("n", "<leader>xp", "<cmd>cprev<cr>", { desc = "Quickfix: Previous" })
4 changes: 4 additions & 0 deletions home-manager/modules/neovim/conf/plugin.diffview.lua
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@

-- https://github.com/sindrets/diffview.nvim
require("diffview").setup {
}
1 change: 1 addition & 0 deletions home-manager/modules/neovim/conf/plugin.fzf.lua
Original file line number Diff line number Diff line change
Expand Up @@ -37,6 +37,7 @@ vim.keymap.set("n", "<leader>fh", fzf.helptags, { desc = "FZF: Help tags" })
vim.keymap.set("n", "<leader>fk", fzf.keymaps, { desc = "FZF: Keymaps" })

vim.keymap.set("n", "<leader>fql", fzf.quickfix, { desc = "FZF: Quickfix list" })
vim.keymap.set("n", "<leader>xf", fzf.quickfix, { desc = "FZF: Quickfix list" })
vim.keymap.set("n", "<leader>fqs", fzf.quickfix_stack, { desc = "FZF: Quickfix stack" })

vim.keymap.set("n", "<leader>fls", fzf.lsp_document_symbols, { desc = "FZF: LSP document symbols" })
Expand Down
8 changes: 0 additions & 8 deletions home-manager/modules/neovim/conf/plugin.lsp.lua
Original file line number Diff line number Diff line change
Expand Up @@ -45,14 +45,6 @@ vim.api.nvim_create_autocmd('LspAttach', {
-- Enable inlays
vim.lsp.inlay_hint.enable(true)

--------------
-- Diagnostics
-- See `:help vim.diagnostic.*` for documentation on any of the below functions
vim.keymap.set('n', '<space>e', vim.diagnostic.open_float, { desc = "LSP: Open diagnostic float" })
vim.keymap.set('n', '[d', vim.diagnostic.goto_prev, { desc = "LSP: Go to previous diagnostic" })
vim.keymap.set('n', ']d', vim.diagnostic.goto_next, { desc = "LSP: Go to next diagnostic" })
vim.keymap.set('n', '<space>q', vim.diagnostic.setloclist, { desc = "LSP: Set location list" })

-- nvim-cmp (https://github.com/hrsh7th/nvim-cmp)
-- luasnip (https://github.com/L3MON4D3/LuaSnip)
local luasnip = require 'luasnip'
Expand Down
5 changes: 4 additions & 1 deletion home-manager/modules/neovim/conf/plugin.neotest.lua
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,7 @@ Neotest.setup({

local function run_nearest()
Neotest.output_panel.open()
Neotest.output_panel.clear()
Neotest.run.run()
end

Expand All @@ -27,21 +28,23 @@ end

local function run_file()
Neotest.output_panel.open()
Neotest.output_panel.clear()
Neotest.run.run(vim.fn.expand("%"))
end

local function debug_file()
Neotest.output_panel.open()
Neotest.output_panel.clear()
Neotest.run.run({ vim.fn.expand("%"), strategy = "dap" })
end

local function run_last()
Neotest.output_panel.open()
Neotest.output_panel.clear()
Neotest.run.run_last()
end

local function debug_last()
Neotest.output_panel.open()
Neotest.run.run_last({ strategy = "dap" })
end

Expand Down
4 changes: 4 additions & 0 deletions home-manager/modules/neovim/conf/plugin.nvimtree.lua
Original file line number Diff line number Diff line change
Expand Up @@ -13,4 +13,8 @@ require("nvim-tree").setup {
update_focused_file = {
enable = true,
},
diagnostics = {
enable = true,
show_on_dirs = true,
},
}
44 changes: 44 additions & 0 deletions home-manager/modules/neovim/conf/plugin.trouble.lua
Original file line number Diff line number Diff line change
@@ -0,0 +1,44 @@


-----------
-- Trouble
-- https://github.com/folke/trouble.nvim
local Trouble = require("trouble")
Trouble.setup {
}

local function trouble_open()
Trouble.open("diagnostics")
end

local function trouble_close()
Trouble.close("diagnostics")
end

local function trouble_next()
if Trouble.is_open("diagnostics") then
Trouble.focus()
Trouble.next()
else
vim.diagnostic.goto_next()
end
end

local function trouble_prev()
if Trouble.is_open("diagnostics") then
Trouble.focus()
Trouble.previous()
else
vim.diagnostic.goto_prev()
end
end

-- See `:help vim.diagnostic.*` for documentation on any of the below functions
vim.keymap.set('n', '<leader>ds', vim.diagnostic.open_float, { desc = "Diag: Open diagnostic float" })
vim.keymap.set('n', '<leader>dn', trouble_next, { desc = "Diag: Go to next diagnostic" })
vim.keymap.set('n', ']d', trouble_next, { desc = "Diag: Go to next diagnostic" })
vim.keymap.set('n', '<leader>dp', trouble_prev, { desc = "Diag: Go to previous diagnostic" })
vim.keymap.set('n', '[d', trouble_prev, { desc = "Diag: Go to previous diagnostic" })
vim.keymap.set('n', '<leader>dl', vim.diagnostic.setloclist, { desc = "Diag: Set location list" })
vim.keymap.set('n', '<leader>do', trouble_open, { desc = "Diag: Open trouble" })
vim.keymap.set('n', '<leader>dq', trouble_close, { desc = "Diag: Close trouble" })
5 changes: 5 additions & 0 deletions home-manager/modules/neovim/default.nix
Original file line number Diff line number Diff line change
Expand Up @@ -44,9 +44,13 @@ in
which-key-nvim # show keymap hints
todo-comments-nvim # highlight TODO, FIXME, etc

# Diagnostics
trouble-nvim

# Git
vim-fugitive # Git (diff|log|...) commands
vim-gitgutter # Show diffs in gutter
diffview-nvim # :DiffviewOpen, :DiffviewClose

# LSP / Languages
nvim-lspconfig # https://github.com/neovim/nvim-lspconfig
Expand Down Expand Up @@ -118,6 +122,7 @@ in
(readLuaFile ./conf/plugin.nvimtree.lua)
(readLuaFile ./conf/plugin.todocomments.lua)
(readLuaFile ./conf/plugin.treesitter.lua)
(readLuaFile ./conf/plugin.trouble.lua)
]
);
};
Expand Down

0 comments on commit e0d345b

Please sign in to comment.