usability improvements

- add autocmds to highlight yanking and disabling line numbers in Oil
- lsp-zero: fix 'gd' command by setting 'preserve_mappings' to false
- lualine: show clock, simplify statusline, shorten mode name
- oil: decrease float window size, add 'q' hotkey to close window
- prefs: show line numbers again, disable additional mode showing
- add todo-comments.nvim
- remap: add keymap to find all TODOs/FIXME/XXX etc.
This commit is contained in:
Oliver Ladner 2024-03-05 21:32:07 +01:00
commit 480a5c2fff
10 changed files with 96 additions and 21 deletions

View file

@ -101,6 +101,7 @@
- `cc` replace whole line
- `C` replace to the end of the line
- `yy` copy the current line
- `yap` "yank-around-paragraph"
- `p` paste yanked line below
- `P` paste yanked line above

Binary file not shown.

18
lua/weeheavy/autocmd.lua Normal file
View file

@ -0,0 +1,18 @@
-- Highlight yanked text on e.g. yy,yap etc.
vim.api.nvim_create_autocmd("TextYankPost", {
desc = "Highlight when yanking (copying) text",
group = vim.api.nvim_create_augroup("weeheavy-highlight-yank", { clear = true }),
callback = function()
vim.highlight.on_yank()
end,
})
-- Disable (relative) line numbers on Oil windows
vim.api.nvim_create_autocmd("FileType", {
group = vim.api.nvim_create_augroup("weeheavy-no-line-numbers-in-oil", { clear = true }),
pattern = { "oil" },
callback = function()
vim.opt.relativenumber = false
vim.opt.number = false
end,
})

View file

@ -9,3 +9,6 @@ require("weeheavy.lazy")
-- Other preferences
require("weeheavy.prefs")
-- Auto commands
require("weeheavy.autocmd")

View file

