From 05e7c0ddf7ab6a5d510f50fe38bde9b47c07d365 Mon Sep 17 00:00:00 2001 From: handdara Date: Fri, 15 Nov 2024 01:12:13 -0500 Subject: [PATCH] basic snippets set up --- fst/him/nvim-nrw/init.lua | 6 +- fst/him/nvim-nrw/lazy-lock.json | 2 + .../nvim-nrw/lua/handdara/config/keymap.lua | 48 ++++++++------- .../nvim-nrw/lua/handdara/config/looks.lua | 50 +++++++++++++--- fst/him/nvim-nrw/lua/handdara/config/set.lua | 58 +++++++++---------- fst/him/nvim-nrw/lua/handdara/lspconfig.lua | 4 +- fst/him/nvim-nrw/lua/handdara/luasnip.lua | 15 ++++- .../nvim-nrw/lua/handdara/plugins/colors.lua | 8 +++ .../nvim-nrw/lua/handdara/snippets/all.lua | 46 +++++++++++---- .../nvim-nrw/lua/handdara/snippets/lua.lua | 38 ++++++++++++ .../lua/handdara/snippets/markdown.lua | 19 ++++++ .../nvim-nrw/lua/handdara/snippets/matlab.lua | 16 +++++ .../nvim-nrw/lua/handdara/snippets/tex.lua | 19 ++++++ .../nvim-nrw/lua/handdara/snippets/util.lua | 28 +++++++++ 14 files changed, 285 insertions(+), 72 deletions(-) create mode 100644 fst/him/nvim-nrw/lua/handdara/plugins/colors.lua create mode 100644 fst/him/nvim-nrw/lua/handdara/snippets/lua.lua create mode 100644 fst/him/nvim-nrw/lua/handdara/snippets/markdown.lua create mode 100644 fst/him/nvim-nrw/lua/handdara/snippets/matlab.lua create mode 100644 fst/him/nvim-nrw/lua/handdara/snippets/tex.lua create mode 100644 fst/him/nvim-nrw/lua/handdara/snippets/util.lua diff --git a/fst/him/nvim-nrw/init.lua b/fst/him/nvim-nrw/init.lua index ed8e270..d71fee6 100644 --- a/fst/him/nvim-nrw/init.lua +++ b/fst/him/nvim-nrw/init.lua @@ -31,4 +31,8 @@ require("lazy").setup({ vim.cmd('colorscheme ' .. inital_colorscheme) -require 'handdara'.setup { colorscheme = "lunaperche" } +require 'handdara'.setup { + colorscheme = "rose-pine-moon", + -- colorscheme = "darkrose", + -- colorscheme = "lunaperche", +} diff --git a/fst/him/nvim-nrw/lazy-lock.json b/fst/him/nvim-nrw/lazy-lock.json index fec6a49..0455192 100644 --- a/fst/him/nvim-nrw/lazy-lock.json +++ b/fst/him/nvim-nrw/lazy-lock.json @@ -6,6 +6,7 @@ "cmp-nvim-lsp": { "branch": "main", "commit": "39e2eda76828d88b773cc27a3f61d2ad782c922d" }, "cmp-path": { "branch": "main", "commit": "91ff86cd9c29299a64f968ebb45846c485725f23" }, "cmp_luasnip": { "branch": "master", "commit": "98d9cb5c2c38532bd9bdb481067b20fea8f32e90" }, + "darkrose.nvim": { "branch": "main", "commit": "ce6ceb55332862e180264fa534d2ce4d70f02db2" }, "fidget.nvim": { "branch": "main", "commit": "0ba1e16d07627532b6cae915cc992ecac249fb97" }, "kmonad-vim": { "branch": "master", "commit": "37978445197ab00edeb5b731e9ca90c2b141723f" }, "lazy.nvim": { "branch": "main", "commit": "7967abe55752aa90532e6bb4bd4663fe27a264cb" }, @@ -19,6 +20,7 @@ "nvim-web-devicons": { "branch": "master", "commit": "19d257cf889f79f4022163c3fbb5e08639077bd8" }, "plenary.nvim": { "branch": "master", "commit": "2d9b06177a975543726ce5c73fca176cedbffe9d" }, "popup.nvim": { "branch": "master", "commit": "b7404d35d5d3548a82149238289fa71f7f6de4ac" }, + "rose-pine": { "branch": "main", "commit": "07a887a7bef4aacea8c7caebaf8cbf808cdc7a8e" }, "telekasten.nvim": { "branch": "main", "commit": "6a10a7929421d6e696e46bbc5aa5627a8cbcf61d" }, "telescope-fzf-native.nvim": { "branch": "main", "commit": "cf48d4dfce44e0b9a2e19a008d6ec6ea6f01a83b" }, "telescope-media-files.nvim": { "branch": "master", "commit": "0826c7a730bc4d36068f7c85cf4c5b3fd9fb570a" }, diff --git a/fst/him/nvim-nrw/lua/handdara/config/keymap.lua b/fst/him/nvim-nrw/lua/handdara/config/keymap.lua index 96da911..8b6b078 100644 --- a/fst/him/nvim-nrw/lua/handdara/config/keymap.lua +++ b/fst/him/nvim-nrw/lua/handdara/config/keymap.lua @@ -1,29 +1,35 @@ local map = vim.keymap.set return function() - map({ 'n', 'v' }, '', '', { silent = true }) -- space is my leader key - map('n', 'Q', '', { silent = true }) - map('i', 'kk', '') -- Better feeling exit insert mode - map('t', '', '') -- Better feeling exit term mode - map({ 'n', 'v' }, "y", [["+y]]) -- Access system clipboard - map('n', "Y", [["+Y]]) - map('n', "pp", [["+p]], { desc = '[P]aste system clipboard' }) - map('v', "p", [["_dP]]) -- Dont overwrite after pasting over text + map({ 'n', 'v' }, '', '', { silent = true }) -- space is my leader key + map('n', 'Q', '', { silent = true }) + map('i', 'kk', '') -- Better feeling exit insert mode + map('t', '', '') -- Better feeling exit term mode + map({ 'n', 'v' }, "y", [["+y]]) -- Access system clipboard + map('n', "Y", [["+Y]]) + map('n', "pp", [["+p]], { desc = '[P]aste system clipboard' }) + map('v', "p", [["_dP]]) -- Dont overwrite after pasting over text - -- sorting paragraphs - map('v', 's', '!sort', { desc = '[S]ort highlighted' }) - map('v', 'gs', '!sort -r', { desc = 'reverse [S]ort highlighted' }) + -- sorting paragraphs + map('v', 's', '!sort', { desc = '[S]ort highlighted' }) + map('v', 'gs', '!sort -r', { desc = 'reverse [S]ort highlighted' }) - map('n', 'dt', 'r!date -u \'+\\%F \\%T\'', { desc = 'insert [D]ate [T]ime' }) + map('n', 'dt', 'r!date -u \'+\\%F \\%T\'', { desc = 'insert [D]ate [T]ime' }) - map('n', '', "") -- split movement - map('n', '', "") - map('n', '', "") - map('n', '', "") + map('n', '', "") -- split movement + map('n', '', "") + map('n', '', "") + map('n', '', "") - map('n', "", "5<") -- split resizing - map('n', "", "5>") - map('n', "", "+") - map('n', "", "-") - map('n', "", "=") + map('n', "", "5<") -- split resizing + map('n', "", "5>") + map('n', "", "+") + map('n', "", "-") + map('n', "", "=") + + -- Diagnostic keymaps + map('n', '[d', vim.diagnostic.goto_prev, { desc = 'Go to previous diagnostic message' }) + map('n', ']d', vim.diagnostic.goto_next, { desc = 'Go to next diagnostic message' }) + map('n', 'e', vim.diagnostic.open_float, { desc = 'Open floating diagnostic message' }) + map('n', 'q', vim.diagnostic.setloclist, { desc = 'Open diagnostics list' }) end diff --git a/fst/him/nvim-nrw/lua/handdara/config/looks.lua b/fst/him/nvim-nrw/lua/handdara/config/looks.lua index cc1e96b..2d77fbd 100644 --- a/fst/him/nvim-nrw/lua/handdara/config/looks.lua +++ b/fst/him/nvim-nrw/lua/handdara/config/looks.lua @@ -1,12 +1,48 @@ local function set_looks(colorscheme) - local c = colorscheme or "lunaperche" + local c = colorscheme or "lunaperche" -- default is lunaperche b/c it's my favorite builtin colorscheme vim.cmd("colorscheme " .. c) - vim.cmd [[ - highlight Normal guibg=none - highlight NonText guibg=none - highlight Normal ctermbg=none - highlight NonText ctermbg=none - ]] + local groups = { + 'Normal', + 'NormalNC', + 'Comment', + 'Constant', + 'Special', + 'Identifier', + 'Statement', + 'PreProc', + 'Type', + 'Underlined', + 'Todo', + 'String', + 'Function', + 'Conditional', + 'Repeat', + 'Operator', + 'Structure', + 'LineNr', + 'NonText', + 'SignColumn', + 'CursorLine', + 'CursorLineNr', + 'EndOfBuffer', + } + ---@diagnostic disable-next-line: unused-local + local extra_groups = { + 'NormalFloat', + 'FloatBorder', + 'WhichKeyBorder', + 'FloatTitle', + 'TelescopeBorder', + 'TelescopeNormal', + } + local function apply(grps) + for _, value in ipairs(grps) do + vim.cmd('highlight ' .. value .. " guibg=none") + vim.cmd('highlight ' .. value .. " cterm=none") + end + end + apply(groups) + apply(extra_groups) end local function init_looks(colorscheme) diff --git a/fst/him/nvim-nrw/lua/handdara/config/set.lua b/fst/him/nvim-nrw/lua/handdara/config/set.lua index eebaa53..664d75e 100644 --- a/fst/him/nvim-nrw/lua/handdara/config/set.lua +++ b/fst/him/nvim-nrw/lua/handdara/config/set.lua @@ -1,31 +1,31 @@ return function() - vim.o.breakindent = true -- Enable break indent - vim.o.expandtab = true - vim.o.hlsearch = false -- highlight on search - vim.o.ignorecase = true -- Case-insensitive searching UNLESS \C or capital in search - vim.opt.colorcolumn = { 100 } - vim.o.shiftwidth = 2 - vim.o.showtabline = 0 - vim.o.smartcase = true - vim.o.softtabstop = 2 - vim.o.splitbelow = true - vim.o.splitright = true - vim.o.tabstop = 2 - vim.wo.number = true -- Make line numbers default and relative - vim.wo.relativenumber = true - vim.wo.signcolumn = 'no' -- Keep signcolumn on by default - vim.o.shell = "fish" - vim.o.termguicolors = true -- NOTE: make sure your terminal supports this - --[[ - [!IMPORTANT] - The next line is a wezterm/neovim display update bug workaround for using nvim in a wezterm mux - server. see [this issue](https://github.com/wez/wezterm/issues/4607 ) for more info. Also look - at `.../ansible/1-active-quests/hix/nvim-nix-rewrite.md` for more info as well. The bug should - be fixed when the fix linked in issue 4607 above is merged into main, and I believe the nightly - version of wezterm already includes it. - ]] - vim.opt.termsync = false - vim.o.updatetime = 250 -- Decrease update time - vim.o.timeoutlen = 300 - vim.o.undofile = true -- Save undo history + vim.o.breakindent = true -- Enable break indent + vim.o.expandtab = true + vim.o.hlsearch = false -- highlight on search + vim.o.ignorecase = true -- Case-insensitive searching UNLESS \C or capital in search + vim.opt.colorcolumn = { 100 } + vim.o.shiftwidth = 4 + vim.o.showtabline = 0 + vim.o.smartcase = true + vim.o.softtabstop = 4 + vim.o.splitbelow = true + vim.o.splitright = true + vim.o.tabstop = 4 + vim.wo.number = true -- Make line numbers default and relative + vim.wo.relativenumber = true + vim.wo.signcolumn = 'no' -- Keep signcolumn on by default + vim.o.shell = "fish" + vim.o.termguicolors = true -- NOTE: make sure your terminal supports this + --[[ + [!IMPORTANT] + The next line is a wezterm/neovim display update bug workaround for using nvim in a wezterm mux + server. see [this issue](https://github.com/wez/wezterm/issues/4607 ) for more info. Also look + at `.../ansible/1-active-quests/hix/nvim-nix-rewrite.md` for more info as well. The bug should + be fixed when the fix linked in issue 4607 above is merged into main, and I believe the nightly + version of wezterm already includes it. + ]] + vim.opt.termsync = false + vim.o.updatetime = 250 -- Decrease update time + vim.o.timeoutlen = 300 + vim.o.undofile = true -- Save undo history end diff --git a/fst/him/nvim-nrw/lua/handdara/lspconfig.lua b/fst/him/nvim-nrw/lua/handdara/lspconfig.lua index f810566..787496f 100644 --- a/fst/him/nvim-nrw/lua/handdara/lspconfig.lua +++ b/fst/him/nvim-nrw/lua/handdara/lspconfig.lua @@ -45,14 +45,16 @@ local on_attach = function(_, bufnr) end lspconf.marksman.setup { -- markdown lsp config - -- capabilities = capabilities, + capabilities = capabilities, on_attach = on_attach, } require 'lspconfig'.nil_ls.setup { -- nix lsp config + capabilities = capabilities, on_attach = on_attach, } require 'lspconfig'.lua_ls.setup { + capabilities = capabilities, on_attach = on_attach, } diff --git a/fst/him/nvim-nrw/lua/handdara/luasnip.lua b/fst/him/nvim-nrw/lua/handdara/luasnip.lua index 8908435..58f38f5 100644 --- a/fst/him/nvim-nrw/lua/handdara/luasnip.lua +++ b/fst/him/nvim-nrw/lua/handdara/luasnip.lua @@ -38,14 +38,23 @@ end vim.snippet.stop = luasnip.unlink_current -vim.keymap.set({ "i", "s" }, "", function() +vim.keymap.set({ "i", "s" }, '', function() return vim.snippet.active { direction = 1 } and vim.snippet.jump(1) end, { silent = true }) -vim.keymap.set({ "i", "s" }, "", function() +vim.keymap.set({ "i", 's' }, '', function() return vim.snippet.active { direction = -1 } and vim.snippet.jump(-1) end, { silent = true }) +vim.keymap.set({ "i", "s" }, '', function() + if luasnip.choice_active() then + luasnip.change_choice(1) + end +end, { silent = true }) + -- snippets for all files require 'handdara.snippets.all' - +require 'handdara.snippets.tex' +require 'handdara.snippets.lua' +require 'handdara.snippets.markdown' +require 'handdara.snippets.matlab' diff --git a/fst/him/nvim-nrw/lua/handdara/plugins/colors.lua b/fst/him/nvim-nrw/lua/handdara/plugins/colors.lua new file mode 100644 index 0000000..260f88b --- /dev/null +++ b/fst/him/nvim-nrw/lua/handdara/plugins/colors.lua @@ -0,0 +1,8 @@ +return { + { "rose-pine/neovim", name = "rose-pine" }, + { + "water-sucks/darkrose.nvim", + lazy = false, + priority = 1000, + }, +} diff --git a/fst/him/nvim-nrw/lua/handdara/snippets/all.lua b/fst/him/nvim-nrw/lua/handdara/snippets/all.lua index fcae29b..1479acc 100644 --- a/fst/him/nvim-nrw/lua/handdara/snippets/all.lua +++ b/fst/him/nvim-nrw/lua/handdara/snippets/all.lua @@ -1,16 +1,42 @@ -require('luasnip.session.snippet_collection').clear_snippets "lua" - +---@diagnostic disable: unused-local +require('luasnip.session.snippet_collection').clear_snippets "all" local ls = require 'luasnip' local s = ls.snippet local t = ls.text_node local i = ls.insert_node +local c = ls.choice_node +local f = ls.function_node +local extras = require 'luasnip.extras' +local rep = extras.rep +local fmt = require("luasnip.extras.fmt").fmt +local u = require 'handdara.snippets.util' + +-- local bchoose = [[Choose your weapon: {}]] +-- local weapons = { +-- t('sword'), +-- t('gun'), +-- t('spell'), +-- t('beer'), +-- } +-- local schoose = s("choose", +-- fmt(bchoose, { c(1, weapons) }) +-- ) + +local sdate = s("date", { + f(function() + local ts = u.timestamp() + return ts.dy .. ts.mo .. ts.yr + end), +}) + +local sdatetime = s("datetime", { + f(function() + local ts = u.timestamp() + return ts.dy .. ts.mo .. ts.yr .. ' ' .. ts.hr .. ts.mi + end), +}) -ls.add_snippets("lua", { - s("hello", { - t('print("hello '), - i(1), - t('. What a great '), - i(2), - t('!")'), - }) +ls.add_snippets("all", { + sdate, + sdatetime, }) diff --git a/fst/him/nvim-nrw/lua/handdara/snippets/lua.lua b/fst/him/nvim-nrw/lua/handdara/snippets/lua.lua new file mode 100644 index 0000000..97183f2 --- /dev/null +++ b/fst/him/nvim-nrw/lua/handdara/snippets/lua.lua @@ -0,0 +1,38 @@ +---@diagnostic disable: unused-local +require('luasnip.session.snippet_collection').clear_snippets "lua" +local ls = require 'luasnip' +local s = ls.snippet +local t = ls.text_node +local i = ls.insert_node +local c = ls.choice_node +local f = ls.function_node +local d = ls.dynamic_node +local extras = require 'luasnip.extras' +local rep = extras.rep +local fmt = require("luasnip.extras.fmt").fmt +local u = require 'handdara.snippets.util' + +local bsnipfile = [[ +---@diagnostic disable: unused-local +require('luasnip.session.snippet_collection').clear_snippets "{}" +local ls = require 'luasnip' +local s = ls.snippet +local t = ls.text_node +local i = ls.insert_node +local c = ls.choice_node +local f = ls.function_node +local d = ls.dynamic_node +local extras = require 'luasnip.extras' +local rep = extras.rep +local fmt = require("luasnip.extras.fmt").fmt +local u = require 'handdara.snippets.util' + +ls.add_snippets("{}", {{ + {}, +}}) +]] + +ls.add_snippets("lua", { + s("luasnipfile", fmt(bsnipfile, {i(1), rep(1), i(0)} )) +}) + diff --git a/fst/him/nvim-nrw/lua/handdara/snippets/markdown.lua b/fst/him/nvim-nrw/lua/handdara/snippets/markdown.lua new file mode 100644 index 0000000..20546b8 --- /dev/null +++ b/fst/him/nvim-nrw/lua/handdara/snippets/markdown.lua @@ -0,0 +1,19 @@ +---@diagnostic disable: unused-local +require('luasnip.session.snippet_collection').clear_snippets "markdown" +local ls = require 'luasnip' +local s = ls.snippet +local t = ls.text_node +local i = ls.insert_node +local c = ls.choice_node +local f = ls.function_node +local d = ls.dynamic_node +local extras = require 'luasnip.extras' +local rep = extras.rep +local fmt = require("luasnip.extras.fmt").fmt +local u = require 'handdara.snippets.util' + + + +ls.add_snippets("markdown", { + -- s, +}) diff --git a/fst/him/nvim-nrw/lua/handdara/snippets/matlab.lua b/fst/him/nvim-nrw/lua/handdara/snippets/matlab.lua new file mode 100644 index 0000000..b3a86f7 --- /dev/null +++ b/fst/him/nvim-nrw/lua/handdara/snippets/matlab.lua @@ -0,0 +1,16 @@ +---@diagnostic disable: unused-local +require('luasnip.session.snippet_collection').clear_snippets "matlab" +local ls = require 'luasnip' +local s = ls.snippet +local t = ls.text_node +local i = ls.insert_node +local c = ls.choice_node +local f = ls.function_node +local d = ls.dynamic_node +local extras = require 'luasnip.extras' +local rep = extras.rep +local fmt = require("luasnip.extras.fmt").fmt +local u = require 'handdara.snippets.util' + +ls.add_snippets("matlab", { +}) diff --git a/fst/him/nvim-nrw/lua/handdara/snippets/tex.lua b/fst/him/nvim-nrw/lua/handdara/snippets/tex.lua new file mode 100644 index 0000000..b0f8d3f --- /dev/null +++ b/fst/him/nvim-nrw/lua/handdara/snippets/tex.lua @@ -0,0 +1,19 @@ +require('luasnip.session.snippet_collection').clear_snippets "tex" + +local ls = require 'luasnip' +local s = ls.snippet +local t = ls.text_node +local i = ls.insert_node +local extras = require 'luasnip.extras' +local rep = extras.rep +local fmt = require("luasnip.extras.fmt").fmt + +local bbeg = [[ +\begin{{{}}} + {} +\end{{{}}} +]] + +ls.add_snippets("tex", { + s("begin", fmt(bbeg, {i(1), i(0), rep(1)})) +}) diff --git a/fst/him/nvim-nrw/lua/handdara/snippets/util.lua b/fst/him/nvim-nrw/lua/handdara/snippets/util.lua new file mode 100644 index 0000000..1d94b51 --- /dev/null +++ b/fst/him/nvim-nrw/lua/handdara/snippets/util.lua @@ -0,0 +1,28 @@ +-- datetime number to string +local function dtnum2str(x) + local xs = tostring(x) + if x < 10 then + return '0' .. xs + else + return xs + end +end + +local function timestamp() + local ts = os.date('*t') + local months = { 'jan', 'feb', 'mar', 'apr', 'may', 'jun', 'jul', 'aug', 'sep', 'oct', 'nov', 'dec' } + local weekdays = { 'Sun', 'Mon', 'Tue', 'Wed', 'Thu', 'Fri', 'Sat' } + return { + yr = tostring(ts.year), + dy = tostring(ts.day), + mo = months[ts.month], + wd = weekdays[ts.wday], + hr = dtnum2str(ts.hour), + mi = dtnum2str(ts.min), + } +end + +return { + timestamp = timestamp, + dtnum2str = dtnum2str, +}