Many things are working

This commit is contained in:
RingOfStorms (Joshua Bell) 2024-05-01 17:33:08 -05:00
parent c42f197307
commit 4582bd5469
20 changed files with 715 additions and 300 deletions

View file

@ -1,4 +1,3 @@
local util = require("util")
-- Remap space as leader key
vim.keymap.set("", "<Space>", "<Nop>", { silent = true })
vim.g.mapleader = " "
@ -14,10 +13,8 @@ vim.g.maplocalleader = " "
local nvx = { "n", "v", "x" }
util.keymaps({
-- ===========
-- Basic
-- ===========
U.keymaps({
-- Basic
{ "<left>", '<cmd>echo "use h/j/k/l to move!"<cr>', mode = nvx },
{ "<right>", '<cmd>echo "use h/j/k/l to move!"<cr>', mode = nvx },
{ "<up>", '<cmd>echo "use h/j/k/l to move!"<cr>', mode = nvx },
@ -26,19 +23,33 @@ util.keymaps({
{ "<leader>Q", "<nop>", mode = nvx }, -- don't do normal Q quit
{ "<leader>a", "<esc>ggVG", desc = "Select all", mode = nvx },
{ "Q", "<cmd>qa<CR>", desc = "Quit all", mode = nvx },
{
"<leader>QQ",
-- TODO REVISIT is this session stuff still relevant?
"<cmd>NvimTreeClose<cr><cmd>SessionDelete<cr><cmd>qa<CR>",
desc = "Quit all, no session saved",
mode = nvx,
},
-- {
-- "<leader>QQ",
-- -- TODO REVISIT is this session stuff still relevant?
-- "<cmd>NvimTreeClose<cr><cmd>SessionDelete<cr><cmd>qa<CR>",
-- desc = "Quit all, no session saved",
-- mode = nvx,
-- },
{ "<leader>y", '"+y', desc = "Copy to system clipboard", mode = nvx },
{ "<leader>p", '"+p', desc = "Paste from system clipboard", mode = nvx },
{ "<esc>", "<cmd>nohlsearch<CR><esc>", desc = "Clear search on escape" },
{ "<return>", "<cmd>nohlsearch<CR><return>", desc = "Clear search on return" },
{ "|", "<cmd>vsplit<cr>", desc = "Vertical Split" },
{ "\\", "<cmd>split<cr>", desc = "Horizontal Split" },
{ "<S-Tab>", "<C-o>", desc = "Go back <C-o>" },
{
"J",
":m '>+1<CR>gv=gv",
desc = "Visually move block down",
mode = "v",
},
{
"K",
":m '<-2<CR>gv=gv",
desc = "Visually move block up",
mode = "v",
},
{ "<Esc>", "<C-\\><C-n>", desc = "Escape the terminal", mode = "t" },
-- Buffers
{ "<leader>b", "<cmd>b#<cr>", desc = "Switch to last buffer", mode = nvx },
@ -51,7 +62,7 @@ util.keymaps({
-- * if empty buffer, then we will quit this buffer
local close_always = { "quickfix", "help", "nofile" }
if
util.table_contains(close_always, vim.bo.buftype)
U.table_contains(close_always, vim.bo.buftype)
or (vim.api.nvim_buf_line_count(0) == 1 and vim.api.nvim_buf_get_lines(0, 0, 1, -1)[1] == "")
then
vim.cmd("silent confirm q")
@ -73,6 +84,30 @@ util.keymaps({
{ "<C-k>", "<C-W>k", desc = "Move window above current", mode = nvx },
{ "<C-l>", "<C-W>l", desc = "Move window right current", mode = nvx },
-- Editor
{ "J", "mzJ`z", desc = "Move line below onto this line" },
{ -- TODO stay here, are these already mapped?
"]d",
vim.diagnostic.goto_next,
desc = "Go to next diagnostic message",
},
{
"[d",
vim.diagnostic.goto_prev,
desc = "Go to previous diagnostic message",
},
{ ">", "> gv", desc = "Indent selection", mode = "v" },
{ "<", "< gv", desc = "Outdent selection", mode = "v" },
{ "p", '"_dP', desc = "Paste without yanking replaced content", mode = "v" },
-- TODO take <leader>r from http requests?
{ "<C-r>", '"hy:%s/<C-r>h//g<left><left>', desc = "Replace current selection", mode = "v" },
{ "<C-k>", "<Up>", desc = "Up", mode = { "i", "c" }, desc = "Movements in insert/command mode" },
{ "<C-j>", "<Down>", desc = "Down", mode = { "i", "c" }, desc = "Movements in insert/command mode" },
{ "<C-h>", "<Left>", desc = "Left", mode = { "i", "c" }, desc = "Movements in insert/command mode" },
{ "<C-l>", "<Right>", desc = "Right", mode = { "i", "c" }, desc = "Movements in insert/command mode" },
{ "<C-4>", "<End>", desc = "End", mode = { "i", "c" }, desc = "Movements in insert/command mode" },
{ "<C-6>", "<Home>", desc = "Home", mode = { "i", "c" }, desc = "Movements in insert/command mode" },
-- Tabs
-- TODO revisit, do I even need these tab things?
{ "<leader>tn", "<cmd>tabnew<cr>", desc = "Create new tab", mode = nvx },
@ -80,7 +115,7 @@ util.keymaps({
{ "H", "<cmd>tabprevious<cr>", desc = "Move to previous tab" },
{ "L", "<cmd>tabnext<cr>", desc = "Move to next tab" },
-- LSP/IDE/etc
-- LSP/IDE/etc TODO move to lsp config file
{
"<leader>l<leader>",
vim.lsp.buf.format,
@ -99,76 +134,4 @@ util.keymaps({
desc = "Show diagnostics in quickfix list",
mode = nvx,
},
-- =============
-- =============
-- =============
-- =============
-- =============
-- =============
-- =============
-- normal mode
-- =============
-- { "", "", desc = "" },
-- { "n", "nzzzv", desc = "Next search result centered" },
-- { "N", "Nzzzv", desc = "Previous search result centered" },
-- { "<C-d>", "<C-d>zz", desc = "Vertical half page down and center cursor" },
-- { "<C-u>", "<C-u>zz", desc = "Vertical half page up and center cursor" },
{ "J", "mzJ`z", desc = "Move line below onto this line" },
{ "<S-Tab>", "<C-o>", desc = "Go back <C-o>" },
{
"]d",
vim.diagnostic.goto_next,
desc = "Go to next diagnostic message",
},
{
"[d",
vim.diagnostic.goto_prev,
desc = "Go to previous diagnostic message",
},
-- =============
-- VISUAL
-- =============
{
"J",
":m '>+1<CR>gv=gv",
desc = "Visually move block down",
mode = "v",
},
{
"K",
":m '<-2<CR>gv=gv",
desc = "Visually move block up",
mode = "v",
},
{
"<leader>,uu",
'd:let @u = trim(tolower(system("uuidgen")))<cr>i<C-r>u',
desc = "Generate and replace UUID",
mode = "v",
},
{ "p", '"_dP', desc = "Paste without yanking replaced content", mode = "v" },
{ "<C-r>", '"hy:%s/<C-r>h//g<left><left>', desc = "Replace current selection", mode = "v" },
{ ">", "> gv", desc = "Indent selection", mode = "v" },
{ "<", "< gv", desc = "Outdent selection", mode = "v" },
-- =============
-- insert / command
-- =============
{ "<C-k>", "<Up>", desc = "Up", mode = { "i", "c" } },
{ "<C-j>", "<Down>", desc = "Down", mode = { "i", "c" } },
{ "<C-h>", "<Left>", desc = "Left", mode = { "i", "c" } },
{ "<C-l>", "<Right>", desc = "Right", mode = { "i", "c" } },
{ "<C-4>", "<End>", desc = "End", mode = { "i", "c" } },
{ "<C-6>", "<Home>", desc = "Home", mode = { "i", "c" } },
-- =============
-- command
-- =============
-- { mode = "c" }
-- =============
-- terminal
-- =============
{ "<Esc>", "<C-\\><C-n>", desc = "Escape the terminal", mode = "t" },
})

View file

@ -42,7 +42,7 @@ vim.opt.expandtab = true
-- Dont use swap files, use undotree
vim.opt.swapfile = false
vim.opt.backup = false
vim.opt.undodir = vim.fn.stdpath("state") .. "/undodir"
vim.opt.undodir = vim.fn.stdpath("data") .. "/undodir"
vim.opt.undofile = true
-- Sets how neovim will display certain whitespace characters in the editor.

View file

@ -2,6 +2,11 @@ return {
"Pocco81/auto-save.nvim",
event = "BufEnter",
opts = {
execution_message = {
message = function()
return ""
end,
},
trigger_events = { "InsertLeave", "TextChanged", "TextChangedI", "BufLeave" },
condition = function(buf)
local disallowed_filetypes = { "TelescopePrompt", "quickfix", "terminal" }

View file

@ -0,0 +1,26 @@
return {
"preservim/nerdcommenter",
dependencies = {
{
-- This will auto change the commentstring option in files that could have varying
-- comment modes like in jsx/markdown/files with embedded languages
"JoosepAlviste/nvim-ts-context-commentstring",
init = function()
-- skip backwards compatibility routines and speed up loading
vim.g.skip_ts_context_commentstring_module = true
end,
config = function()
require("ts_context_commentstring").setup({})
end,
},
},
config = function()
vim.g.NERDCreateDefaultMappings = 0
vim.g.NERDDefaultAlign = "both"
vim.g.NERDSpaceDelims = 1
vim.cmd("filetype plugin on")
end,
keys = {
{ "<leader>/", "<Plug>NERDCommenterToggle<cr>k", mode = { "n", "x" } },
},
}

View file

@ -4,7 +4,5 @@ return {
event = "VeryLazy",
opts = {
retirementAgeMins = 1,
notificationOnAutoClose = true,
-- deleteBufferWhenFileDeleted = true,
},
}

View file

@ -0,0 +1,127 @@
-- TODO checkout https://github.com/nvim-lua/lsp-status.nvim
local function lsp_clients()
local clients = {}
for _, client in pairs(vim.lsp.buf_get_clients(0)) do
local name = client.name
-- TODO revisit this doesn't work
if not client.initialized then
name = name .. " (loading)"
end
clients[#clients + 1] = name
end
table.sort(clients)
return table.concat(clients, ""), ""
end
local function langs()
local l = {}
for _, client in pairs(vim.lsp.buf_get_clients(0)) do
local out = nil
if client.name == "pyright" then
out = vim.fn.system({ "python", "-V" })
elseif client.name == "tsserver" then
out = "node " .. vim.fn.system({ "node", "--version" })
end
if out ~= nil and out ~= "" then
l[#l + 1] = vim.trim(out)
end
end
table.sort(l)
return table.concat(l, ""), ""
end
local function latest_message()
return U.safeRequire("noice", function(n)
return n.api.status.message.get_hl
end, U.fnEmptyStr)
end
local function latest_message_cond()
return U.safeRequire("noice", function(n)
return n.api.status.message.has
end, U.fnFalse)
end
return {
"nvim-lualine/lualine.nvim",
dependencies = { { "folke/noice.nvim", optional = true } },
lazy = false,
opts = function()
return {
options = {
theme = "codedark",
section_separators = { left = "", right = "" },
component_separators = "|",
},
sections = {
lualine_a = { "mode" },
lualine_b = { "branch", "diff", "diagnostics" },
lualine_c = {
{ "filename", separator = { right = "" } },
{ "reg_recording", icon = { "󰻃" }, color = { fg = "#D37676" } },
{ latest_message, cond = latest_message_cond },
},
lualine_x = {
lsp_clients,
langs,
"encoding",
"filetype",
"filesize",
},
lualine_y = { "searchcount", "selectioncount" },
lualine_z = { "location" },
},
winbar = {
lualine_a = {
{
"filename",
symbols = {
modified = "", -- Text to show when the file is modified.
readonly = "[-]", -- Text to show when the file is non-modifiable or readonly.
unnamed = "[No Name]", -- Text to show for unnamed buffers.
newfile = "[New]", -- Text to show for newly created file before first write
},
},
},
lualine_b = {
"mode",
},
},
inactive_winbar = {
lualine_a = {
{
"filename",
symbols = {
modified = "", -- Text to show when the file is modified.
readonly = "[-]", -- Text to show when the file is non-modifiable or readonly.
unnamed = "[No Name]", -- Text to show for unnamed buffers.
newfile = "[New]", -- Text to show for newly created file before first write
},
},
},
},
}
end,
config = function(_, opts)
require("lualine").setup(opts)
local ref = function()
require("lualine").refresh({
place = { "statusline" },
})
end
vim.api.nvim_create_autocmd("RecordingEnter", {
callback = ref,
})
vim.api.nvim_create_autocmd("RecordingLeave", {
callback = function()
local timer = vim.loop.new_timer()
timer:start(50, 0, vim.schedule_wrap(ref))
end,
})
end,
}

View file

@ -2,12 +2,12 @@ return {
"folke/noice.nvim",
event = "VeryLazy",
opts = {
cmdline = {
format = {
conceal = {
pattern = "^noh"
},
},
messages = {
view = "mini", -- default view for messages
view_error = "notify", -- view for errors
view_warn = "mini", -- view for warnings
view_history = "messages", -- view for :messages
view_search = false, -- view for search count messages. Set to `false` to disable
},
lsp = {
-- override markdown rendering so that **cmp** and other plugins use **Treesitter**

View file

@ -1,27 +1,12 @@
return {
"rcarriga/nvim-notify",
-- dependencies = { "nvim-telescope/telescope.nvim", optional = true },
lazy = false,
priority = 999,
priority = 150,
opts = {
top_down = false,
timeout = 3000,
timeout = 5000,
},
config = function(_, opts)
require("notify").setup(opts)
vim.notify = require("notify")
-- TODO move to telescope instead...
-- if package.loaded["telescope"] then
-- require("telescope").load_extension("notify")
-- require("util").keymaps({
-- {
-- "<leader>fn",
-- "<cmd>Telescope notify<cr>",
-- desc = "Telescope search notifications",
-- mode = { "n", "v", "x" },
-- },
-- })
-- end
end,
}

View file

@ -0,0 +1,32 @@
return {
"folke/which-key.nvim",
event = "VeryLazy",
init = function()
vim.o.timeout = true
vim.o.timeoutlen = 250
end,
opts = {
window = {
border = "single",
winblend = 10,
},
},
config = function(_, opts)
local wk = require("which-key")
wk.setup(opts)
wk.register({
["<leader>b"] = { name = "Buffers" },
["<leader>t"] = { name = "Tabs" },
-- ["<leader>,"] = { name = "Miscellaneous Tools" },
-- ["<leader>c"] = { name = "Copilot" },
["<leader>f"] = { name = "Find [Telescope]" },
-- ["<leader>fs"] = { name = "Find in Scratches [Telescope]" },
-- ["<leader>g"] = { name = "Git" },
["<leader>l"] = { name = "LSP" },
["<leader>lf"] = { name = "LSP Find" },
-- ["<leader>Q"] = { name = "+Q Quit and remove session" },
-- ["<leader>s"] = { name = "Scratch Files" },
-- ["<leader>x"] = { name = "Generative AI, Ollama" },
})
end,
}

154
lua/plugins/telescope.lua Normal file
View file

@ -0,0 +1,154 @@
return {
"nvim-telescope/telescope.nvim",
dependencies = {
{ "nvim-lua/plenary.nvim" },
{ "nvim-telescope/telescope-fzf-native.nvim" },
{ "nvim-telescope/telescope-ui-select.nvim" },
},
init = function()
U.cmd_executable("rg", {
[false] = function()
vim.notify("rg not installed, live grep will not function.", 2)
end,
})
end,
cmd = "Telescope",
opts = function()
return {
pickers = {
buffers = {
sort_lastused = true,
},
find_files = {
hidden = true,
sort_lastused = true,
},
live_grep = {
hidden = true,
},
},
defaults = {
file_ignore_patterns = { "node_modules", "package-lock.json", "target", ".git" },
mappings = {
i = {
["<C-j>"] = "move_selection_next",
["<C-k>"] = "move_selection_previous",
},
},
vimgrep_arguments = {
"rg",
"--hidden",
"--color=never",
"--no-heading",
"--with-filename",
"--line-number",
"--column",
"--smart-case",
},
},
extensions = {
["ui-select"] = {
require("telescope.themes").get_cursor(),
},
["notify"] = {},
},
}
end,
config = function(_, opts)
local ts = require("telescope")
ts.setup(opts)
ts.load_extension("ui-select")
if package.loaded["notify"] then
ts.load_extension("notify")
U.keymaps({
{
"<leader>fn",
"<cmd>Telescope notify<cr>",
desc = "Telescope search notifications",
mode = { "n", "v", "x" },
},
})
end
end,
-- https://github.com/nvim-telescope/telescope.nvim?tab=readme-ov-file#pickers
keys = {
{
"<leader>fr",
function()
require("telescope.builtin").resume()
end,
desc = "Resume last telescope",
},
{
"<leader>fj",
function()
require("telescope.builtin").current_buffer_fuzzy_find()
end,
desc = "Fuzzy find/search in current buffer fuzzy.",
},
{
"<leader>ff",
function()
require("telescope.builtin").find_files({
hidden = true,
})
end,
desc = "Find Files",
},
{
"<leader>fg",
function()
require("telescope.builtin").git_files({
hidden = true,
})
end,
desc = "Find Git only Files",
},
{
"<leader>fw",
function()
U.cmd_executable("rg", {
function()
require("telescope.builtin").live_grep({
hidden = true,
})
end,
function()
vim.notify("rg not installed, find words will not function.", 3)
end,
})
end,
desc = "Find Words",
},
{
"<leader>fc",
function()
require("telescope.builtin").commands()
end,
desc = "Find Commands",
},
{
"<leader>fk",
function()
require("telescope.builtin").keymaps()
end,
desc = "Find Commands",
},
{
"<leader>fb",
function()
require("telescope.builtin").buffers()
end,
desc = "Find Commands",
},
{
"<leader>lfr",
function()
require("telescope.builtin").lsp_references()
end,
desc = "Find References",
mode = { "n", "v", "x" },
},
},
}

View file

@ -0,0 +1,56 @@
return {
"nvim-treesitter/nvim-treesitter",
dependencies = { "windwp/nvim-ts-autotag", "JoosepAlviste/nvim-ts-context-commentstring" },
init = function()
U.cmd_executable("tree-sitter", {
[false] = function()
vim.notify("tree-sitter not installed, code syntax will be broken.", 2)
end,
})
end,
event = "BufRead",
cmd = {
"TSBufDisable",
"TSBufEnable",
"TSBufToggle",
"TSDisable",
"TSEnable",
"TSToggle",
"TSInstall",
"TSInstallInfo",
"TSInstallSync",
"TSModuleInfo",
"TSUninstall",
"TSUpdate",
"TSUpdateSync",
},
opts = function()
local nonNixOpts = {}
if not NIX then
nonNixOpts = {
ensure_installed = "all",
}
end
return U.assign({
highlight = {
enable = true,
use_languagetree = true,
disable = function(_, bufnr)
return vim.api.nvim_buf_line_count(bufnr) > 10000
end,
-- additional_vim_regex_highlighting = false,
},
incremental_selection = { enable = true },
ident = { enable = true },
autotag = { enable = true },
rainbow = {
enable = true,
extended_mode = true,
max_file_lines = nil,
},
}, nonNixOpts)
end,
config = function(_, opts)
require("nvim-treesitter.configs").setup(opts)
end,
}

View file

@ -1,5 +1,5 @@
-- Require all files in this tools dir, minus this init.lua file
function script_path()
local function script_path()
return debug.getinfo(2, "S").source:sub(2):match("(.*/)")
end
-- Extract the directory name from the script path

View file

@ -1,11 +1,12 @@
-- Function to remove item from quickfix list
function RemoveQFItem()
local curqfidx = vim.fn.line(".") - 1
local qfall = vim.fn.getqflist()
table.remove(qfall, curqfidx + 1) -- Lua is 1-indexed
vim.fn.setqflist(qfall, "r")
vim.cmd(curqfidx .. "cfirst")
vim.cmd("copen")
local function RemoveQFItem()
local currentIndex = vim.fn.line(".") - 1
local quickfixList = vim.fn.getqflist()
-- Remove current item and replace the quickfix list
table.remove(quickfixList, currentIndex + 1) -- Lua is 1-indexed
vim.fn.setqflist(quickfixList, "r")
-- Keep cursor on the line it was +1 (so it goes to next item rather than back up)
vim.cmd("cwindow | :" .. (currentIndex + 1))
end
-- Command to call the function

View file

@ -63,6 +63,7 @@ function M.keymap(keymap)
end
end
-- spread({})({})
function M.spread(template)
local result = {}
for key, value in pairs(template) do
@ -77,6 +78,14 @@ function M.spread(template)
end
end
-- assign({}, {})
function M.assign(obj, assign)
for key, value in pairs(assign) do
obj[key] = value
end
return obj
end
function M.table_contains(table, element)
for _, value in pairs(table) do
if value == element then
@ -109,4 +118,30 @@ function M.highlight(group, options)
)
end
function M.safeRequire(module, func, errorFunc)
local ok, result = pcall(require, module)
if ok then
return func(result)
elseif errorFunc then
return errorFunc(result)
end
return nil
end
function M.fnFalse()
return false
end
function M.fnNil()
return nil
end
function M.fnEmptyStr()
return ""
end
function M.fnZero()
return 0
end
return M