@ -38,9 +38,7 @@ return {
["<C-u>"] = cmp.mapping.scroll_docs(-4),
["<C-d>"] = cmp.mapping.scroll_docs(4),
["<C-l>"] = cmp.mapping.confirm({ select = true }), -- accept LSP autocompletion
--["<C-p>"] = cmp.mapping.select_prev_item(cmp_select),
["<C-k>"] = cmp.mapping.select_prev_item(cmp_select),
--["<C-n>"] = cmp.mapping.select_next_item(cmp_select),
["<C-j>"] = cmp.mapping.select_next_item(cmp_select),
["<C-f>"] = cmp_action.luasnip_jump_forward(),
["<C-b>"] = cmp_action.luasnip_jump_backward(),
@ -67,7 +65,8 @@ return {
lsp_zero.on_attach(function(client, bufnr)
-- see :help lsp-zero-keybindings
-- to learn the available actions
lsp_zero.default_keymaps({ buffer = bufnr })
-- https://www.reddit.com/r/neovim/comments/1ankiu1/lsp_zero_go_to_definition_stopped_working/
lsp_zero.default_keymaps({ buffer = bufnr, preserve_mappings = false })
end)
require("mason").setup({

View file

@ -22,6 +22,11 @@ local function hide_in_width()
return vim.fn.winwidth(0) > 80
end
local function clock()
local time = tostring(os.date()):sub(12, 16)
return time
end
return {
"nvim-lualine/lualine.nvim",
lazy = true,
@ -29,21 +34,44 @@ return {
opts = {
options = {
globalstatus = false, -- true == single statusline
icons_enabled = true,
theme = "auto",
--component_separators = '⋮',
component_separators = "",
--section_separators = { left = '', right = '' },
--section_separators = { left = '', right = '' },
section_separators = { left = "", right = "" },
component_separators = "",
--section_separators = { left = "", right = "" },
section_separators = { left = "", right = "" },
},
sections = {
lualine_a = {
{
-- shorten mode names
-- https://github.com/nvim-lualine/lualine.nvim/issues/614#issuecomment-1072275099
"mode",
fmt = function(res)
return res:sub(1, 1)
end,
},
},
lualine_c = {
{ "searchcount" },
{
"buffers",
show_filename_only = false,
--fmt = function(str)
-- return str:sub(1, 1)
--end,
--fmt = function()
-- return string.gsub(vim.api.nvim_buf_get_name(0), vim.loop.cwd(), "")
--end,
},
},
lualine_x = {
-- specify full list of elements when adding custom things
{ "encoding" },
{ "fileformat" },
{ "filetype" },
{ lsp_clients, cond = hide_in_width },
{ clock, cond = hide_in_width },
},
},
},

View file

@ -24,6 +24,19 @@ return {
["<leader>e"] = "actions.close",
["<C-v>"] = "actions.select_vsplit",
["<C-x>"] = "actions.select_split",
["<C-c>"] = "actions.close",
["q"] = "actions.close",
},
float = {
-- Padding around the floating window
padding = 2,
max_width = 80,
max_height = 50,
border = "rounded",
win_options = {
winblend = 0,
},
},
})
end,

View file

@ -0,0 +1,16 @@
-- Highlight, list and search todo comments in your projects
-- https://github.com/folke/todo-comments.nvim
return {
"folke/todo-comments.nvim",
lazy = true,
event = "VimEnter",
-- TODO: a todo
-- WARN: a warning
-- PERF: a performance remark
-- NOTE: a note
-- FIXME: a fixme
dependencies = {
"nvim-lua/plenary.nvim",
},
opts = { signs = false },
}

View file

@ -10,7 +10,7 @@ vim.opt.ignorecase = true
vim.opt.smartcase = true
-- Show line numbers default
--vim.opt.number = true
vim.opt.number = true
-- Show relative line numbers
vim.opt.relativenumber = true
@ -66,3 +66,6 @@ vim.opt.splitbelow = true
-- Split windows appear to the right instead of left
vim.opt.splitright = true
-- Mode is shown in lualine, so we don't need it one line below
vim.opt.showmode = false

View file

@ -3,24 +3,17 @@
-- Leader key set to space, base for any key combo
vim.g.mapleader = " "
vim.keymap.set("n", "<leader>r", vim.cmd.Ex, { noremap = true, desc = "netrw File Browser" }) -- netrw file explorer
--vim.keymap.set("n", "<leader>r", vim.cmd.Ex, { noremap = true, desc = "netrw File Browser" }) -- netrw file explorer
--vim.keymap.set("n", "<leader>e", ":Oil<CR>", { desc = "File navigation" })
vim.keymap.set("n", "<leader>e", ":Oil --float<CR>", { desc = "File navigation" })
--vim.keymap.set("n", "<leader>e", "<cmd>lua require('oil').toggle_float('.')<CR>", { noremap = true, silent = true })
vim.keymap.set("n", "<leader>e", ":Oil<CR>", { desc = "File navigation" })
--vim.keymap.set(
-- "n",
-- "<leader>e",
-- ":Telescope file_browser hidden=true no_ignore=true previewer=false display_stat=false<CR>",
-- { noremap = true, desc = "Directory browser" }
--)
-- List recently opened files
vim.keymap.set("n", "<leader>fo", ":Telescope oldfiles<CR>", { noremap = true, desc = "File history" })
vim.keymap.set(
"n",
"<leader>ff",
":Telescope find_files hidden=true no_ignore=false <CR>",
":Telescope find_files hidden=true no_ignore=true<CR>",
{ noremap = true, desc = "File search" }
)
@ -32,6 +25,8 @@ vim.keymap.set(
{ noremap = true, desc = "Search text under cursor in cwd/grep search string" }
)
vim.keymap.set("n", "<leader><leader>", ":Telescope buffers<CR>", { noremap = true, desc = "Show open buffers" })
-- todo-comments.nvim
vim.keymap.set("n", "<leader>ft", ":TodoTelescope<CR>", { noremap = true, desc = "Find TODOs" })
vim.keymap.set("n", "<leader>gst", ":Telescope git_status<CR>", { noremap = true, desc = "Git status" })
vim.keymap.set(
"n",
@ -41,7 +36,6 @@ vim.keymap.set(
)
vim.keymap.set("n", "<leader>glf", ":Telescope git_bcommits<CR>", { noremap = true, desc = "Git log (this file)" })
vim.keymap.set("n", "<leader>gdp", ":Gitsigns diffthis<CR>", { noremap = true, desc = "Git diff previous (this file)" })
vim.keymap.set("n", "<leader>gg", ":LazyGitCurrentFile<CR>", { noremap = true, desc = "LazyGit" })
-- Remapping of existing Vim key binds
vim.keymap.set("n", "w", "W") -- skip punctuation when moving to start of next word