fixed some issues that have been bothering me.

This commit is contained in:
Solomon Laing 2023-02-27 21:48:31 +10:30
parent 0f976b5d74
commit 61f0e55271
4 changed files with 55 additions and 71 deletions

View File

@ -40,41 +40,41 @@ vim.api.nvim_create_autocmd({ "VimEnter" }, {
-- go to last loc when opening a buffer
vim.api.nvim_create_autocmd("BufReadPost", {
callback = function()
local mark = vim.api.nvim_buf_get_mark(0, '"')
local lcount = vim.api.nvim_buf_line_count(0)
if mark[1] > 0 and mark[1] <= lcount then
pcall(vim.api.nvim_win_set_cursor, 0, mark)
end
end,
callback = function()
local mark = vim.api.nvim_buf_get_mark(0, '"')
local lcount = vim.api.nvim_buf_line_count(0)
if mark[1] > 0 and mark[1] <= lcount then
pcall(vim.api.nvim_win_set_cursor, 0, mark)
end
end,
})
-- close some filetypes with <q>
vim.api.nvim_create_autocmd("FileType", {
pattern = {
"qf",
"help",
"man",
"notify",
"lspinfo",
"spectre_panel",
"startuptime",
"tsplayground",
"PlenaryTestPopup",
},
callback = function(event)
vim.bo[event.buf].buflisted = false
vim.keymap.set("n", "q", "<cmd>close<cr>", { buffer = event.buf, silent = true })
end,
pattern = {
"qf",
"help",
"man",
"notify",
"lspinfo",
"spectre_panel",
"startuptime",
"tsplayground",
"PlenaryTestPopup",
},
callback = function(event)
vim.bo[event.buf].buflisted = false
vim.keymap.set("n", "q", "<cmd>close<cr>", { buffer = event.buf, silent = true })
end,
})
-- add spellcheck and wrapping to some file types
vim.api.nvim_create_autocmd("FileType", {
pattern = { "gitcommit", "markdown" },
callback = function()
vim.opt_local.wrap = true
vim.opt_local.spell = true
end,
pattern = { "gitcommit", "markdown" },
callback = function()
vim.opt_local.wrap = true
vim.opt_local.spell = true
end,
})
-- Prevent auto comment on next line
@ -84,16 +84,18 @@ vim.cmd([[autocmd FileType * setlocal formatoptions-=c formatoptions-=r formatop
vim.cmd([[autocmd BufRead,BufNewFile *.tex set filetype=tex]])
-- Trim whitespace from files on save
vim.cmd [[
vim.cmd([[
autocmd BufWritePre * let currPos = getpos(".")
autocmd BufWritePre * %s/\s\+$//e
autocmd BufWritePre * %s/\n\+\%$//e
autocmd BufWritePre *.[ch] %s/\%$/\r/e
autocmd BufWritePre * cal cursor(currPos[1], currPos[2])
]]
]])
-- Recompile and restart Xmonad on save of config file for Xmonad or Xmobar
vim.cmd([[autocmd BufWritePost ~/.xmonad/xmonad.hs,~/.config/xmobar/xmobar-main.hs,~/.config/xmobar/xmobar-sub.hs,~/.config/xmobar/xmobar-single.hs !xmonad --recompile && xmonad --restart]])
vim.cmd(
[[autocmd BufWritePost ~/.xmonad/xmonad.hs,~/.config/xmobar/xmobar-main.hs,~/.config/xmobar/xmobar-sub.hs,~/.config/xmobar/xmobar-single.hs !xmonad --recompile && xmonad --restart]]
)
-- Run custom textclear command when exiting a .tex file (cleanup files)
vim.cmd([[autocmd VimLeave *.tex !texclear %]])

View File

@ -26,22 +26,8 @@ return {
["<C-Space>"] = cmp.mapping.complete(),
["<C-e>"] = cmp.mapping.abort(),
["<CR>"] = cmp.mapping.confirm({ select = true }), -- Accept currently selected item. Set `select` to `false` to only confirm explicitly selected items.
["<Tab>"] = cmp.mapping(function(fallback)
if cmp.visible() then
cmp.select_next_item()
end
end, {
"i",
"s",
}),
["<S-Tab>"] = cmp.mapping(function(fallback)
if cmp.visible() then
cmp.select_prev_item()
end
end, {
"i",
"s",
}),
["<C-n>"] = cmp.mapping.select_next_item({ behavior = cmp.SelectBehavior.Insert }),
["<C-p>"] = cmp.mapping.select_prev_item({ behavior = cmp.SelectBehavior.Insert }),
}),
sources = cmp.config.sources({
{ name = "nvim_lsp" },

View File

@ -21,7 +21,7 @@ return {
},
servers = {
jsonls = {},
lua_ls = {
sumneko_lua = {
settings = {
Lua = {
workspace = {
@ -33,15 +33,6 @@ return {
},
},
},
-- arduino_language_server = {
-- cmd = {
-- "arduino-language-server",
-- "-cli-config",
-- "/home/solomon/.arduino15/arduino-cli.yaml",
-- "-fqbn",
-- "arduino:avr:uno",
-- },
-- },
},
setup = {
-- additional setup can be added here.
@ -84,14 +75,6 @@ return {
require("lspconfig")[server].setup(server_opts)
end
-- temp fix for lspconfig rename
-- https://github.com/neovim/nvim-lspconfig/pull/2439
local mappings = require("mason-lspconfig.mappings.server")
if not mappings.lspconfig_to_package.lua_ls then
mappings.lspconfig_to_package.lua_ls = "lua-language-server"
mappings.package_to_lspconfig["lua-language-server"] = "lua_ls"
end
local mlsp = require("mason-lspconfig")
local available = mlsp.get_available_servers()

View File

@ -4,10 +4,24 @@ return {
cmd = "NvimTreeToggle",
config = function()
local nvim_tree = require("nvim-tree")
local nvim_tree_config = require("nvim-tree.config")
local icons = require("lazyvim.config.icons")
local tree_cb = nvim_tree_config.nvim_tree_callback
local function edit_or_open()
-- open as vsplit on current node
local action = "edit"
local node = lib.get_node_at_cursor()
-- Just copy what's done normally with vsplit
if node.link_to and not node.nodes then
require("nvim-tree.actions.node.open-file").fn(action, node.link_to)
view.close() -- Close the tree if file was opened
elseif node.nodes ~= nil then
lib.expand_or_collapse(node)
else
require("nvim-tree.actions.node.open-file").fn(action, node.absolute_path)
view.close() -- Close the tree if file was opened
end
end
nvim_tree.setup({
hijack_directories = {
@ -95,16 +109,15 @@ return {
width = 30,
hide_root_folder = false,
side = "left",
number = false,
relativenumber = false,
mappings = {
custom_only = false,
list = {
{ key = { "l", "<CR>", "o" }, cb = tree_cb("edit") },
{ key = "h", cb = tree_cb("close_node") },
{ key = "v", cb = tree_cb("vsplit") },
{ key = "l", action = "edit", action_cb = edit_or_open },
{ key = "h", action = "close_node" },
},
},
number = false,
relativenumber = false,
},
actions = {
open_file = {