From c36ff90bd6245b3d119ec48b708bcee564d7ae22 Mon Sep 17 00:00:00 2001 From: winston Date: Sun, 21 Aug 2022 20:14:59 +0200 Subject: [PATCH] feat(nvim): roll back to stable, vimwiki markdown --- dot_config/nvim/init.lua | 111 ++++++++-------------- dot_config/nvim/lua/config/catppuccin.lua | 5 - dot_config/nvim/lua/config/lspsaga.lua | 96 +------------------ dot_config/nvim/lua/lsp.lua | 7 +- dot_config/nvim/lua/plugins.lua | 11 ++- 5 files changed, 51 insertions(+), 179 deletions(-) diff --git a/dot_config/nvim/init.lua b/dot_config/nvim/init.lua index 7ec2ebb..b022ffb 100644 --- a/dot_config/nvim/init.lua +++ b/dot_config/nvim/init.lua @@ -1,77 +1,47 @@ -- vim:fdm=marker pcall(require, "impatient") - --- packer {{{ -local fn = vim.fn -local install_path = fn.stdpath("data") .. "/site/pack/packer/start/packer.nvim" -if fn.empty(fn.glob(install_path)) > 0 then - print("Cloning packer ..") - - fn.system({ "git", "clone", "--depth", "1", "https://github.com/wbthomason/packer.nvim", install_path }) - - -- install plugins + compile their configs - vim.cmd("packadd packer.nvim") - require("plugins") - require("packer").sync() -end - -require("utils") +pcall(require, "plugins") pcall(require, "lsp") --- custom packer command -local packer_cmd = function(callback) - return function() - require("plugins") - require("packer")[callback]() - end -end - -local function cmd(lhs, fun, opt) - vim.api.nvim_create_user_command(lhs, fun, opt or {}) -end - -cmd("PackerClean", packer_cmd("clean")) -cmd("PackerCompile", packer_cmd("compile")) -cmd("PackerInstall", packer_cmd("install")) -cmd("PackerProfile", packer_cmd("profile")) -cmd("PackerStatus", packer_cmd("status")) -cmd("PackerSync", packer_cmd("sync")) -cmd("PackerUpdate", packer_cmd("update")) --- }}} - --- prelude -vim.opt.laststatus = 3 -vim.opt.list = true -vim.opt.number = true -vim.opt.relativenumber = true -vim.opt.scrolloff = 5 -vim.opt.showtabline = 2 -vim.opt.sidescrolloff = 15 -vim.opt.splitbelow = true -vim.opt.splitright = true -vim.opt.termguicolors = true -vim.opt.shadafile = nil - --- basic boring stuff +-- true colors +vim.o.termguicolors = true +-- map leader to space vim.g.mapleader = " " -vim.opt.mouse = "nv" - +-- allow mouse in normal/visual mode +vim.o.mouse = "nv" +-- line numbers +vim.o.number = true +vim.o.relativenumber = true +vim.o.numberwidth = 5 +-- scroll offsets +vim.o.scrolloff = 5 +vim.o.sidescrolloff = 15 +-- show leading/trailing whitespace +vim.o.list = true +-- always show status & tab line +vim.o.laststatus = 3 +vim.o.showtabline = 2 +-- completion height +vim.o.pumheight = 15 +-- split directions +vim.o.splitbelow = true +vim.o.splitright = true -- redefine word boundaries - '_' is a word seperator, this helps with snake_case -vim.cmd("set iskeyword-=_") +vim.opt.iskeyword:remove("_") -- easier split navigation -Nmap("", "j") -Nmap("", "k") -Nmap("", "l") -Nmap("", "h") +Nmap("", "j") +Nmap("", "k") +Nmap("", "l") +Nmap("", "h") -- escape :terminal easier vim.cmd([[tnoremap ]]) -- indentations settings -vim.opt.shiftwidth = 2 -vim.opt.tabstop = 2 -vim.opt.softtabstop = 2 -vim.opt.expandtab = true +vim.o.shiftwidth = 2 +vim.o.tabstop = 2 +vim.o.softtabstop = 2 +vim.o.expandtab = true -- indentation autocmds for some filetypes vim.cmd([[ " smol spaces for soydev @@ -80,30 +50,27 @@ autocmd FileType html,css,js,jsreact,ts,tsreact,json,yaml setlocal ts=2 sw=2 sts autocmd FileType go,lua setlocal ts=4 sw=4 sts=4 noet " Spaces, based languages autocmd FileType python,rust setlocal ts=4 sw=4 sts=4 et +autocmd FileType markdown let g:table_mode_corner='|' ]]) +-- auto-compile when lua files in `~/.config/nvim/*` change vim.api.nvim_create_autocmd("BufWritePost", { pattern = "*.lua", callback = function() + local cfg_path = vim.fn.resolve(vim.fn.stdpath("config")) vim.defer_fn(function() - if vim.fn.expand("%:p"):match(vim.fn.resolve(vim.fn.stdpath("config"))) then - packer_cmd("compile") + if vim.fn.expand("%:p"):match(cfg_path) then + vim.cmd("silent! PackerCompile") end end, 0) end, }) +-- neovide settings {{{ if vim.g.neovide then vim.cmd("cd $HOME") vim.g.neovide_cursor_vfx_mode = "ripple" vim.g.neovide_input_macos_alt_is_meta = true vim.o.guifont = "VictorMono Nerd Font:h18" - -- allow copy & paste in neovide, - -- https://github.com/neovide/neovide/issues/1263 - vim.cmd([[ - map "+p - map! + - tmap + - vmap "+y - ]]) end +-- }}} diff --git a/dot_config/nvim/lua/config/catppuccin.lua b/dot_config/nvim/lua/config/catppuccin.lua index e31f3c9..aa8a8c4 100644 --- a/dot_config/nvim/lua/config/catppuccin.lua +++ b/dot_config/nvim/lua/config/catppuccin.lua @@ -1,9 +1,4 @@ -- use transparency in terminal only -local useTransparentBG = true -if vim.g.neovide then - useTransparentBG = false -end - vim.g.catppuccin_flavour = "mocha" require("catppuccin").setup({ diff --git a/dot_config/nvim/lua/config/lspsaga.lua b/dot_config/nvim/lua/config/lspsaga.lua index 2ce7cfe..7d43d41 100644 --- a/dot_config/nvim/lua/config/lspsaga.lua +++ b/dot_config/nvim/lua/config/lspsaga.lua @@ -1,40 +1,5 @@ local saga = require("lspsaga") -saga.init_lsp_saga({ - symbol_in_winbar = { - in_custom = true, - enable = true, - separator = " > ", - show_file = true, - click_support = function(node, clicks, button, modifier) - -- To see all avaiable defails: vim.pretty_print(node) - local st = node.range.start - local en = node.range["end"] - if button == "l" then - if modifier == "c" then - print("lspsaga") -- ctrl left click to print "lspsaga" - end -- jump to node's ending line+char - if clicks == 2 then - -- double left click to visual select - vim.fn.cursor(st.line + 1, st.character + 1) - vim.cmd.normal("v") - vim.fn.cursor(en.line + 1, en.character + 1) - else -- jump to node's starting line+char - vim.fn.cursor(st.line + 1, st.character + 1) - end - elseif button == "r" then - if modifier == "c" then - print("lspsaga") -- shift right click to print "lspsaga" - end -- jump to node's ending line+char - vim.fn.cursor(en.line + 1, en.character + 1) - elseif button == "m" then - -- middle click to visual select node - vim.fn.cursor(st.line + 1, st.character + 1) - vim.cmd.normal("v") - vim.fn.cursor(en.line + 1, en.character + 1) - end - end, - }, -}) +saga.init_lsp_saga() Nmap("gr", "Lspsaga rename") Nmap("gx", "Lspsaga code_action") @@ -46,65 +11,6 @@ Nmap("gk", "Lspsaga diagnostic_jump_prev") Nmap("", "lua require('lspsaga.action').smart_scroll_with_saga(-1, '')", {}) Nmap("", "lua require('lspsaga.action').smart_scroll_with_saga(1, '')", {}) --- nullchilly winbar -local function get_file_name(include_path) - local file_name = require("lspsaga.symbolwinbar").get_file_name() - if vim.fn.bufname("%") == "" then - return "" - end - if include_path == false then - return file_name - end - -- Else if include path: ./lsp/saga.lua -> lsp > saga.lua - local sep = vim.loop.os_uname().sysname == "Windows" and "\\" or "/" - local path_list = vim.split(string.gsub(vim.fn.expand("%:~:.:h"), "%%", ""), sep) - local file_path = "" - for _, cur in ipairs(path_list) do - file_path = (cur == "." or cur == "~") and "" or file_path .. cur .. " " .. "%#LspSagaWinbarSep#>%*" .. " %*" - end - return file_path .. file_name -end - -local function config_winbar() - local exclude = { - ["teminal"] = true, - ["toggleterm"] = true, - ["prompt"] = true, - ["NvimTree"] = true, - ["help"] = true, - } -- Ignore float windows and exclude filetype - if vim.api.nvim_win_get_config(0).zindex or exclude[vim.bo.filetype] then - vim.wo.winbar = "" - else - local ok, lspsaga = pcall(require, "lspsaga.symbolwinbar") - local sym - if ok then - sym = lspsaga.get_symbol_node() - end - local win_val = "" - win_val = get_file_name(true) -- set to true to include path - if sym ~= nil then - win_val = win_val .. sym - end - vim.wo.winbar = win_val - end -end - -local events = { "BufEnter", "BufWinEnter", "CursorMoved" } -vim.api.nvim_create_autocmd(events, { - pattern = "*", - callback = function() - config_winbar() - end, -}) - -vim.api.nvim_create_autocmd("User", { - pattern = "LspsagaUpdateSymbol", - callback = function() - config_winbar() - end, -}) - vim.cmd([[ nnoremap lua require('lspsaga.floaterm').open_float_terminal() tnoremap :lua require('lspsaga.floaterm').close_float_terminal() diff --git a/dot_config/nvim/lua/lsp.lua b/dot_config/nvim/lua/lsp.lua index 42c37ba..d466c9b 100644 --- a/dot_config/nvim/lua/lsp.lua +++ b/dot_config/nvim/lua/lsp.lua @@ -63,10 +63,10 @@ local capabilities = require("cmp_nvim_lsp").update_capabilities(vim.lsp.protoco -- Mappings. -- See `:help vim.diagnostic.*` for documentation on any of the below functions local opts = { noremap = true, silent = true } -vim.keymap.set("n", "e", vim.diagnostic.open_float, opts) +vim.keymap.set("n", "e", vim.diagnostic.open_float, opts) vim.keymap.set("n", "[d", vim.diagnostic.goto_prev, opts) vim.keymap.set("n", "]d", vim.diagnostic.goto_next, opts) -vim.keymap.set("n", "q", vim.diagnostic.setloclist, opts) +vim.keymap.set("n", "q", vim.diagnostic.setloclist, opts) -- Use an on_attach function to only map the following keys -- after the language server attaches to the current buffer @@ -75,7 +75,7 @@ local on_attach = function(client, bufnr) -- Enable completion triggered by vim.api.nvim_buf_set_option(bufnr, "omnifunc", "v:lua.vim.lsp.omnifunc") - -- disable yaml diagnostics on Helm files + -- disable diagnostics on Helm files if vim.bo[bufnr].buftype ~= "" or vim.bo[bufnr].filetype == "helm" then vim.diagnostic.disable() end @@ -110,6 +110,7 @@ end local common_config = { on_attach = on_attach, + capabilities = capabilities, } local lsp = require("lspconfig") diff --git a/dot_config/nvim/lua/plugins.lua b/dot_config/nvim/lua/plugins.lua index 97a3048..b0c4f3f 100644 --- a/dot_config/nvim/lua/plugins.lua +++ b/dot_config/nvim/lua/plugins.lua @@ -20,14 +20,12 @@ return packer.startup(function(use) use({ "catppuccin/nvim", as = "catppuccin", - branch = "dev", config = function() require("config/catppuccin") end, }) use({ "Pocco81/true-zen.nvim", - branch = "main", config = function() require("true-zen").setup({ modes = { @@ -418,10 +416,15 @@ return packer.startup(function(use) vim.g.vimwiki_list = { { auto_export = 1, - path_html = "~/.local/share/vimwiki/", path = "~/.local/share/vimwiki/", syntax = "markdown", ext = ".md", + path_html = "~/vimwiki/", + template_path = "~/.config/vimwiki/templates/", + template_default = "default", + template_ext = ".tpl", + custom_wiki2html = "vimwiki_markdown", + html_filename_parameterization = 1, }, } end, @@ -456,7 +459,7 @@ return packer.startup(function(use) local auto_dark_mode = require("auto-dark-mode") auto_dark_mode.setup({ ---@diagnostic disable-next-line: assign-type-mismatch - update_interval = 5000, + update_interval = 1000, set_dark_mode = function() vim.cmd("Catppuccin mocha") end,