diff options
author | Gustaf Rydholm <gustaf.rydholm@gmail.com> | 2021-07-07 14:10:25 +0200 |
---|---|---|
committer | Gustaf Rydholm <gustaf.rydholm@gmail.com> | 2021-07-07 14:10:25 +0200 |
commit | 409dfed3237f9f0a6e96879078d1daf3d9c02e03 (patch) | |
tree | fd340e6803212b5ae401e2d6a1b524c412498663 /.config/nvim/lua/cfg | |
parent | 4918f8747e2d3e4d3342bb1f5ee05db6198819d1 (diff) |
Updated config again after Chris's updates
Diffstat (limited to '.config/nvim/lua/cfg')
-rw-r--r-- | .config/nvim/lua/cfg/autopairs/init.lua | 4 | ||||
-rw-r--r-- | .config/nvim/lua/cfg/colorizer/init.lua | 6 | ||||
-rw-r--r-- | .config/nvim/lua/cfg/compe/init.lua | 10 | ||||
-rw-r--r-- | .config/nvim/lua/cfg/dashboard/init.lua | 9 | ||||
-rw-r--r-- | .config/nvim/lua/cfg/galaxyline/init.lua | 4 | ||||
-rw-r--r-- | .config/nvim/lua/cfg/gitsigns/init.lua | 6 | ||||
-rw-r--r-- | .config/nvim/lua/cfg/lspinstall/init.lua | 26 | ||||
-rw-r--r-- | .config/nvim/lua/cfg/neoformat/init.lua | 12 | ||||
-rw-r--r-- | .config/nvim/lua/cfg/nvimtree/init.lua | 24 | ||||
-rw-r--r-- | .config/nvim/lua/cfg/telescope/init.lua | 11 | ||||
-rw-r--r-- | .config/nvim/lua/cfg/treesitter/init.lua | 26 | ||||
-rw-r--r-- | .config/nvim/lua/cfg/utils/init.lua | 15 | ||||
-rw-r--r-- | .config/nvim/lua/cfg/which-key/init.lua | 98 | ||||
-rw-r--r-- | .config/nvim/lua/cfg/zen/init.lua | 6 |
14 files changed, 111 insertions, 146 deletions
diff --git a/.config/nvim/lua/cfg/autopairs/init.lua b/.config/nvim/lua/cfg/autopairs/init.lua index 6a9e428..b8dad5f 100644 --- a/.config/nvim/lua/cfg/autopairs/init.lua +++ b/.config/nvim/lua/cfg/autopairs/init.lua @@ -1,6 +1,10 @@ -- if not package.loaded['nvim-autopairs'] then -- return -- end +local status_ok, autopairs = pcall(require, "nvim-autopairs") +if not status_ok then + return +end local npairs = require "nvim-autopairs" local Rule = require "nvim-autopairs.rule" diff --git a/.config/nvim/lua/cfg/colorizer/init.lua b/.config/nvim/lua/cfg/colorizer/init.lua index ac5f135..abe2f72 100644 --- a/.config/nvim/lua/cfg/colorizer/init.lua +++ b/.config/nvim/lua/cfg/colorizer/init.lua @@ -1,4 +1,8 @@ -require("colorizer").setup({ "*" }, { +local status_ok, colorizer = pcall(require, "colorizer") +if not status_ok then + return +end +colorizer.setup({ "*" }, { RGB = true, -- #RGB hex codes RRGGBB = true, -- #RRGGBB hex codes RRGGBBAA = true, -- #RRGGBBAA hex codes diff --git a/.config/nvim/lua/cfg/compe/init.lua b/.config/nvim/lua/cfg/compe/init.lua index 5b86f27..f42e8ad 100644 --- a/.config/nvim/lua/cfg/compe/init.lua +++ b/.config/nvim/lua/cfg/compe/init.lua @@ -7,7 +7,7 @@ local M = {} vim.g.vsnip_snippet_dir = O.vnsip_dir M.config = function() - opt = { + local opt = { enabled = O.auto_complete, autocomplete = true, debug = false, @@ -39,8 +39,12 @@ M.config = function() -- for emoji press : (idk if that in compe tho) }, } + local status_ok, compe = pcall(require, "compe") + if not status_ok then + return + end - require("compe").setup(opt) + compe.setup(opt) local t = function(str) return vim.api.nvim_replace_termcodes(str, true, true, true) @@ -86,7 +90,7 @@ M.config = function() vim.api.nvim_set_keymap("s", "<S-Tab>", "v:lua.s_tab_complete()", { expr = true }) vim.api.nvim_set_keymap("i", "<C-Space>", "compe#complete()", { noremap = true, silent = true, expr = true }) - -- vim.api.nvim_set_keymap("i", "<CR>", "compe#confirm('<CR>')", { noremap = true, silent = true, expr = true }) + vim.api.nvim_set_keymap("i", "<CR>", "compe#confirm('<CR>')", { noremap = true, silent = true, expr = true }) vim.api.nvim_set_keymap("i", "<C-e>", "compe#close('<C-e>')", { noremap = true, silent = true, expr = true }) vim.api.nvim_set_keymap("i", "<C-f>", "compe#scroll({ 'delta': +4 })", { noremap = true, silent = true, expr = true }) vim.api.nvim_set_keymap("i", "<C-d>", "compe#scroll({ 'delta': -4 })", { noremap = true, silent = true, expr = true }) diff --git a/.config/nvim/lua/cfg/dashboard/init.lua b/.config/nvim/lua/cfg/dashboard/init.lua index 2305243..bac9081 100644 --- a/.config/nvim/lua/cfg/dashboard/init.lua +++ b/.config/nvim/lua/cfg/dashboard/init.lua @@ -1,3 +1,4 @@ + local M = {} M.config = function() @@ -28,10 +29,10 @@ M.config = function() description = { " Settings " }, command = ":e " .. CONFIG_PATH .. "/config.lua", }, - f = { - description = { " Neovim Config Files" }, - command = "Telescope find_files cwd=" .. CONFIG_PATH, - }, + -- f = { + -- description = { " Neovim Config Files" }, + -- command = "Telescope find_files cwd=" .. CONFIG_PATH, + -- }, -- e = {description = {' Marks '}, command = 'Telescope marks'} } vim.cmd "let g:dashboard_session_directory = $HOME..'/.config/nvim/.sessions'" diff --git a/.config/nvim/lua/cfg/galaxyline/init.lua b/.config/nvim/lua/cfg/galaxyline/init.lua index 058846a..536144d 100644 --- a/.config/nvim/lua/cfg/galaxyline/init.lua +++ b/.config/nvim/lua/cfg/galaxyline/init.lua @@ -51,7 +51,7 @@ table.insert(gls.left, { t = colors.blue, } vim.api.nvim_command("hi GalaxyViMode guifg=" .. mode_color[vim.fn.mode()]) - return "▊" + return "▎" end, highlight = "StatusLineNC", }, @@ -173,7 +173,7 @@ local get_lsp_client = function(msg) lsps = client.name else lsps = lsps .. ", " .. client.name - -- print("more", lsps) + -- print("more", lsps) end end end diff --git a/.config/nvim/lua/cfg/gitsigns/init.lua b/.config/nvim/lua/cfg/gitsigns/init.lua index 7f1fbff..920c312 100644 --- a/.config/nvim/lua/cfg/gitsigns/init.lua +++ b/.config/nvim/lua/cfg/gitsigns/init.lua @@ -1,7 +1,11 @@ local M = {} M.config = function() - require("gitsigns").setup { + local status_ok, gitsigns = pcall(require, "gitsigns") + if not status_ok then + return + end + gitsigns.setup { signs = { -- TODO add hl to colorscheme add = { diff --git a/.config/nvim/lua/cfg/lspinstall/init.lua b/.config/nvim/lua/cfg/lspinstall/init.lua index 68fcfa2..af5e175 100644 --- a/.config/nvim/lua/cfg/lspinstall/init.lua +++ b/.config/nvim/lua/cfg/lspinstall/init.lua @@ -1,27 +1 @@ --- 1. get the config for this server from nvim-lspconfig and adjust the cmd path. --- relative paths are allowed, lspinstall automatically adjusts the cmd and cmd_cwd for us! -local config = require("lspconfig").jdtls.document_config -require("lspconfig/configs").jdtls = nil -- important, unset the loaded config again --- config.default_config.cmd[1] = "./node_modules/.bin/bash-language-server" - --- 2. extend the config with an install_script and (optionally) uninstall_script --- require'lspinstall/servers'.jdtls = vim.tbl_extend('error', config, { --- -- lspinstall will automatically create/delete the install directory for every server --- install_script = [[ --- git clone https://github.com/eclipse/eclipse.jdt.ls.git --- cd eclipse.jdt.ls --- ./mvnw clean verify --- ]], --- uninstall_script = nil -- can be omitted --- }) - --- require'lspinstall/servers'.kotlin = vim.tbl_extend('error', config, { --- install_script = [[ --- git clone https://github.com/fwcd/kotlin-language-server.git language-server --- cd language-server --- ./gradlew :server:installDist --- ]], --- uninstall_script = nil -- can be omitted --- }) - require("lspinstall").setup() diff --git a/.config/nvim/lua/cfg/neoformat/init.lua b/.config/nvim/lua/cfg/neoformat/init.lua new file mode 100644 index 0000000..eb9596e --- /dev/null +++ b/.config/nvim/lua/cfg/neoformat/init.lua @@ -0,0 +1,12 @@ +-- autoformat +if O.format_on_save then + require("cfg.utils").define_augroups { + autoformat = { + { + "BufWritePre", + "*", + [[try | undojoin | Neoformat | catch /^Vim\%((\a\+)\)\=:E790/ | finally | silent Neoformat | endtry]], + }, + }, + } +end diff --git a/.config/nvim/lua/cfg/nvimtree/init.lua b/.config/nvim/lua/cfg/nvimtree/init.lua index 37a931e..97cfe03 100644 --- a/.config/nvim/lua/cfg/nvimtree/init.lua +++ b/.config/nvim/lua/cfg/nvimtree/init.lua @@ -1,9 +1,13 @@ ---if not package.loaded['nvim-tree.view'] then --- return ---end - +-- --if not package.loaded['nvim-tree.view'] then +-- -- return +-- --end +-- local M = {} - +local status_ok, nvim_tree_config = pcall(require, "nvim-tree.config") +if not status_ok then + return +end +-- M.config = function() local g = vim.g @@ -52,7 +56,7 @@ M.config = function() symlink = "", }, } - local tree_cb = require("nvim-tree.config").nvim_tree_callback + local tree_cb = nvim_tree_config.nvim_tree_callback vim.g.nvim_tree_bindings = { { key = { "l", "<CR>", "o" }, cb = tree_cb "edit" }, @@ -61,8 +65,10 @@ M.config = function() } end -local view = require "nvim-tree.view" - +local view_status_ok, view = pcall(require, "nvim-tree.view") +if not view_status_ok then + return +end M.toggle_tree = function() if view.win_open() then require("nvim-tree").close() @@ -77,5 +83,5 @@ M.toggle_tree = function() require("nvim-tree").find_file(true) end end - +-- return M diff --git a/.config/nvim/lua/cfg/telescope/init.lua b/.config/nvim/lua/cfg/telescope/init.lua index 6bbce29..5411c32 100644 --- a/.config/nvim/lua/cfg/telescope/init.lua +++ b/.config/nvim/lua/cfg/telescope/init.lua @@ -1,3 +1,7 @@ +local status_ok, telescope = pcall(require, "telescope") +if not status_ok then + return +end local actions = require "telescope.actions" -- if O.plugin.trouble.active then -- local trouble = require("trouble.providers.telescope") @@ -5,7 +9,7 @@ local actions = require "telescope.actions" -- Global remapping ------------------------------ -- '--color=never', -require("telescope").setup { +telescope.setup { defaults = { find_command = { "rg", @@ -20,11 +24,11 @@ require("telescope").setup { entry_prefix = " ", initial_mode = "insert", selection_strategy = "reset", - sorting_strategy = "descending", + sorting_strategy = "ascending", layout_strategy = "horizontal", layout_config = { width = 0.75, - prompt_position = "bottom", + prompt_position = "top", preview_cutoff = 120, horizontal = { mirror = false }, vertical = { mirror = false }, @@ -83,4 +87,3 @@ require("telescope").setup { }, } --- require'telescope'.load_extension('project') diff --git a/.config/nvim/lua/cfg/treesitter/init.lua b/.config/nvim/lua/cfg/treesitter/init.lua index 12525da..deaa86e 100644 --- a/.config/nvim/lua/cfg/treesitter/init.lua +++ b/.config/nvim/lua/cfg/treesitter/init.lua @@ -80,8 +80,12 @@ if status then wk.register(textobj_move_keymaps["goto_previous_start"], normal) wk.register(textobj_move_keymaps["goto_previous_end"], normal) end +local status_ok, treesitter_configs = pcall(require, "nvim-treesitter.configs") +if not status_ok then + return +end -require("nvim-treesitter.configs").setup { +treesitter_configs.setup { ensure_installed = O.treesitter.ensure_installed, -- one of "all", "maintained" (parsers with maintainers), or a list of languages ignore_install = O.treesitter.ignore_install, matchup = { @@ -97,7 +101,7 @@ require("nvim-treesitter.configs").setup { enable = O.plugin.ts_context_commentstring.active, config = { css = "// %s" }, }, - -- indent = {enable = true, disable = {"python", "html", "javascript"}}, + -- indent = {enable = true, disable = {"python", "html, "javascript"}}, -- TODO seems to be broken indent = { enable = { "javascriptreact" } }, autotag = { enable = O.plugin.ts_autotag.active }, @@ -116,22 +120,4 @@ require("nvim-treesitter.configs").setup { enable = O.plugin.ts_textsubjects, keymaps = { ["."] = "textsubjects-smart", [";"] = "textsubjects-big" }, }, - playground = { - enable = O.plugin.ts_playground.active, - disable = {}, - updatetime = 25, -- Debounced time for highlighting nodes in the playground from source code - persist_queries = false, -- Whether the query persists across vim sessions - keybindings = { - toggle_query_editor = "o", - toggle_hl_groups = "i", - toggle_injected_languages = "t", - toggle_anonymous_nodes = "a", - toggle_language_display = "I", - focus_language = "f", - unfocus_language = "F", - update = "R", - goto_node = "<cr>", - show_help = "?", - }, - }, } diff --git a/.config/nvim/lua/cfg/utils/init.lua b/.config/nvim/lua/cfg/utils/init.lua index e879831..f8ed082 100644 --- a/.config/nvim/lua/cfg/utils/init.lua +++ b/.config/nvim/lua/cfg/utils/init.lua @@ -1,5 +1,13 @@ local utils = {} +function utils.reload_config() + vim.cmd "source ~/.config/nvim/config.lua" + vim.cmd "source ~/.config/nvim/lua/plugins.lua" + vim.cmd "source ~/.config/nvim/lua/neoformat/init.lua" + vim.cmd ":PackerCompile" + vim.cmd ":PackerInstall" +end + function utils.define_augroups(definitions) -- {{{1 -- Create autocommand groups based on the passed definitions -- @@ -24,7 +32,7 @@ end utils.define_augroups { - _user_autocommands = O.user_autocommands, + _user_autocommands = O.user_autocommands, _general_settings = { { "TextYankPost", @@ -46,6 +54,7 @@ utils.define_augroups { "*", "setlocal formatoptions-=c formatoptions-=r formatoptions-=o", }, + { "BufWritePost", "config.lua", "lua require('utils').reload_config()" }, { "VimLeavePre", "*", "set title set titleold=" }, }, -- _solidity = { @@ -65,7 +74,7 @@ utils.define_augroups { }, _auto_resize = { -- will cause split windows to be resized evenly if main window is resized - {'VimResized ', '*', 'wincmd ='}, + { "VimResized ", "*", "wincmd =" }, }, -- _mode_switching = { -- -- will switch between absolute and relative line numbers depending on mode @@ -77,5 +86,3 @@ utils.define_augroups { } return utils - --- TODO find a new home for these autocommands diff --git a/.config/nvim/lua/cfg/which-key/init.lua b/.config/nvim/lua/cfg/which-key/init.lua index 1558a50..ca87c6f 100644 --- a/.config/nvim/lua/cfg/which-key/init.lua +++ b/.config/nvim/lua/cfg/which-key/init.lua @@ -1,8 +1,12 @@ -- if not package.loaded['which-key'] then -- return -- end +local status_ok, which_key = pcall(require, "which-key") +if not status_ok then + return +end -require("which-key").setup { +which_key.setup { plugins = { marks = true, -- shows a list of your marks on ' and ` registers = true, -- shows your registers on " in NORMAL or <C-r> in INSERT mode @@ -61,16 +65,12 @@ vim.api.nvim_set_keymap("n", "<Leader>n", ':let @/=""<CR>', { noremap = true, si -- explorer --- TODO this introduces some bugs unfortunately vim.api.nvim_set_keymap( "n", "<Leader>e", ":lua require'cfg.nvimtree'.toggle_tree()<CR>", { noremap = true, silent = true } ) --- vim.api.nvim_set_keymap('n', '<Leader>e', --- ":NvimTreeToggle<CR>", --- {noremap = true, silent = true}) vim.api.nvim_set_keymap("n", "<Leader>f", ":Telescope find_files<CR>", { noremap = true, silent = true }) @@ -81,23 +81,31 @@ vim.api.nvim_set_keymap("n", "<Leader>;", ":Dashboard<CR>", { noremap = true, si vim.api.nvim_set_keymap("n", "<leader>k", ":CommentToggle<CR>", { noremap = true, silent = true }) vim.api.nvim_set_keymap("v", "<leader>k", ":CommentToggle<CR>", { noremap = true, silent = true }) - -- split window vim.api.nvim_set_keymap("n", "<leader>v", ":vsplit<CR>", {noremap = true, silent = true}) vim.api.nvim_set_keymap("n", "<leader>h", ":split<CR>", {noremap = true, silent = true}) + -- close buffer vim.api.nvim_set_keymap("n", "<leader>c", ":BufferClose<CR>", { noremap = true, silent = true }) --- TODO create entire treesitter section +-- open config +vim.api.nvim_set_keymap( + "n", + "<leader>.", + ":e " .. CONFIG_PATH .. "/config.lua<CR>", + { noremap = true, silent = true } +) local mappings = { + ["."] = "LunarConfig", ["k"] = "Comment", ["c"] = "Close Buffer", ["e"] = "Explorer", ["f"] = "Find File", ["n"] = "No Highlight", + [";"] = "Dashboard", ["v"] = "Vertical Split", ["h"] = "Horizontal Split", b = { @@ -127,54 +135,10 @@ local mappings = { name = "Packer", c = { "<cmd>PackerCompile<cr>", "Compile" }, i = { "<cmd>PackerInstall<cr>", "Install" }, - r = { ":luafile %<cr>", "Reload" }, + r = { "<cmd>lua require('cfg.utils').reload_config()<cr>", "Reload" }, s = { "<cmd>PackerSync<cr>", "Sync" }, u = { "<cmd>PackerUpdate<cr>", "Update" }, }, - -- diagnostics vanilla nvim - -- -- diagnostic - -- function lv_utils.get_all() - -- vim.lsp.diagnostic.get_all() - -- end - -- function lv_utils.get_next() - -- vim.lsp.diagnostic.get_next() - -- end - -- function lv_utils.get_prev() - -- vim.lsp.diagnostic.get_prev() - -- end - -- function lv_utils.goto_next() - -- vim.lsp.diagnostic.goto_next() - -- end - -- function lv_utils.goto_prev() - -- vim.lsp.diagnostic.goto_prev() - -- end - -- function lv_utils.show_line_diagnostics() - -- vim.lsp.diagnostic.show_line_diagnostics() - -- end - - -- " Available Debug Adapters: - -- " https://microsoft.github.io/debug-adapter-protocol/implementors/adapters/ - -- " Adapter configuration and installation instructions: - -- " https://github.com/mfussenegger/nvim-dap/wiki/Debug-Adapter-installation - -- " Debug Adapter protocol: - -- " https://microsoft.github.io/debug-adapter-protocol/ - -- " Debugging - d = { - name = "Debug", - t = { "<cmd>lua require'dap'.toggle_breakpoint()<cr>", "Toggle Breakpoint" }, - b = { "<cmd>lua require'dap'.step_back()<cr>", "Step Back" }, - c = { "<cmd>lua require'dap'.continue()<cr>", "Continue" }, - C = { "<cmd>lua require'dap'.run_to_cursor()<cr>", "Run To Cursor" }, - d = { "<cmd>lua require'dap'.disconnect()<cr>", "Disconnect" }, - g = { "<cmd>lua require'dap'.session()<cr>", "Get Session" }, - i = { "<cmd>lua require'dap'.step_into()<cr>", "Step Into" }, - o = { "<cmd>lua require'dap'.step_over()<cr>", "Step Over" }, - u = { "<cmd>lua require'dap'.step_out()<cr>", "Step Out" }, - p = { "<cmd>lua require'dap'.pause.toggle()<cr>", "Pause" }, - r = { "<cmd>lua require'dap'.repl.toggle()<cr>", "Toggle Repl" }, - s = { "<cmd>lua require'dap'.continue()<cr>", "Start" }, - q = { "<cmd>lua require'dap'.stop()<cr>", "Quit" }, - }, g = { name = "Git", j = { "<cmd>lua require 'gitsigns'.next_hunk()<cr>", "Next Hunk" }, @@ -207,7 +171,7 @@ local mappings = { "<cmd>Telescope lsp_workspace_diagnostics<cr>", "Workspace Diagnostics", }, - f = { "<cmd>lua vim.lsp.buf.formatting()<cr>", "Format" }, + f = { "<cmd>Neoformat<cr>", "Format" }, i = { "<cmd>LspInfo<cr>", "Info" }, j = { "<cmd>lua vim.lsp.diagnostic.goto_next({popup_opts = {border = O.lsp.popup_border}})<cr>", "Next Diagnostic" }, k = { "<cmd>lua vim.lsp.diagnostic.goto_prev({popup_opts = {border = O.lsp.popup_border}})<cr>", "Prev Diagnostic" }, @@ -244,18 +208,6 @@ local mappings = { }, } --- if O.plugin.trouble.active then --- mappings["d"] = { --- name = "Diagnostics", --- t = { "<cmd>TroubleToggle<cr>", "trouble" }, --- w = { "<cmd>TroubleToggle lsp_workspace_diagnostics<cr>", "workspace" }, --- d = { "<cmd>TroubleToggle lsp_document_diagnostics<cr>", "document" }, --- q = { "<cmd>TroubleToggle quickfix<cr>", "quickfix" }, --- l = { "<cmd>TroubleToggle loclist<cr>", "loclist" }, --- r = { "<cmd>TroubleToggle lsp_references<cr>", "references" }, --- } --- end - if O.plugin.symbol_outline.active then vim.api.nvim_set_keymap("n", "<leader>o", ":SymbolsOutline<CR>", { noremap = true, silent = true }) mappings["o"] = "Symbols outline" @@ -270,10 +222,7 @@ if O.plugin.zen.active then vim.api.nvim_set_keymap("n", "<leader>z", ":ZenMode<CR>", { noremap = true, silent = true }) mappings["z"] = "Zen" end -if O.plugin.lazygit.active then - vim.api.nvim_set_keymap("n", "<leader>gg", ":LazyGit<CR>", { noremap = true, silent = true }) - mappings["gg"] = "LazyGit" -end + if O.plugin.telescope_project.active then -- open projects vim.api.nvim_set_keymap( @@ -285,8 +234,6 @@ if O.plugin.telescope_project.active then mappings["P"] = "Projects" end --- [";"] = "Dashboard", - if O.lang.latex.active then mappings["L"] = { name = "+Latex", @@ -309,5 +256,14 @@ if O.lushmode then } end +-- for _, v in pairs(O.user_which_key) do +-- end +for k, v in pairs(O.user_which_key) do + mappings[k] = v + -- table.insert(mappings, O.user_which_key[1]) + -- print(k) + -- print(v) +end + local wk = require "which-key" wk.register(mappings, opts) diff --git a/.config/nvim/lua/cfg/zen/init.lua b/.config/nvim/lua/cfg/zen/init.lua index 0d6bfca..d4a3da5 100644 --- a/.config/nvim/lua/cfg/zen/init.lua +++ b/.config/nvim/lua/cfg/zen/init.lua @@ -1,7 +1,11 @@ local M = {} +local status_ok, zen_mode = pcall(require, "zen-mode") +if not status_ok then + return +end M.config = function() - require("zen-mode").setup { + zen_mode.setup { window = { backdrop = 1, height = 0.85, -- height of the Zen window |