From 1423db18ba4937cc02e0a121bf6edc944ebadcea Mon Sep 17 00:00:00 2001 From: spike Date: Sat, 20 Aug 2022 16:06:49 +0200 Subject: [PATCH] update --- .gitignore | 1 - custom_snippets | 1 + lua/core/mappings.lua | 162 ++++++++++++++++++++++++++---- lua/core/options.lua | 67 ++++++++++-- lua/custom/chadrc.lua | 22 ++++ lua/custom/init.lua | 42 ++++++++ lua/custom/plugins/init.lua | 39 +++++++ lua/plugins/configs/cmp.lua | 28 +++++- lua/plugins/configs/lspconfig.lua | 5 + lua/plugins/configs/others.lua | 4 +- 10 files changed, 334 insertions(+), 37 deletions(-) create mode 120000 custom_snippets create mode 100644 lua/custom/chadrc.lua create mode 100644 lua/custom/init.lua create mode 100644 lua/custom/plugins/init.lua diff --git a/.gitignore b/.gitignore index db7df8e..da07f7f 100644 --- a/.gitignore +++ b/.gitignore @@ -1,3 +1,2 @@ plugin -custom spell diff --git a/custom_snippets b/custom_snippets new file mode 120000 index 0000000..ad0f97f --- /dev/null +++ b/custom_snippets @@ -0,0 +1 @@ +../../dotfiles/nvim/.config/nvim/mysnippets \ No newline at end of file diff --git a/lua/core/mappings.lua b/lua/core/mappings.lua index 8ab1757..3d05bf1 100644 --- a/lua/core/mappings.lua +++ b/lua/core/mappings.lua @@ -1,4 +1,4 @@ --- n, v, i, t = mode names +-- n, v, i, t, c = mode name.s local function termcodes(str) return vim.api.nvim_replace_termcodes(str, true, true, true) @@ -8,15 +8,20 @@ local M = {} M.general = { i = { - -- go to beginning and end - [""] = { "^i", "beginning of line" }, - [""] = { "", "end of line" }, + + ["jk"] = { "", "escape"}, -- navigate within insert mode [""] = { "", "move left" }, [""] = { "", "move right" }, [""] = { "", "move down" }, [""] = { "", "move up" }, + + [""] = { " update ", "update file (save on changes)"}, + + -- luasnip change choice + [""] = {"luasnip-next-choice", "change luasnip choice"}, + }, n = { @@ -28,8 +33,35 @@ M.general = { [""] = { "j", "window down" }, [""] = { "k", "window up" }, + -- Window resizing + + [""] = { " vert res +2 ", "window width +" }, + [""] = { " vert res -2 ", "window width -" }, + [""] = { "res +2 ", "window height +" }, + [""] = { "res -2 ", "window height -" }, + + -- quit dont save + ["qq"] = {" quitall! ", "quit/close all windows, don't save"}, + + ["Q"] = {" q!", "quit now"}, + + -- easier horizontal scrolling + ["zl"] = {"zL", "horizontal scroll left"}, + ["zh"] = {"zH", "horizontal scroll right"}, + + -- Use fast jump to exact location and reserve `` for other usage + ["''"] = {"``", "jump back to exact location"}, + + -- Go to the first non-blank character of a line + ["0"] = {"^"}, + -- Just in case you need to go to the very beginning of a line + ["^"] = {"0"}, + + + ["ww"] = { " set wrap! echo 'wrap = '.&wrap "}, + -- save - [""] = { " w ", "save file" }, + [""] = { " update ", "save file" }, -- Copy all [""] = { " %y+ ", "copy whole file" }, @@ -52,34 +84,98 @@ M.general = { -- http://www.reddit.com/r/vim/comments/2k4cbr/problem_with_gj_and_gk/ -- empty mode is same as using :map -- also don't use g[j|k] when in operator pending mode, so it doesn't alter d, y or c behaviour - ["j"] = { 'v:count || mode(1)[0:1] == "no" ? "j" : "gj"', opts = { expr = true } }, - ["k"] = { 'v:count || mode(1)[0:1] == "no" ? "k" : "gk"', opts = { expr = true } }, - [""] = { 'v:count || mode(1)[0:1] == "no" ? "k" : "gk"', opts = { expr = true } }, - [""] = { 'v:count || mode(1)[0:1] == "no" ? "j" : "gj"', opts = { expr = true } }, + -- ["j"] = { 'v:count || mode(1)[0:1] == "no" ? "j" : "gj"', opts = { expr = true } }, + -- ["k"] = { 'v:count || mode(1)[0:1] == "no" ? "k" : "gk"', opts = { expr = true } }, + ["j"] = { "gj" }, + ["k"] = { "gk" }, -- new buffer [""] = { " enew ", "new buffer" }, + -- new tab + [""] = {" tabe ", "new tab"}, + + + -- Fast tab + [""] = { "gT", "Previous tab"}, + [""] = { "gt", "Previous tab"}, + -- close buffer + hide terminal buffer - ["x"] = { + ["xx"] = { function() require("core.utils").close_buffer() end, "close buffer", }, + [""] = {" close ", "close window"}, + + -- yank from cusor to eol to system and primary clipboard + ["y"] = {'"*y$"+y$'}, + + + -- folding levels + ["f0"] = {":set foldlevel=0", "set fold level"}, + ["f1"] = {":set foldlevel=1", "set fold level"}, + ["f2"] = {":set foldlevel=2", "set fold level"}, + ["f3"] = {":set foldlevel=3", "set fold level"}, + ["f4"] = {":set foldlevel=4", "set fold level"}, + ["f5"] = {":set foldlevel=5", "set fold level"}, + ["f6"] = {":set foldlevel=6", "set fold level"}, + ["f7"] = {":set foldlevel=7", "set fold level"}, + ["f8"] = {":set foldlevel=8", "set fold level"}, + ["f9"] = {":set foldlevel=9", "set fold level"}, + + ["en"] = {" cn ", "next error"}, + ["rp"] = {" cp ", "previous error"}, + + + ["g."] = {":cwd", "change dir to current file", opts = { remap = true}}, + + -- Packer commands + ["ps"] = {" PackerSync ", "packer sync"}, + + -- Notify cmd watcher (see /scripts/utils/fifo_watch.sh) + [","] = { + function() + local fifo_patch="/tmp/fifo_vimnotify" + os.execute("echo do >" .. fifo_patch ) + end, + "notify " + } }, t = { [""] = { termcodes "", "escape terminal mode" } }, v = { - ["j"] = { 'v:count || mode(1)[0:1] == "no" ? "j" : "gj"', opts = { expr = true } }, - ["k"] = { 'v:count || mode(1)[0:1] == "no" ? "k" : "gk"', opts = { expr = true } }, - [""] = { 'v:count || mode(1)[0:1] == "no" ? "k" : "gk"', opts = { expr = true } }, - [""] = { 'v:count || mode(1)[0:1] == "no" ? "j" : "gj"', opts = { expr = true } }, + -- ["j"] = { 'v:count || mode(1)[0:1] == "no" ? "j" : "gj"', opts = { expr = true } }, + -- ["k"] = { 'v:count || mode(1)[0:1] == "no" ? "k" : "gk"', opts = { expr = true } }, + ["j"] = { "gj" }, + ["k"] = { "gk" }, -- Don't copy the replaced text after pasting in visual mode -- https://vim.fandom.com/wiki/Replace_a_word_with_yanked_text#Alternative_mapping_for_paste ["p"] = { 'p:let @+=@0:let @"=@0', opts = { silent = true } }, + + -- yank from cursor to eol to system and primary clipboard + ["y"] = {'"*y gv"+y', "yank line to clipboards"}, + + -- visual shifting + ["<"] = {""] = {">gv"}, + + -- Allow using the repeat operator with a visual selection (!) + -- http://stackoverflow.com/a/8064607/127816 + ["."] = {":normal .", opts = { silent = true}}, + }, + + -- command line mappings + c = { + ["Tabe"] = {"tabe"}, + + -- Change Working Directory to that of the current file + ["cwd"] = {"lcd %:p:h", "change dir to current file"}, + ["cd."] = {"lcd %:p:h", "change dir to current file"}, + } } M.tabufline = { @@ -154,7 +250,7 @@ M.lspconfig = { "lsp hover", }, - ["gi"] = { + ["gm"] = { function() vim.lsp.buf.implementation() end, @@ -259,10 +355,7 @@ M.nvimtree = { n = { -- toggle - [""] = { " NvimTreeToggle ", "toggle nvimtree" }, - - -- focus - ["e"] = { " NvimTreeFocus ", "focus nvimtree" }, + [""] = { " NvimTreeToggle ", "toggle nvimtree" }, }, } @@ -272,16 +365,20 @@ M.telescope = { n = { -- find ["ff"] = { " Telescope find_files ", "find files" }, + [""] = { " Telescope find_files ", "find files" }, + ["fa"] = { " Telescope find_files follow=true no_ignore=true hidden=true ", "find all" }, - ["fw"] = { " Telescope live_grep ", "live grep" }, + ["f*"] = { " Telescope live_grep ", "live grep" }, ["fb"] = { " Telescope buffers ", "find buffers" }, + [";"] = { " Telescope buffers ", "find buffers" }, ["fh"] = { " Telescope help_tags ", "help page" }, ["fo"] = { " Telescope oldfiles ", "find oldfiles" }, ["tk"] = { " Telescope keymaps ", "show keys" }, -- git - ["cm"] = { " Telescope git_commits ", "git commits" }, - ["gt"] = { " Telescope git_status ", "git status" }, + ["tg"] = {" ", "telescope git commands"}, + ["tgc"] = { " Telescope git_commits ", "git commits" }, + ["tgs"] = { " Telescope git_status ", "git status" }, -- pick a hidden term ["pt"] = { " Telescope terms ", "pick hidden term" }, @@ -401,4 +498,25 @@ M.blankline = { }, } +-- Tagbar equivalent with LSP +M.vista = { + plugin = true, + + n = { + [""] = { " Vista!! ", "toggle Vista "} , + }, +} + +M.asyncrun = { + plugin = true, + + n = { + ["``"] = {" call asyncrun#quickfix_toggle(8)", "toggle quickfix window"} , + ["m"] = {":AsyncRun -program=" .. vim.o.makeprg .. "", "make using asyncrun"}, + ["r"] = {":AsyncRun ", "custom asyncrun command"}, + ["pd"] = {" AsyncRun lpr -P PDF_PRINT %", "PDF print file"}, + ["pp"] = {" AsyncRun lpr %"}, + }, +} + return M diff --git a/lua/core/options.lua b/lua/core/options.lua index 30ec75e..1c77bc7 100644 --- a/lua/core/options.lua +++ b/lua/core/options.lua @@ -20,26 +20,71 @@ opt.showmode = false opt.title = true opt.clipboard = "unnamedplus" opt.cul = true -- cursor line +opt.colorcolumn = "80" +opt.rulerformat = "%30(%=:b%n%y%m%r%w %l,%c%V %P%)" -- NvChad has custom ruler ! -- Indenting -opt.expandtab = true -opt.shiftwidth = 2 -opt.smartindent = true -opt.tabstop = 2 -opt.softtabstop = 2 +opt.expandtab = true -- Tabs are spaces, not tabs +opt.shiftwidth = 2 -- use indents of 2 spaces +opt.smartindent = true -- smart indent when starting new lines +opt.tabstop = 2 -- number of spaces when tab pressed +opt.softtabstop = 2 -- Let backspace delete indent +-- http://vim.wikia.com/wiki/Converting_tabs_to_spaces +opt.tabpagemax = 10 opt.fillchars = { eob = " " } opt.ignorecase = true opt.smartcase = true opt.mouse = "a" +opt.cpoptions:append ">" -- When appending to registers use newline + +-- GUI +opt.mousehide = true -- Numbers opt.number = true +opt.relativenumber = true opt.numberwidth = 2 opt.ruler = false -- disable nvim intro opt.shortmess:append "sI" +opt.viewoptions="folds,cursor,curdir" +opt.viewoptions:remove("options") + +-- . # and - are end of word designators +opt.iskeyword:remove(".") +opt.iskeyword:remove("#") +opt.iskeyword:remove("-") + +opt.foldlevelstart = 0 +opt.conceallevel=1 -- how to show text with :syn-conceal syntax + +opt.list = true -- show tabs,trailing spaces and non-breakable spaces +opt.listchars = "tab:› ,trail:•,extends:#,nbsp:." -- Highlight problematic whitespace +opt.diffopt:append("vertical") +opt.completeopt = "menu,menuone,noselect" +opt.wrap = false +opt.formatoptions:append("b") -- Auto-wrap text based on textwidt +opt.matchpairs:append("<:>") + + +-- Lines to scroll when cursor leaves screen +opt.scrolljump=5 +opt.scrolloff=3 + +-- Allow :find to work on all subdirectories +-- this only works when the original dir path is not changed +opt.path:append("**") + + +-- netrw file explorer (if it's used) +g.netrw_silent = 1 +g.netrw_liststyle=3 -- Display more details with files +g.netrw_banner = 0 -- Remove banner at top +g.netrw_browse_split = 4 -- Open files in vertical split +g.netrw_winsize = 20 -- width of the window (25%) + opt.signcolumn = "yes" opt.splitbelow = true @@ -48,6 +93,12 @@ opt.termguicolors = true opt.timeoutlen = 400 opt.undofile = true +-- backups +opt.backup = true +opt.backupcopy = "yes" +opt.backupdir = vim.fn.expand("$XDG_DATA_HOME/nvim/backups") +opt.sessionoptions="blank,buffers,curdir,folds,tabpages,winsize,resize,localoptions" + -- interval for writing swap file to disk, also used by gitsigns opt.updatetime = 250 @@ -55,7 +106,7 @@ opt.updatetime = 250 -- when cursor reaches end/beginning of line opt.whichwrap:append "<>[]hl" -g.mapleader = " " +g.mapleader = "," -- disable some builtin vim plugins local default_plugins = { @@ -64,10 +115,6 @@ local default_plugins = { "getscriptPlugin", "gzip", "logipat", - "netrw", - "netrwPlugin", - "netrwSettings", - "netrwFileHandlers", "matchit", "tar", "tarPlugin", diff --git a/lua/custom/chadrc.lua b/lua/custom/chadrc.lua new file mode 100644 index 0000000..79c8ba9 --- /dev/null +++ b/lua/custom/chadrc.lua @@ -0,0 +1,22 @@ +-- Just an example, supposed to be placed in /lua/custom/ + +local M = {} + +-- make sure you maintain the structure of `core/default_config.lua` here, +-- example of changing theme: + +M.ui = { + theme = "monekai", + theme_toggle = { "monekai", "blossom" }, + -- hl_override = { + -- CursorLine = { + -- underline = 1 + -- } + -- }, +} + +M.plugins = { + user = require "custom.plugins" +} + +return M diff --git a/lua/custom/init.lua b/lua/custom/init.lua new file mode 100644 index 0000000..d888197 --- /dev/null +++ b/lua/custom/init.lua @@ -0,0 +1,42 @@ +-- local augroup = vim.api.nvim_create_augroup +-- local autocmd = vim.api.nvim_create_autocmd + +vim.cmd [[ + hi CursorLine gui=underline +]] + + +-- Shift key typos +vim.cmd [[ + command! -bang -nargs=* -complete=file E e + command! -bang -nargs=* -complete=file W w + command! -bang -nargs=* -complete=file Wq wq + command! -bang -nargs=* -complete=file WQ wq + command! -nargs=* -complete=help H h + command! -bang Wa wa + command! -bang WA wa + command! -bang Q q + command! -bang QA qa + command! -bang Qa qa +]] + +vim.cmd [[ + " Autocompile suckless + let dwm_file_patterns = expand("$HOME/.local/src/suckless/*/{config.h,*.c}") + + augroup DWM + au! + + execute "au BufEnter " . dwm_file_patterns . " :lcd %:p:h" + execute "au BufWrite " . dwm_file_patterns . " :AsyncRun! make clean && make && sudo make install" + "au BufWrite */src/*/dwm*/{*.h,dwm.c} :AsyncRun! make clean && make && sudo make install + augroup END +]] + +-- Make asyncrun work with fugitive +vim.cmd [[ + augroup asyncrun + au! + command -bang -nargs=* -complete=file Make AsyncRun -program=make @ + augroup END +]] diff --git a/lua/custom/plugins/init.lua b/lua/custom/plugins/init.lua new file mode 100644 index 0000000..ecad11d --- /dev/null +++ b/lua/custom/plugins/init.lua @@ -0,0 +1,39 @@ +return { + ["mfussenegger/nvim-dap"] = { + module = "dap" + }, + ["liuchengxu/vista.vim"] = { + cmd = "Vista", + setup = function() + require("core.utils").load_mappings "vista" + end + }, + ["folke/which-key.nvim"] = { + disable = false, + }, + -- Run async commands (make & errors) + ["skywind3000/asyncrun.vim"] = { + config = function() + require("core.utils").load_mappings "asyncrun" + vim.g.asyncrun_open = 8 + end + }, + ["L3MON4D3/LuaSnip"] = { + config = function() + -- load default config first + require("plugins.configs.others").luasnip() + + vim.g.my_snippets_paths = {"./custom_snippets"} + require("luasnip").filetype_extend("markdown", { "markdown_zk" }) + + -- load snippets from "honza/vim-snippets" + -- includes ultisnips and snipmate snippets + require("luasnip.loaders.from_snipmate").lazy_load({ override_priority = 800 }) + require("luasnip.loaders.from_snipmate").lazy_load { + paths = vim.g.my_snippets_paths, + override_priority = 800 + } + end + }, + ["honza/vim-snippets"] = {} +} diff --git a/lua/plugins/configs/cmp.lua b/lua/plugins/configs/cmp.lua index 2b69b6b..99cd673 100644 --- a/lua/plugins/configs/cmp.lua +++ b/lua/plugins/configs/cmp.lua @@ -57,12 +57,36 @@ local options = { [""] = cmp.mapping.select_next_item(), [""] = cmp.mapping.scroll_docs(-4), [""] = cmp.mapping.scroll_docs(4), - [""] = cmp.mapping.complete(), - [""] = cmp.mapping.close(), + [""] = cmp.mapping.complete(), + [""] = cmp.mapping.close(), [""] = cmp.mapping.confirm { behavior = cmp.ConfirmBehavior.Replace, select = false, }, + -- luasnip forward jump + [""] = cmp.mapping(function(fallback) + local luasnip = require("luasnip") + if luasnip.expand_or_jumpable() then + luasnip.expand_or_jump() + else + fallback() + end + end, { + "i", + "s", + }), + -- luasnip reverse jump + [""] = cmp.mapping(function(fallback) + local luasnip = require("luasnip") + if luasnip.jumpable(-1) then + luasnip.jump(-1) + else + fallback() + end + end, { + "i", + "s", + }), [""] = cmp.mapping(function(fallback) if cmp.visible() then cmp.select_next_item() diff --git a/lua/plugins/configs/lspconfig.lua b/lua/plugins/configs/lspconfig.lua index 0c16830..10c1dd8 100644 --- a/lua/plugins/configs/lspconfig.lua +++ b/lua/plugins/configs/lspconfig.lua @@ -71,4 +71,9 @@ lspconfig.sumneko_lua.setup { }, } +lspconfig.gopls.setup { + on_attach = M.on_attach, + capabilities = M.capabilities, +} + return M diff --git a/lua/plugins/configs/others.lua b/lua/plugins/configs/others.lua index 544f2f0..8ed91ab 100644 --- a/lua/plugins/configs/others.lua +++ b/lua/plugins/configs/others.lua @@ -55,8 +55,8 @@ M.blankline = function() buftype_exclude = { "terminal" }, show_trailing_blankline_indent = false, show_first_indent_level = false, - show_current_context = true, - show_current_context_start = true, + show_current_context = false, + show_current_context_start = false, } options = load_override(options, "lukas-reineke/indent-blankline.nvim")