Skip to content

Commit

Permalink
basic snippets set up
Browse files Browse the repository at this point in the history
  • Loading branch information
handdara committed Nov 15, 2024
1 parent b563495 commit 05e7c0d
Show file tree
Hide file tree
Showing 14 changed files with 285 additions and 72 deletions.
6 changes: 5 additions & 1 deletion fst/him/nvim-nrw/init.lua
Original file line number Diff line number Diff line change
Expand Up @@ -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",
}
2 changes: 2 additions & 0 deletions fst/him/nvim-nrw/lazy-lock.json
Original file line number Diff line number Diff line change
Expand Up @@ -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" },
Expand All @@ -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" },
Expand Down
48 changes: 27 additions & 21 deletions fst/him/nvim-nrw/lua/handdara/config/keymap.lua
Original file line number Diff line number Diff line change
@@ -1,29 +1,35 @@
local map = vim.keymap.set

return function()
map({ 'n', 'v' }, '<Space>', '<Nop>', { silent = true }) -- space is my leader key
map('n', 'Q', '<Nop>', { silent = true })
map('i', 'kk', '<Esc>') -- Better feeling exit insert mode
map('t', '<C-/><C-/>', '<C-\\><C-n>') -- Better feeling exit term mode
map({ 'n', 'v' }, "<leader>y", [["+y]]) -- Access system clipboard
map('n', "<leader>Y", [["+Y]])
map('n', "<leader>pp", [["+p]], { desc = '[P]aste system clipboard' })
map('v', "<leader>p", [["_dP]]) -- Dont overwrite after pasting over text
map({ 'n', 'v' }, '<Space>', '<Nop>', { silent = true }) -- space is my leader key
map('n', 'Q', '<Nop>', { silent = true })
map('i', 'kk', '<Esc>') -- Better feeling exit insert mode
map('t', '<C-/><C-/>', '<C-\\><C-n>') -- Better feeling exit term mode
map({ 'n', 'v' }, "<leader>y", [["+y]]) -- Access system clipboard
map('n', "<leader>Y", [["+Y]])
map('n', "<leader>pp", [["+p]], { desc = '[P]aste system clipboard' })
map('v', "<leader>p", [["_dP]]) -- Dont overwrite after pasting over text

-- sorting paragraphs
map('v', '<leader>s', '!sort<CR>', { desc = '[S]ort highlighted' })
map('v', '<leader>gs', '!sort -r<CR>', { desc = 'reverse [S]ort highlighted' })
-- sorting paragraphs
map('v', '<leader>s', '!sort<CR>', { desc = '[S]ort highlighted' })
map('v', '<leader>gs', '!sort -r<CR>', { desc = 'reverse [S]ort highlighted' })

map('n', '<leader>dt', '<CMD>r!date -u \'+\\%F \\%T\'<CR>', { desc = 'insert [D]ate [T]ime' })
map('n', '<leader>dt', '<CMD>r!date -u \'+\\%F \\%T\'<CR>', { desc = 'insert [D]ate [T]ime' })

map('n', '<C-h>', "<C-w><C-h>") -- split movement
map('n', '<C-j>', "<C-w><C-j>")
map('n', '<C-k>', "<C-w><C-k>")
map('n', '<C-l>', "<C-w><C-l>")
map('n', '<C-h>', "<C-w><C-h>") -- split movement
map('n', '<C-j>', "<C-w><C-j>")
map('n', '<C-k>', "<C-w><C-k>")
map('n', '<C-l>', "<C-w><C-l>")

map('n', "<C-,>", "<c-w>5<") -- split resizing
map('n', "<C-.>", "<c-w>5>")
map('n', "<C-t>", "<C-W>+")
map('n', "<C-s>", "<C-W>-")
map('n', "<C-=>", "<C-W>=")
map('n', "<C-,>", "<c-w>5<") -- split resizing
map('n', "<C-.>", "<c-w>5>")
map('n', "<C-t>", "<C-W>+")
map('n', "<C-s>", "<C-W>-")
map('n', "<C-=>", "<C-W>=")

-- 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', '<leader>e', vim.diagnostic.open_float, { desc = 'Open floating diagnostic message' })
map('n', '<leader>q', vim.diagnostic.setloclist, { desc = 'Open diagnostics list' })
end
50 changes: 43 additions & 7 deletions fst/him/nvim-nrw/lua/handdara/config/looks.lua
Original file line number Diff line number Diff line change
@@ -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)
Expand Down
58 changes: 29 additions & 29 deletions fst/him/nvim-nrw/lua/handdara/config/set.lua
Original file line number Diff line number Diff line change
@@ -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
4 changes: 3 additions & 1 deletion fst/him/nvim-nrw/lua/handdara/lspconfig.lua
Original file line number Diff line number Diff line change
Expand Up @@ -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,
}
15 changes: 12 additions & 3 deletions fst/him/nvim-nrw/lua/handdara/luasnip.lua
Original file line number Diff line number Diff line change
Expand Up @@ -38,14 +38,23 @@ end

vim.snippet.stop = luasnip.unlink_current

vim.keymap.set({ "i", "s" }, "<C-j>", function()
vim.keymap.set({ "i", "s" }, '<C-j>', function()
return vim.snippet.active { direction = 1 } and vim.snippet.jump(1)
end, { silent = true })

vim.keymap.set({ "i", "s" }, "<C-k>", function()
vim.keymap.set({ "i", 's' }, '<C-k>', function()
return vim.snippet.active { direction = -1 } and vim.snippet.jump(-1)
end, { silent = true })

vim.keymap.set({ "i", "s" }, '<C-L>', 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'
8 changes: 8 additions & 0 deletions fst/him/nvim-nrw/lua/handdara/plugins/colors.lua
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
return {
{ "rose-pine/neovim", name = "rose-pine" },
{
"water-sucks/darkrose.nvim",
lazy = false,
priority = 1000,
},
}
46 changes: 36 additions & 10 deletions fst/him/nvim-nrw/lua/handdara/snippets/all.lua
Original file line number Diff line number Diff line change
@@ -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,
})
38 changes: 38 additions & 0 deletions fst/him/nvim-nrw/lua/handdara/snippets/lua.lua
Original file line number Diff line number Diff line change
@@ -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)} ))
})

19 changes: 19 additions & 0 deletions fst/him/nvim-nrw/lua/handdara/snippets/markdown.lua
Original file line number Diff line number Diff line change
@@ -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,
})
16 changes: 16 additions & 0 deletions fst/him/nvim-nrw/lua/handdara/snippets/matlab.lua
Original file line number Diff line number Diff line change
@@ -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", {
})
Loading

0 comments on commit 05e7c0d

Please sign in to comment.