feat: Updates to nvim config and snippets

This commit is contained in:
2024-11-18 08:33:38 -05:00
parent eff01f42fd
commit 2e3c750979
11 changed files with 176 additions and 264 deletions

View File

@@ -16,9 +16,3 @@ require("user.theme")
-- Common settings
require("user.settings")
-- Snippets are setup in the luasnip settings, they get loaded from the snippets directory
-- based on filetype.
--require("user.snippets")
vim.o.shiftwidth = 2

View File

@@ -1,85 +1,41 @@
local defaultGroupOptions = { clear = true }
local markdownGroup = vim.api.nvim_create_augroup("MyMarkdownGroup", defaultGroupOptions)
local spellGroup = vim.api.nvim_create_augroup('SpellGroup', defaultGroupOptions)
local spellGroup = vim.api.nvim_create_augroup("SpellGroup", defaultGroupOptions)
local createCmd = vim.api.nvim_create_autocmd
local swiftGroup = vim.api.nvim_create_augroup('swift_lsp', { clear = true })
-- Remove all trailing whitespace on save
vim.api.nvim_exec([[
augroup TrimWhiteSpace
au!
autocmd BufWritePre * :%s/\s\+$//e
augroup END
]], false)
-- Prevent new line to also start with a comment
vim.api.nvim_exec([[
augroup NewLineComment
au!
au FileType * setlocal formatoptions-=c formatoptions-=r formatoptions-=o
augroup END
]], false)
-- Spell check
createCmd(
"BufEnter",
{
pattern = { '*.md', '*.markdown', '*.txt', '*.tex' },
group = spellGroup,
callback = function(_)
vim.cmd.setlocal('textwidth=80')
vim.cmd.setlocal('spell spelllang=en_us')
end,
}
)
createCmd("BufEnter", {
pattern = { "*.md", "*.markdown", "*.txt", "*.tex" },
group = spellGroup,
callback = function(_)
vim.cmd.setlocal("textwidth=80")
vim.cmd.setlocal("spell spelllang=en_us")
end,
})
-- Markdown
createCmd(
"BufWritePost",
{
pattern = { "*.md", "*.markdown" },
group = markdownGroup,
callback = function(_)
local cursor = vim.fn.getpos('.')
vim.cmd("FormatWrite")
vim.fn.setpos('.', cursor)
end,
}
)
createCmd("BufWritePost", {
pattern = { "*.md", "*.markdown" },
group = markdownGroup,
callback = function(_)
local cursor = vim.fn.getpos(".")
vim.cmd("FormatWrite")
vim.fn.setpos(".", cursor)
end,
})
-- Go
createCmd(
"BufWritePre",
{
pattern = "*.go",
callback = function()
require('go.format').goimport()
end,
group = vim.api.nvim_create_augroup("GoFormat", defaultGroupOptions)
}
)
createCmd("BufWritePre", {
pattern = "*.go",
callback = function()
require("go.format").goimport()
end,
group = vim.api.nvim_create_augroup("GoFormat", defaultGroupOptions),
})
vim.api.nvim_exec([[
vim.api.nvim_exec2(
[[
autocmd BufNewFile,BufRead /private/**/gopass** setlocal noswapfile nobackup noundofile shada=""
]], false)
-- Swift
-- createCmd(
-- "FileType",
-- {
-- pattern = { 'swift' },
-- callback = function()
-- local root_dir = vim.fs.dirname(vim.fs.find({
-- "Package.swift",
-- ".git",
-- }, { upward = true })[1])
-- local client = vim.lsp.start({
-- name = "sourcekit-lsp",
-- cmd = { "sourcekit-lsp" },
-- root_dir = root_dir
-- })
-- vim.lsp.buf_attach_client(0, client)
-- end,
-- group = swiftGroup
-- }
-- )
]],
{}
)

View File

