From 76534ab4cb12725525206e8728391ae9ce5c7f87 Mon Sep 17 00:00:00 2001 From: Fabio Lenherr / DashieTM Date: Thu, 3 Nov 2022 23:40:33 +0100 Subject: [PATCH] feat: improve nvim keymaps, add trouble --- nvim/init.lua | 3 +- nvim/lua/settings/.prettierrc | 6 + nvim/lua/settings/barbar.lua | 1 - nvim/lua/settings/cmp.lua | 45 +++++++- nvim/lua/settings/keymaps.lua | 12 +- nvim/lua/settings/lsp.lua | 10 +- nvim/lua/settings/null-ls.lua | 8 +- nvim/lua/settings/nvim-tree.lua | 2 +- nvim/lua/settings/options.lua | 3 +- nvim/lua/settings/plugins.lua | 3 +- nvim/lua/settings/treesitter.lua | 3 +- nvim/snippets/.texsnippetsold | 55 +++++++++ nvim/snippets/tex.lua | 184 +++++++++++++++++++++++++++++++ 13 files changed, 315 insertions(+), 20 deletions(-) create mode 100644 nvim/lua/settings/.prettierrc create mode 100644 nvim/snippets/.texsnippetsold create mode 100644 nvim/snippets/tex.lua diff --git a/nvim/init.lua b/nvim/init.lua index 76e8ecb..9426609 100644 --- a/nvim/init.lua +++ b/nvim/init.lua @@ -6,7 +6,7 @@ require("settings.devicons") require("settings.treesitter") require("settings.nvim-tree") require("settings.pairs") -require("settings.comment") +--require("settings.comment") require("settings.indentline") require("settings.project") require("settings.dashboard") @@ -25,3 +25,4 @@ require("telescope").setup({}) require("telescope").load_extension("fzy_native") require("impatient").enable_profile() require("nightfox") +require('Comment').setup() diff --git a/nvim/lua/settings/.prettierrc b/nvim/lua/settings/.prettierrc new file mode 100644 index 0000000..b9a0244 --- /dev/null +++ b/nvim/lua/settings/.prettierrc @@ -0,0 +1,6 @@ +{ + "trailingComma": "all", + "tabWidth": 2, + "semi": true, + "singleQuote": false +} diff --git a/nvim/lua/settings/barbar.lua b/nvim/lua/settings/barbar.lua index 41e8498..565bfd3 100644 --- a/nvim/lua/settings/barbar.lua +++ b/nvim/lua/settings/barbar.lua @@ -5,7 +5,6 @@ require("bufferline").setup({ tabpages = true, closable = true, clickable = true, - exclude_ft = { "javascript" }, exclude_name = { "package.json" }, icons = true, icon_custom_colors = false, diff --git a/nvim/lua/settings/cmp.lua b/nvim/lua/settings/cmp.lua index f92eab1..31b0777 100644 --- a/nvim/lua/settings/cmp.lua +++ b/nvim/lua/settings/cmp.lua @@ -8,9 +8,27 @@ if not snip_status_ok then return end +require("luasnip.loaders.from_lua").load({ paths = "~/.config/nvim/snippets" }) + +luasnip.config.set_config({ + history = true, + updateevents = "TextChanged,TextChangedI", + enable_autosnippets = true, + ext_opts = { + [require("luasnip.util.types").choiceNode] = { + active = { + virt_text = { { + Snippet = "", + "Snippet", + } }, + }, + }, + }, +}) + vim.cmd('let g:snipMate = {"snippet_version" : 1 }') require("luasnip/loaders/from_vscode").lazy_load() -require("luasnip.loaders.from_snipmate").lazy_load() +--require("luasnip.loaders.from_snipmate").lazy_load() local check_backspace = function() local col = vim.fn.col(".") - 1 @@ -47,6 +65,11 @@ local kind_icons = { } -- find more here: https://www.nerdfonts.com/cheat-sheet +--local has_words_before = function() +-- local line, col = unpack(vim.api.nvim_win_get_cursor(0)) +-- return col ~= 0 and vim.api.nvim_buf_get_lines(0, line - 1, line, true)[1]:sub(col, col):match("%s") == nil +--end + cmp.setup({ snippet = { expand = function(args) @@ -55,7 +78,7 @@ cmp.setup({ }, mapping = { [""] = cmp.mapping.select_prev_item(), - [""] = cmp.mapping.select_next_item(), + --[""] = cmp.mapping.select_next_item(), [""] = cmp.mapping(cmp.mapping.scroll_docs(-1), { "i", "c" }), [""] = cmp.mapping(cmp.mapping.scroll_docs(1), { "i", "c" }), [""] = cmp.mapping(cmp.mapping.complete(), { "i", "c" }), @@ -64,13 +87,25 @@ cmp.setup({ i = cmp.mapping.abort(), c = cmp.mapping.close(), }), + -- mapping = cmp.mapping.preset.insert({ + -- [''] = cmp.mapping.scroll_docs(-4), + -- [''] = cmp.mapping.scroll_docs(4), + -- [''] = cmp.mapping.complete(), + -- [''] = cmp.mapping.abort(), + -- [''] = cmp.mapping.confirm({ select = true }), -- Accept currently selected item. Set `select` to `false` to only confirm explicitly selected items. + -- }), -- Accept currently selected item. If none selected, `select` first item. -- Set `select` to `false` to only confirm explicitly selected items. [""] = cmp.mapping.confirm({ select = true }), [""] = cmp.mapping(function(fallback) if cmp.visible() then cmp.select_next_item() - elseif luasnip.expandable() then + else + fallback() + end + end, { "i", "s" }), + [""] = cmp.mapping(function(fallback) + if luasnip.expandable() then luasnip.expand() elseif luasnip.expand_or_jumpable() then luasnip.expand_or_jump() @@ -84,9 +119,7 @@ cmp.setup({ "s", }), [""] = cmp.mapping(function(fallback) - if cmp.visible() then - cmp.select_prev_item() - elseif luasnip.jumpable(-1) then + if luasnip.jumpable(-1) then luasnip.jump(-1) else fallback() diff --git a/nvim/lua/settings/keymaps.lua b/nvim/lua/settings/keymaps.lua index e85756f..64c641e 100644 --- a/nvim/lua/settings/keymaps.lua +++ b/nvim/lua/settings/keymaps.lua @@ -4,8 +4,11 @@ local term_opts = { silent = true } -- Shorten function name local keymap = vim.api.nvim_set_keymap +--vim.lsp.handlers["textDocument/codeAction"] = require'lspactions'.codeaction +--vim.cmd [[ nnoremap af :lua require'lspactions'.code_action() ]] -keymap("n", "c", ":CodeActionMenu", opts) +keymap("n", "", ":CodeActionMenu", opts) +keymap("n", "", "TroubleToggle", term_opts) keymap("n", "", ':lua require("dap").toggle_breakpoint()', opts) keymap("n", "", ':lua require("dap").step_over()', opts) keymap("n", "", ':lua require("dap").step_into()', opts) @@ -26,3 +29,10 @@ vim.keymap.set("n", "ff", builtin.find_files, {}) vim.keymap.set("n", "fg", builtin.live_grep, {}) vim.keymap.set("n", "fb", builtin.buffers, {}) vim.keymap.set("n", "fh", builtin.help_tags, {}) + +require("trouble").setup { + action_keys = { + --remove the fucking stupid keymap amk + open_tab = {} + } +} diff --git a/nvim/lua/settings/lsp.lua b/nvim/lua/settings/lsp.lua index ed876a1..90dd8e9 100644 --- a/nvim/lua/settings/lsp.lua +++ b/nvim/lua/settings/lsp.lua @@ -17,9 +17,9 @@ require("mason-lspconfig").setup({ ensure_installed = { "cssls", -- css "html", -- html - "eslint", -- latex + "eslint", -- latex "clangd", -- cpp / c - "tsserver", -- python + --"tsserver", -- python "texlab", -- latex "sumneko_lua", -- lua "pyright", -- python @@ -56,10 +56,10 @@ require("lspconfig")["clangd"].setup({ --on_attach = on_attach, }) -require("lspconfig")["tsserver"].setup({ - capabilities = capabilities, +--require("lspconfig")["tsserver"].setup({ +-- capabilities = capabilities, --on_attach = on_attach, -}) +--}) require("lspconfig")["texlab"].setup({ capabilities = capabilities, diff --git a/nvim/lua/settings/null-ls.lua b/nvim/lua/settings/null-ls.lua index efd88e9..84dc1f4 100644 --- a/nvim/lua/settings/null-ls.lua +++ b/nvim/lua/settings/null-ls.lua @@ -2,7 +2,7 @@ local null_ls = require("null-ls") require("mason-null-ls").setup({ ensure_installed = { - "prettier", + "prettierd", "clang_format", "latexindent", "shellharden", @@ -22,7 +22,11 @@ null_ls.setup({ end end, sources = { - require("null-ls").builtins.formatting.prettier, + require("null-ls").builtins.formatting.prettierd.with({ + env = { + PRETTIERD_DEFAULT_CONFIG = vim.fn.expand("~/.config/nvim/lua/settings/.prettierrc"), + },} + ), require("null-ls").builtins.formatting.clang_format, require("null-ls").builtins.formatting.latexindent, require("null-ls").builtins.formatting.shellharden, diff --git a/nvim/lua/settings/nvim-tree.lua b/nvim/lua/settings/nvim-tree.lua index e24fae6..efcbc64 100644 --- a/nvim/lua/settings/nvim-tree.lua +++ b/nvim/lua/settings/nvim-tree.lua @@ -36,7 +36,7 @@ nvim_tree.setup { -- BEGIN_DEFAULT_OPTS centralize_selection = false, width = 30, hide_root_folder = false, - side = "left", + side = "right", preserve_window_proportions = false, number = false, relativenumber = false, diff --git a/nvim/lua/settings/options.lua b/nvim/lua/settings/options.lua index d7c4ca1..54eaedc 100644 --- a/nvim/lua/settings/options.lua +++ b/nvim/lua/settings/options.lua @@ -3,6 +3,7 @@ local options = { mouse = "a", fileencoding = "utf-8", relativenumber = true, + number = true, smartindent = true, smartcase = true, showmode = true, @@ -10,7 +11,7 @@ local options = { -- winbar = "", ignorecase = true, showtabline = 2, - timeoutlen = 100, -- time to wait for a mapped sequence to complete (in milliseconds) + timeoutlen = 200, -- time to wait for a mapped sequence to complete (in milliseconds) undofile = true, -- enable persistent undoi updatetime = 300, -- faster completion (4000ms default) writebackup = false, -- if a file is being edited by another program (or was written to file while editing with another program), it is not allowed to be edited expandtab = true, -- convert tabs to spaces diff --git a/nvim/lua/settings/plugins.lua b/nvim/lua/settings/plugins.lua index 55f91f0..e102d91 100644 --- a/nvim/lua/settings/plugins.lua +++ b/nvim/lua/settings/plugins.lua @@ -9,7 +9,6 @@ Plug("feline-nvim/feline.nvim") Plug("lewis6991/gitsigns.nvim") Plug("tanvirtin/vgit.nvim") Plug("nvim-lua/plenary.nvim") -Plug("b3nj5m1n/kommentary") Plug("antoinemadec/FixCursorHold.nvim") Plug("lambdalisue/fern.vim") Plug("williamboman/mason.nvim") @@ -51,4 +50,6 @@ Plug("p00f/nvim-ts-rainbow") Plug("nvim-telescope/telescope-ui-select.nvim") Plug("nvim-telescope/telescope-file-browser.nvim") Plug("nvim-telescope/telescope-fzy-native.nvim") +Plug 'folke/trouble.nvim' vim.call("plug#end") + diff --git a/nvim/lua/settings/treesitter.lua b/nvim/lua/settings/treesitter.lua index 0c37e2e..1da7c3a 100644 --- a/nvim/lua/settings/treesitter.lua +++ b/nvim/lua/settings/treesitter.lua @@ -5,7 +5,8 @@ end require("nvim-treesitter.configs").setup({ -- A list of parser names, or "all" - ensure_installed = { "latex", "c", "cpp", "rust", "lua", "haskell", "java", "javascript", "typescript" }, + ensure_installed = { "latex", "c", "cpp", "rust", "lua", "haskell", "java", "javascript", "typescript", "python", "html", "css", +"yaml", "bash", "json", "c_sharp"}, highlight = { enable = true, additional_vim_regex_highlighting = false, diff --git a/nvim/snippets/.texsnippetsold b/nvim/snippets/.texsnippetsold new file mode 100644 index 0000000..6a23f7e --- /dev/null +++ b/nvim/snippets/.texsnippetsold @@ -0,0 +1,55 @@ + +snippet mini \minipg{}{}[] + \\minipg{ + $1 + } + {${2}}[${3}] + +snippet graphics \includegraphics[]{} + \\includegraphics[scale=$1]{${2}} + +snippet code "code" + \\begin{lstlisting} + $1 + \\end{lstlisting} + +snippet list "list" + \\begin{itemize} + \\item \\textcolor{${1}}{${2}} + \\item \\textcolor{${1}}{${3}} + \\item \\textcolor{${1}}{${4}} + \\item \\textcolor{${1}}{${5}} + \\vspace{-3mm} + \\end{itemize} + +snippet enum "enumerate" + \\begin{enumerate} + \\item \textcolor{${1}}{${2}} + \\item \textcolor{${1}}{${3}} + \\item \textcolor{${1}}{${4}} + \\item \textcolor{${1}}{${5}} + \\vspace{-3mm} + \\end{enumerate} + +snippet table "table" + \\begin{table}[ht!] + \\section{${1}} + \\begin{tabular}{|m{0.2\linewidth}|m{0.755\linewidth}|} + \hline + $2 + \hline + \\end{tabular} + \\end{table} + +snippet tabular "tabular" + \\begin{tabular}{|m{0.2\linewidth}|m{0.755\linewidth}|} + \hline + $1 + \hline + \\end{tabular} + +snippet tx "textcolor" + \\textcolor{${1}}{${2}} + +snippet bm "vectormatrix" + \\begin{bmatrix} $1 \\ $2 \\ $3 \end{bmatrix} diff --git a/nvim/snippets/tex.lua b/nvim/snippets/tex.lua new file mode 100644 index 0000000..3635d26 --- /dev/null +++ b/nvim/snippets/tex.lua @@ -0,0 +1,184 @@ +local ls = require("luasnip") +-- some shorthands... +local s = ls.s +local i = ls.i +local t = ls.t +local d = ls.dynamic_node +local c = ls.choice_node +local f = ls.function_node +local sn = ls.snippet_node + +local fmt = require("luasnip.extras.fmt").fmt +local rep = require("luasnip.extras").rep + +local snippets, autosnippets = {}, {} +local group = vim.api.nvim_create_augroup("Tex Snippets", { clear = true }) +local file_pattern = "*.tex" +------------------------------------------------- boilerplate end +-- snippers go here: + +local listSnippet = s( + "list-", + fmt( + [[ +\begin{{itemize}} +\item \textcolor{{{1}}}{{{5}}} +\item \textcolor{{{2}}}{{{6}}} +\item \textcolor{{{3}}}{{{7}}} +\item \textcolor{{{4}}}{{{8}}} +\vspace{{2mm}} +\end{{itemize}} + ]], + { + i(1, "color"), + rep(1), + rep(1), + rep(1), + i(2, "item 2"), + i(3, "item 1"), + i(4, "item 3"), + i(5, "item 4"), + } + ) +) +table.insert(snippets, listSnippet) + +local enumerateSnippet = s( + "enum-", + fmt( + [[ +\begin{{enumerate}} +\item \textcolor{{{1}}}{{{5}}} +\item \textcolor{{{2}}}{{{6}}} +\item \textcolor{{{3}}}{{{7}}} +\item \textcolor{{{4}}}{{{8}}} +\vspace{{2mm}} +\end{{enumerate}} + ]], + { + i(1, "color"), + rep(1), + rep(1), + rep(1), + i(2, "item 2"), + i(3, "item 1"), + i(4, "item 3"), + i(5, "item 4"), + } + ) +) +table.insert(snippets, enumerateSnippet) + +local tableSnippet = s( + "table-", + fmt( + [[ +\begin{{table}}[ht!] +\section{{{}}} +\begin{{tabular}}{{|m{{0.2\linewidth}}|m{{0.755\linewidth}}|}} +\hline +{} +\hline +\end{{tabular}} +\end{{table}} + ]], + { + i(1, "Section Name"), + i(2, "data....."), + } + ) +) +table.insert(snippets, tableSnippet) + +local tabularSnippet = s( + "tabular-", + fmt( + [[ +\begin{{tabular}}{{|m{{0.2\linewidth}}|m{{0.755\linewidth}}|}} +\hline +{} +\hline +\end{{tabular}} + ]], + { + i(1, "data....."), + } + ) +) + +local textcolorSnippet = s( + "tx-", + fmt( + [[ +\textcolor{{{1}}}{{{2}}} + ]], + { + i(1, "color"), + i(2, "text...") + } + ) +) +table.insert(snippets, textcolorSnippet) + +local boldSnippet = s( + "bold-", + fmt( + [[ +\textbf{{{1}}} + ]], + { + i(1, "text..."), + } + ) +) +table.insert(snippets, boldSnippet) + +local minipgSnippet = s( + "mini-", + fmt( + [[ +\minipg{{ +{1} +}}{{{2}}}[{3}] + ]], + { + i(1, "data..."), + rep(1), + i(2, "0.4,0.4"), + } + ) +) +table.insert(snippets, minipgSnippet) + +local graphicSnippet = s( + "graph-", + fmt( + [[ +\includegraphics[scale={1}]{{{2}}} + ]], + { + i(1, "0.4"), + i(2, "something.png"), + } + ) +) +table.insert(snippets, graphicSnippet) + +local lstSnippet = s( + "lst-", + fmt( + [[ +\begin{{lstlisting}} +{} +\end{{lstlisting}} + ]], + { + i(1, "data"), + } + ) +) +table.insert(snippets, lstSnippet) + + +------------------------------------------------- snippets end +return snippets, autosnippets