diff --git a/.config/npm/npmrc b/.config/npm/npmrc index fc84b78..c2da224 100644 --- a/.config/npm/npmrc +++ b/.config/npm/npmrc @@ -1,4 +1,3 @@ prefix=${XDG_DATA_HOME}/npm cache=${XDG_CACHE_HOME}/npm -tmp=${XDG_RUNTIME_DIR}/npm init-module=${XDG_CONFIG_HOME}/npm/config/npm-init.js diff --git a/.config/nvim/after/ftplugin/javascript.lua b/.config/nvim/after/ftplugin/javascript.lua new file mode 100644 index 0000000..6a3dc86 --- /dev/null +++ b/.config/nvim/after/ftplugin/javascript.lua @@ -0,0 +1,14 @@ +-- Author : swytch +-- Created : Saturday Feb. 18, 2023 20:41:05 CET +-- License : GPLv3 +-- Description : javascript settings file + + +local format_sync_grp = vim.api.nvim_create_augroup("Format", {}) +vim.api.nvim_create_autocmd("BufWritePre", { + pattern = "*.js", + callback = function() + vim.lsp.buf.format({ timeout_ms = 200 }) + end, + group = format_sync_grp, +}) diff --git a/.config/nvim/after/ftplugin/markdown.lua b/.config/nvim/after/ftplugin/markdown.lua new file mode 100644 index 0000000..40defc9 --- /dev/null +++ b/.config/nvim/after/ftplugin/markdown.lua @@ -0,0 +1,44 @@ +-- Author : swytch +-- Created : Saturday Feb. 18, 2023 21:54:19 CET +-- License : GPLv3 +-- Description : markdown settings file + + +-- Snippets +local ls = require("luasnip") + +-- some shorthands... +local s = ls.snippet +local sn = ls.snippet_node +local t = ls.text_node +local i = ls.insert_node +local d = ls.dynamic_node + +-- Returns a snippet_node wrapped around an insertNode whose initial +-- text value is set to the current date in the desired format. +local date_input = function(args, snip, old_state, fmt) + local fmt = fmt or "%Y-%m-%d" + return sn(nil, i(1, os.date(fmt))) +end + +ls.add_snippets("markdown", { + s("date", { + d(1, date_input, {}, { user_args = { "%Y-%m-%d" } }), + }), + s("datep", { + d(1, date_input, {}, { user_args = { "%Y-%m-%d %X %z" } }), + }), + s("/xrpt", { + t(""), + }), + s("bb", { + t({ "**" }), + i(1), + t({ "**" }), + }), + s("ii", { + t({ "*" }), + i(1), + t({ "*" }), + }), +}) diff --git a/.config/nvim/lua/maps.lua b/.config/nvim/lua/maps.lua index 9f06f58..07c4ad6 100644 --- a/.config/nvim/lua/maps.lua +++ b/.config/nvim/lua/maps.lua @@ -36,7 +36,7 @@ vim.keymap.set({ "t" }, "", -- yank and pasting vim.keymap.set({ "n", "x" }, "y", "\"+y", - { desc = "Yank to clipboard"} + { desc = "Yank to clipboard" } ) vim.keymap.set("n", "p", "\"+P", @@ -95,9 +95,11 @@ vim.keymap.set("n", "tk", { desc = "Search through keymaps" } ) vim.keymap.set("n", "tx", - function() require("telescope.builtin").diagnostics( - { buffnr = 0 } - ) end, + function() + require("telescope.builtin").diagnostics( + { buffnr = 0 } + ) + end, { desc = "Search through LSP diagnostics" } ) diff --git a/.config/nvim/lua/plugin/lsp/html.lua b/.config/nvim/lua/plugin/lsp/html.lua new file mode 100644 index 0000000..1d84744 --- /dev/null +++ b/.config/nvim/lua/plugin/lsp/html.lua @@ -0,0 +1,11 @@ +-- Author : swytch +-- Created : Sunday Feb. 19, 2023 17:09:46 CET +-- License : GPLv3 +-- Description : neovim lsp config file for html-lsp + +local M = {} + +M.setup = function(opts) +end + +return M diff --git a/.config/nvim/lua/plugin/lsp/init.lua b/.config/nvim/lua/plugin/lsp/init.lua index 4721084..38dc0e0 100644 --- a/.config/nvim/lua/plugin/lsp/init.lua +++ b/.config/nvim/lua/plugin/lsp/init.lua @@ -11,6 +11,8 @@ local servers = { "rust_analyzer", "lua_ls", "texlab", + "tsserver", + "html", } return { @@ -22,7 +24,6 @@ return { "williamboman/mason-lspconfig.nvim", }, config = function() - vim.diagnostic.config({ underline = true, update_in_insert = false, diff --git a/.config/nvim/lua/plugin/lsp/lua_ls.lua b/.config/nvim/lua/plugin/lsp/lua_ls.lua index 0905cab..5e7beea 100644 --- a/.config/nvim/lua/plugin/lsp/lua_ls.lua +++ b/.config/nvim/lua/plugin/lsp/lua_ls.lua @@ -33,13 +33,13 @@ M.setup = function(opts) workspace = { -- Make the server aware of Neovim runtime files library = - vim.api.nvim_get_runtime_file("", true), + vim.api.nvim_get_runtime_file("", true), checkThirdParty = false, }, -- Do not send telemetry data containing a randomized but -- unique identifier telemetry = { - enable = false, + enable = false, }, }, } diff --git a/.config/nvim/lua/plugin/lsp/texlab.lua b/.config/nvim/lua/plugin/lsp/texlab.lua index 2fbbf14..c79154d 100644 --- a/.config/nvim/lua/plugin/lsp/texlab.lua +++ b/.config/nvim/lua/plugin/lsp/texlab.lua @@ -15,4 +15,3 @@ M.setup = function(opts) end return M - diff --git a/.config/nvim/lua/plugin/lsp/tsserver.lua b/.config/nvim/lua/plugin/lsp/tsserver.lua new file mode 100644 index 0000000..28b96d6 --- /dev/null +++ b/.config/nvim/lua/plugin/lsp/tsserver.lua @@ -0,0 +1,12 @@ +-- Author : swytch +-- Created : Sunday Feb. 19, 2023 17:12:35 CET +-- License : GPLv3 +-- Description : neovim lsp config file for tsserver + + +local M = {} + +M.setup = function(opts) +end + +return M diff --git a/.config/nvim/lua/plugin/treesitter.lua b/.config/nvim/lua/plugin/treesitter.lua index 6b65232..8797bdb 100644 --- a/.config/nvim/lua/plugin/treesitter.lua +++ b/.config/nvim/lua/plugin/treesitter.lua @@ -13,6 +13,7 @@ return { opts = { ensure_installed = { "c", "cpp", "lua", "rust", "bash", "vim", "latex", "python", + "html", "javascript", "json", "markdown" }, highlight = { enable = true, diff --git a/.config/nvim/lua/settings.lua b/.config/nvim/lua/settings.lua index d993097..d382ecb 100644 --- a/.config/nvim/lua/settings.lua +++ b/.config/nvim/lua/settings.lua @@ -3,63 +3,68 @@ -- License : GPLv3 -- Description : neovim settings file -local opt = vim.opt -local g = vim.g +local opt = vim.opt +local g = vim.g -- general -opt.wildignore = { - ".git", - "*.o", "*.class", - "*.jpg", "*.jpeg", "*.png", - "*.pdf", - "*.zip", "*.gz", "*.rar", "*.tar.xz", +opt.wildignore = { + ".git", + "*.o", "*.class", + "*.jpg", "*.jpeg", "*.png", + "*.pdf", + "*.zip", "*.gz", "*.rar", "*.tar.xz", } -opt.wildmode = { "longest", "full" } -opt.wildoptions = "pum" +opt.wildmode = { "longest", "full" } +opt.wildoptions = "pum" -- editor -opt.lazyredraw = true -opt.splitright = true -opt.splitbelow = true -opt.scrolloff = 4 -opt.termguicolors = true -opt.background = "dark" -opt.cursorline = true -opt.colorcolumn = "+1" -opt.shortmess = opt.shortmess:append { c = true } -opt.number = true -opt.relativenumber = true -opt.signcolumn = "yes" -opt.listchars = { - tab = "<->", - nbsp = "␣", - trail = "·", - extends = ">", - precedes = "<", +opt.lazyredraw = true +opt.splitright = true +opt.splitbelow = true +opt.scrolloff = 4 +opt.termguicolors = true +opt.background = "dark" +opt.cursorline = true +opt.colorcolumn = "+1" +opt.shortmess = opt.shortmess:append { c = true } +opt.number = true +opt.relativenumber = true +opt.signcolumn = "yes" +opt.listchars = { + tab = "<->", + nbsp = "␣", + trail = "·", + extends = ">", + precedes = "<", } -opt.showmatch = true -opt.ignorecase = true -opt.smartcase = true -opt.inccommand = "split" -opt.completeopt = { "menuone", "noselect" } +opt.showmatch = true +opt.ignorecase = true +opt.smartcase = true +opt.inccommand = "split" +opt.completeopt = { "menuone", "noselect" } -- statusline -opt.laststatus = 2 -opt.showmode = false +opt.laststatus = 2 +opt.showmode = false -- text, tabs, indents -opt.textwidth = 79 -opt.shiftwidth = 8 -opt.softtabstop = -1 -opt.expandtab = true -opt.shiftwidth = 0 -opt.backspace = { "indent", "eol", "start" } +opt.textwidth = 79 +opt.tabstop = 4 +opt.softtabstop = -1 +opt.expandtab = true +opt.shiftwidth = 0 +opt.backspace = { "indent", "eol", "start" } -- augroups utils.create_augroup({ - {"BufWritePre", "*", "%s/\\s\\+$//e"} + { "BufWritePre", "*", "%s/\\s\\+$//e" } }, "remove_trailing_whitespaces") utils.create_augroup({ - {"BufNewFile,BufRead", "*.mom", "set filetype=groff"}, - {"BufNewFile,BufRead", "*.tex", "set filetype=tex"}, + { "BufNewFile,BufRead", "*.mom", "set filetype=groff" }, + { "BufNewFile,BufRead", "*.tex", "set filetype=tex" }, }, "enforce_filetypes") + +vim.api.nvim_create_autocmd({ "BufEnter", "BufWinEnter" }, { + pattern = { "*.njk" }, + callback = function() vim.bo.filetype = "html" end, +}) diff --git a/.config/nvim/lua/statusline.lua b/.config/nvim/lua/statusline.lua index a383585..4abecb5 100644 --- a/.config/nvim/lua/statusline.lua +++ b/.config/nvim/lua/statusline.lua @@ -107,17 +107,34 @@ local function shorten_path(path, max_len) end local segments = vim.split(path, sep) - for idx = 1, #segments - 1 do + local start = 1 + if segments[1] == "~" then + start = start + 1 + end + + + for idx = start, #segments - 1 do if len <= max_len then break end local segment = segments[idx] - local shortened = segment:sub(1, vim.startswith(segment, '.') and 2 or 1) + local short_end = 1 + if (vim.startswith(segment, '.') or vim.startswith(segment, '_')) then + short_end = 2 + end + local shortened = segment:sub(1, short_end) segments[idx] = shortened len = len - (#segment - #shortened) end + if (len > max_len and #segments > 3) then + while (len > max_len and #segments > 3) do + table.remove(segments, 2) + end + table.insert(segments,2, "...") + end + return table.concat(segments, sep) end @@ -169,49 +186,48 @@ local function statusline_focused() local winwidth = vim.fn.winwidth(0) local left = table.concat { - gen_section(accent_color, { get_mode_display_name(mg) }), - gen_section("%#Middle#", { shorten_path(file, winwidth / 3) }), - gen_section("%#Bottom#", { "%m", "%r" }), - gen_section( - "%#Alert#", - { - process_diagnostics( - globals.sign_error .. " ", - diagnostics.error, - "%#DiagnosticVirtualTextError#" - ), - process_diagnostics( - globals.sign_warn .. " ", - diagnostics.warn, - "%#DiagnosticVirtualTextWarn#" - ), - process_diagnostics( - globals.sign_info .. " ", - diagnostics.info, - "%#DiagnosticVirtualTextInfo#" - ) - } - ) - } + gen_section(accent_color, { get_mode_display_name(mg) }), + gen_section("%#Middle#", { shorten_path(file, winwidth / 2) }), + gen_section("%#Bottom#", { "%m", "%r" }), + gen_section( + "%#Alert#", + { + process_diagnostics( + globals.sign_error .. " ", + diagnostics.error, + "%#DiagnosticVirtualTextError#" + ), + process_diagnostics( + globals.sign_warn .. " ", + diagnostics.warn, + "%#DiagnosticVirtualTextWarn#" + ), + process_diagnostics( + globals.sign_info .. " ", + diagnostics.info, + "%#DiagnosticVirtualTextInfo#" + ) + } + ) + } local right = table.concat { - gen_section( - "%#Bottom#", - { - spell_check(), - vim.bo.filetype - } - ), - gen_section("%#Middle#", { "%03.p%%" }), - gen_section("%#Top#", { "-%03.c-" }) - } + gen_section( + "%#Bottom#", + { + spell_check(), + vim.bo.filetype + } + ), + gen_section("%#Middle#", { "%03.p%%" }), + gen_section("%#Top#", { "-%03.c-" }) + } return table.concat { - left, - "%#Statusline#", - "%=", - right - } - + left, + "%#Statusline#", + "%=", + right + } end local function statusline_not_focused() @@ -219,14 +235,14 @@ local function statusline_not_focused() local file = vim.fn.expand("#" .. bufnr .. ":p:~") local winwidth = vim.fn.winwidth(0) return table.concat { - gen_section("%#StatuslineNF#", { - shorten_path(file, winwidth / 3), - "%m" - }), - "%=", - gen_section("%#StatuslineNF#", { "%03.p%%" }), - gen_section("%#StatuslineNF#", { "-%03.c-" }) - } + gen_section("%#StatuslineNF#", { + shorten_path(file, winwidth / 2), + "%m" + }), + "%=", + gen_section("%#StatuslineNF#", { "%03.p%%" }), + gen_section("%#StatuslineNF#", { "-%03.c-" }) + } end function _G.gen_statusline() diff --git a/.config/nvim/lua/utils.lua b/.config/nvim/lua/utils.lua index 9ea50dc..3041559 100644 --- a/.config/nvim/lua/utils.lua +++ b/.config/nvim/lua/utils.lua @@ -8,40 +8,40 @@ local cmd = vim.cmd -- augroup helper function M.create_augroup(autocmds, name) - cmd("augroup " .. name) - cmd("autocmd!") - for _, autocmd in ipairs(autocmds) do - cmd("autocmd " .. table.concat(autocmd, " ")) - end - cmd("augroup END") + cmd("augroup " .. name) + cmd("autocmd!") + for _, autocmd in ipairs(autocmds) do + cmd("autocmd " .. table.concat(autocmd, " ")) + end + cmd("augroup END") end -- add a path to the rtp function M.add_rtp(path) - local rtp = vim.o.rtp - rtp = rtp .. "," .. path + local rtp = vim.o.rtp + rtp = rtp .. "," .. path end -- see if a file exists function M.file_exists(file) - local f = io.open(file, "rb") - if f then f:close() end - return f ~= nil + local f = io.open(file, "rb") + if f then f:close() end + return f ~= nil end -- get all lines from a file -- @return table (empty if the file does not exist) function M.lines_from(file) - if not M.file_exists(file) then return {} end - local lines = {} - for line in io.lines(file) do - lines[#lines] = line - end - return lines + if not M.file_exists(file) then return {} end + local lines = {} + for line in io.lines(file) do + lines[#lines] = line + end + return lines end function M.copy(args) - return args[1] + return args[1] end -- Make it accessible everywhere