@@ -36,7 +36,6 @@ wk_add("n", {
{ "<leader>n", "<CMD>:noh<CR>", desc = "[N]o highlighting" },
{ "<leader>s", "<CMD>:set spell!<CR>", desc = "[S]pell check toggle" },
--{ "<C-n>", "<CMD>:Neotree toggle<CR>", desc = "Toggle Neotree" },
{ "<C-s>", "<CMD>:write<CR>", desc = "[S]ave" },
{ "J", ":move .+1<CR>==", desc = "Move line down" },
@@ -62,14 +61,7 @@ wk_add("n", {
--------------------------------------------------------------------------------
-- Visual Mode
--------------------------------------------------------------------------------
-- wk_add("v", {
-- { "p", "\"_dP", desc = "[P]aste" },
-- })
-- wk_add("v", {
-- { "K", ":move '<-2<CR>", desc = "Move selected block up" },
-- { "J", ":move '>+1<CR>", desc = "Move selected block down" },
-- })
vim.keymap.set("v", "K", ":move '<-2<CR>gv=gv", { desc = "Move selected block up.", silent = true, noremap = true })
vim.keymap.set("v", "J", ":move '>+1<CR>gv=gv", { desc = "Move selected block up.", silent = true, noremap = true })
@@ -79,33 +71,3 @@ function _G.set_terminal_keymaps()
keymap("t", "<esc>", [[<C-\><C-n>]], opts)
end
vim.cmd("autocmd! TermOpen term://* lua set_terminal_keymaps()")
-- LuaSnip Keymaps
--local ls = require('luasnip')
-- <c-k> to expand snippets.
-- This will expand the snippet or jump to the next item within the snippet.
-- vim.keymap.set({ "i", "s" }, "<c-k>", function()
-- if ls.expand_or_jumpable() then
-- ls.expand_or_jump()
-- end
-- end, { silent = true })
-- <c-j>
-- This will jump backwards in the snippet.
-- vim.keymap.set({ "i", "s" }, "<c-j>", function()
-- if ls.jumpable(-1) then
-- ls.jump(-1)
-- end
-- end, { silent = true })
-- <c-l>
-- This is for selecting withing a list of options.
-- vim.keymap.set("i", "<c-l>", function()
-- if ls.choice_active() then
-- ls.change_choice(1)
-- end
-- end, { silent = true })
-- Reload the snippets.
--vim.keymap.set("n", "<leader><leader>s", "<cmd>source ~/.config/m-housh/lua/snippets/init.lua<cr>")

View File

@@ -14,6 +14,8 @@ return {
local luasnip = require("luasnip")
local lspkind = require("lspkind")
-- TODO: This is implemented in LuaSnip config, does it need to be here?
-- loads vscode style snippets from installed plugins (e.g. friendly-snippets)
require("luasnip.loaders.from_vscode").lazy_load()
@@ -32,6 +34,9 @@ return {
["<C-Space>"] = cmp.mapping.complete(), -- show completion suggestions
["<C-e>"] = cmp.mapping.abort(), -- close completion window
["<CR>"] = cmp.mapping.confirm({ select = false, behavior = cmp.ConfirmBehavior.Replace }),
-- TODO:
-- The next two mappings are also implemented in the LuaSnip configuration,
-- as <C-j> and <C-k> do they actually need to be here??
["<C-b>"] = cmp.mapping(function(fallback)
if luasnip.jumpable(-1) then
luasnip.jump(-1)

View File

@@ -1,31 +1,2 @@
-- This file contains plugin's that don't require much configuration.
return {
-- {
-- "L3MON4D3/LuaSnip",
-- version = "2.*",
-- build = "make install_jsregexp",
-- event = { 'BufReadPre', 'BufNewFile' },
-- config = function()
-- local luasnip = require('luasnip')
-- local types = require('luasnip.util.types')
-- luasnip.config.set_config {
-- history = true,
-- updateevents = "TextChanged,TextChangedI",
-- enable_autosnippets = true,
-- ext_opts = {
-- [types.choiceNode] = {
-- active = {
-- virt_text = { { "<-", "Error" } },
-- },
-- },
-- },
-- }
-- end
-- },
{
"hrsh7th/vim-vsnip",
config = function()
vim.g.vsnip_snippet_dir = os.getenv('HOME') .. '/.config/m-housh/lua/snippets/'
end
},
}
return {}

View File

@@ -74,6 +74,7 @@ return {
-- more details: https://github.com/neovim/neovim/issues/19237#issuecomment-2237037154
client.offset_encoding = "utf-8"
end,
cmd = lsp == "sourcekit" and { vim.trim(vim.fn.system("xcrun -f sourcekit-lsp")) } or nil,
})
end
@@ -84,6 +85,7 @@ return {
vim.fn.sign_define(hl, { text = icon, texthl = hl, numhl = "" })
end
-- For some reason I was having trouble getting this to work inside the on-attach, so it's here.
vim.keymap.set("n", "<leader>rn", vim.lsp.buf.rename, { desc = "[R]e-[N]ame" })
end,
}

View File

@@ -11,9 +11,8 @@ return {
["<M-h>"] = "actions.select_split",
},
view_options = {
--show_hidden = true,
is_hidden_file = function(name, bufnr)
-- Don't show .DS_STORE in output.
is_hidden_file = function(name, _) -- second arg is bufnr, but not currently used.
-- Don't show .DS_Store in output.
local is_ds_store = name ~= ".DS_Store"
return not is_ds_store
end,
@@ -25,5 +24,8 @@ return {
-- Open parent directory in floating window.
vim.keymap.set("n", "<space>-", require("oil").toggle_float)
-- Old habits die hard, map what used to toggle neo-tree to just open a float.
vim.keymap.set("n", "<C-n>", require("oil").toggle_float)
end,
}

View File

@@ -27,14 +27,18 @@ return {
},
mappings = {
i = {
-- Close on first esc instead of gonig to normal mode
-- Close on first esc instead of going to normal mode
["<esc>"] = actions.close,
["<A-q>"] = actions.send_selected_to_qflist,
["<C-q>"] = actions.send_to_qflist,
["<s-tab>"] = actions.toggle_selection + actions.move_selection_next,
["<tab>"] = actions.toggle_selection + actions.move_selection_previous,
["<C-j>"] = actions.move_selection_next,
["<C-k>"] = actions.move_selection_previous,
},
n = {
["<C-j>"] = actions.move_selection_next,
["<C-k>"] = actions.move_selection_previous,
["<s-tab>"] = actions.toggle_selection + actions.move_selection_next,
["<tab>"] = actions.toggle_selection + actions.move_selection_previous,
["<A-q>"] = actions.send_selected_to_qflist,

View File

@@ -77,46 +77,3 @@ return {
vim.keymap.set("n", "<leader>xa", "<cmd>XcodebuildCodeActions<cr>", { desc = "Show Code Actions" })
end,
}
-- return {
-- "wojciech-kulik/xcodebuild.nvim",
-- dependencies = {
-- "nvim-telescope/telescope.nvim",
-- "MunifTanjim/nui.nvim",
-- "nvim-neo-tree/neo-tree.nvim", -- (optional) to manage project files
-- "stevearc/oil.nvim", -- (optional) to manage project files
-- "nvim-treesitter/nvim-treesitter", -- (optional) for Quick tests support (required Swift parser)
-- },
-- config = function()
-- require("xcodebuild").setup({
-- -- put some options here or leave it empty to use default settings
-- code_coverage = {
-- enabled = true
-- }
-- })
--
-- vim.keymap.set("n", "<leader>X", "<cmd>XcodebuildPicker<cr>", { desc = "Show Xcodebuild Actions" })
-- vim.keymap.set("n", "<leader>xf", "<cmd>XcodebuildProjectManager<cr>", { desc = "Show Project Manager Actions" })
--
-- vim.keymap.set("n", "<leader>xb", "<cmd>XcodebuildBuild<cr>", { desc = "Build Project" })
-- vim.keymap.set("n", "<leader>xB", "<cmd>XcodebuildBuildForTesting<cr>", { desc = "Build For Testing" })
-- vim.keymap.set("n", "<leader>xr", "<cmd>XcodebuildBuildRun<cr>", { desc = "Build & Run Project" })
--
-- vim.keymap.set("n", "<leader>xt", "<cmd>XcodebuildTest<cr>", { desc = "Run Tests" })
-- vim.keymap.set("v", "<leader>xt", "<cmd>XcodebuildTestSelected<cr>", { desc = "Run Selected Tests" })
-- vim.keymap.set("n", "<leader>xT", "<cmd>XcodebuildTestClass<cr>", { desc = "Run Current Test Class" })
-- vim.keymap.set("n", "<leader>x.", "<cmd>XcodebuildTestRepeat<cr>", { desc = "Repeat Last Test Run" })
--
-- vim.keymap.set("n", "<leader>xl", "<cmd>XcodebuildToggleLogs<cr>", { desc = "Toggle Xcodebuild Logs" })
-- vim.keymap.set("n", "<leader>xc", "<cmd>XcodebuildToggleCodeCoverage<cr>", { desc = "Toggle Code Coverage" })
-- vim.keymap.set("n", "<leader>xC", "<cmd>XcodebuildShowCodeCoverageReport<cr>", { desc = "Show Code Coverage Report" })
-- vim.keymap.set("n", "<leader>xe", "<cmd>XcodebuildTestExplorerToggle<cr>", { desc = "Toggle Test Explorer" })
-- vim.keymap.set("n", "<leader>xs", "<cmd>XcodebuildFailingSnapshots<cr>", { desc = "Show Failing Snapshots" })
--
-- vim.keymap.set("n", "<leader>xd", "<cmd>XcodebuildSelectDevice<cr>", { desc = "Select Device" })
-- vim.keymap.set("n", "<leader>xp", "<cmd>XcodebuildSelectTestPlan<cr>", { desc = "Select Test Plan" })
-- vim.keymap.set("n", "<leader>xq", "<cmd>Telescope quickfix<cr>", { desc = "Show QuickFix List" })
--
-- vim.keymap.set("n", "<leader>xx", "<cmd>XcodebuildQuickfixLine<cr>", { desc = "Quickfix Line" })
-- vim.keymap.set("n", "<leader>xa", "<cmd>XcodebuildCodeActions<cr>", { desc = "Show Code Actions" })
-- end,
-- }

View File

@@ -1,57 +1,56 @@
-- Bootstrap Lazy.
local lazypath = vim.fn.stdpath("data") .. "/lazy/lazy.nvim"
if not vim.loop.fs_stat(lazypath) then
vim.fn.system({
"git",
"clone",
"--filter=blob:none",
"https://github.com/folke/lazy.nvim.git",
"--branch=stable", -- latest stable release
lazypath,
})
vim.fn.system({
"git",
"clone",
"--filter=blob:none",
"https://github.com/folke/lazy.nvim.git",
"--branch=stable", -- latest stable release
lazypath,
})
end
vim.opt.rtp:prepend(lazypath)
require("lazy").setup({
dev = {
path = '~/LocalProjects/plugins',
fallback = true
},
-- Import all the plugin configs in the 'plugin' directory
{ import = 'user.plugin' },
-- Plugins that don't have a configuration file.
{
"folke/zen-mode.nvim",
opts = { }
},
{
"christoomey/vim-tmux-navigator",
lazy = false,
},
{
"NMAC427/guess-indent.nvim",
opts = { }
},
{ "NoahTheDuke/vim-just", ft = { "just" } },
{
'chipsenkbeil/distant.nvim',
branch = 'v0.3',
config = function()
require('distant'):setup()
end
},
-- LSP, formatting, etc. --
{ 'folke/neodev.nvim', opts = {} },
dev = {
path = "~/LocalProjects/plugins",
fallback = true,
},
-- Import all the plugin configs in the 'plugin' directory
{ import = "user.plugin" },
-- Plugins that don't have a configuration file.
{
"folke/zen-mode.nvim",
opts = {},
},
{
"christoomey/vim-tmux-navigator",
lazy = false,
},
-- {
-- "NMAC427/guess-indent.nvim",
-- opts = { }
-- },
{ "NoahTheDuke/vim-just", ft = { "just" } },
{
"chipsenkbeil/distant.nvim",
branch = "v0.3",
config = function()
require("distant"):setup()
end,
},
-- LSP, formatting, etc. --
{ "folke/neodev.nvim", opts = {} },
}, {
checker = {
enabled = true,
notify = false
},
change_detection = {
notify = false
}
checker = {
enabled = true,
notify = false,
},
change_detection = {
notify = false,
},
})
vim.keymap.set("n", "<leader>ll", "<CMD>Lazy<CR>", { desc = "Open [L]azy" })

View File

@@ -15,50 +15,110 @@ ls.add_snippets("swift", {
s("@d", fmt("@Dependency(\\.{}) var {}", { i(1), rep(1) })),
-- Add a dependency client.
s("@dc", fmt([[
s(
{
trig = "@dc",
desc = "Add a dependency client.",
},
fmt(
[[
public extension DependencyValues {{
var {}: {} {{
get: {{ self[{}.self] }}
set: {{ self[{}.self] = newValue }}
get {{ self[{}.self] }}
set {{ self[{}.self] = newValue }}
}}
}}
@DependencyClient
struct {} {{
public struct {} {{
// Insert interface here.
{}
}}
extension {}: TestDependencyKey {{
static let testValue: {} = Self()
public static let testValue: {} = Self()
}}
]], {
i(1, "<var-name>"),
i(2, "<Type>"),
rep(2),
rep(2),
rep(2),
rep(2),
rep(2),
})
]],
{
i(1, "<name>"),
i(2, "<Dependency>"),
rep(2),
rep(2),
rep(2),
i(0),
rep(2),
rep(2),
}
)
),
-- Add spi modifier snippet.
s("spi", fmt("@_spi({})", { i(1, "name") })),
s(
{ trig = "str", desc = "Add a struct" },
fmt(
[[
struct {}: {} {{
{}
}}
]],
{ i(1, "<Name>"), i(2, "<Protocols>"), i(0) }
)
),
-- Add spi import modifier snippet.
s("sii", fmt("@_spi({}) import {}", { i(1, "name"), i(2, "modlue") })),
s({ trig = "spi", desc = "Add spi modifier." }, fmt("@_spi({})", { i(1, "name") })),
-- Document a function.
s("doc", fmt([[
s(
{ trig = "sii", desc = "Import with spi." },
fmt(
[[
@_spi({}) import {}
{}
]],
{ i(1, "name"), i(2, "modlue"), i(0) }
)
),
s(
{ trig = "docf", desc = "Document a function." },
fmt(
[[
/// {}
///
/// - Parameters:
/// - {}: {}
]], { i(1, "A short description."), i(2, "<param>"), i(3, "<param-description>") }
)),
]],
{ i(1, "A short description."), i(2, "<param>"), i(3, "<param-description>") }
)
),
s("param", fmt([[
s(
{ trig = "param", desc = "Add a parameter to documentation" },
fmt(
[[
/// - {}: {}
]], { i(1, "<param>"), i(2, "<description>") })),
]],
{ i(1, "<param>"), i(2, "<description>") }
)
),
s(
{ trig = "wd", desc = "withDependencies" },
fmt(
[[
withDependencies {{
$0.{} = {}
}} operation: {{
@Dependency(\.{}) var {}
{}
}}
]],
{
i(1, "<dependency>"),
i(2, "<override>"),
rep(1),
rep(1),
i(0),
}
)
),
})