From f639c1bd959909d6b4ee733ff768918424fb8836 Mon Sep 17 00:00:00 2001 From: Evan Chen Date: Tue, 24 Dec 2024 10:02:55 -0800 Subject: [PATCH] feat(vim): what an adventure --- .codespellrc | 4 +- nvim/lua/config/keymaps.lua | 83 ++++++++++++++++++++++++++------ nvim/lua/plugins/builtins.lua | 50 +++++++++++++------ nvim/lua/plugins/colorscheme.lua | 3 ++ 4 files changed, 107 insertions(+), 33 deletions(-) diff --git a/.codespellrc b/.codespellrc index ebc4b826..2f2fae66 100644 --- a/.codespellrc +++ b/.codespellrc @@ -1,4 +1,4 @@ [codespell] -skip=vim/autoload/plug.vim,i3/3kon/*,i18n/zh_TW/LC_MESSAGES/*,ranger/*,vim/after/ftplugin/asy.vim,sh-scripts/git-prompt.bash,sh-scripts/git-completion.bash,gh-extensions/*,lualatex-font-catalog/*,*/poetry.lock,texmf/tex/latex/beamer/*,typst/packages/local/svg-emoji/*,nvim/lazy-lock.json +skip=vim/autoload/plug.vim,i3/3kon/*,i18n/zh_TW/LC_MESSAGES/*,ranger/*,vim/after/ftplugin/asy.vim,sh-scripts/git-prompt.bash,sh-scripts/git-completion.bash,gh-extensions/*,lualatex-font-catalog/*,*/poetry.lock,texmf/tex/latex/beamer/*,typst/packages/local/svg-emoji/* count= -ignore-words-list=ques,alph,mor,nd,progamer,iterm,oly,scaleable,ake,Fallin,WarpIn,ABD,Hom,forin,oint +ignore-words-list=ques,alph,mor,nd,progamer,iterm,oly,scaleable,ake,Fallin,WarpIn,ABD,Hom,forin,oint,noice diff --git a/nvim/lua/config/keymaps.lua b/nvim/lua/config/keymaps.lua index 6d22307b..d0b3d4f9 100644 --- a/nvim/lua/config/keymaps.lua +++ b/nvim/lua/config/keymaps.lua @@ -8,26 +8,23 @@ vim.keymap.set("n", "", function() else return "" end -end, { expr = true, noremap = true, desc = "Write all" }) +end, { expr = true, remap = true, desc = "Write all" }) vim.keymap.del("n", "s") vim.keymap.del("n", "S") -vim.keymap.set( - "n", - "e", - ":let $VIM_DIR=expand('%:p:h'):silent !xfce4-terminal --working-directory='$VIM_DIR' &", - { noremap = true, desc = "Open an xfce4-terminal" } -) +vim.keymap.set("n", "t", function() + vim.cmd("silent !xfce4-terminal --working-directory='" .. vim.fn.expand("%:p:h") .. "' &") +end, { noremap = true, silent = true, desc = "Open an xfce4-terminal" }) -vim.keymap.set("n", "-h", "h", { noremap = true, desc = "Move one window left" }) -vim.keymap.set("n", "-l", "l", { noremap = true, desc = "Move one window right" }) -vim.keymap.set("n", "-j", "j", { noremap = true, desc = "Move one window down" }) -vim.keymap.set("n", "-k", "k", { noremap = true, desc = "Move one window up" }) -vim.keymap.set("n", "-i", ":split", { noremap = true, desc = "Open a horizontal split" }) -vim.keymap.set("n", "-s", ":vsplit", { noremap = true, desc = "Open a vertical split" }) - -vim.keymap.set("n", "", ":bp", { noremap = true, desc = "Previous buffer" }) +vim.keymap.set("n", "-o", "o", { noremap = true, silent = true, desc = "Maximize window" }) +vim.keymap.set("n", "-h", "h", { noremap = true, silent = true, desc = "Move one window left" }) +vim.keymap.set("n", "-l", "l", { noremap = true, silent = true, desc = "Move one window right" }) +vim.keymap.set("n", "-j", "j", { noremap = true, silent = true, desc = "Move one window down" }) +vim.keymap.set("n", "-k", "k", { noremap = true, silent = true, desc = "Move one window up" }) +vim.keymap.set("n", "-i", ":split", { noremap = true, silent = true, desc = "Open a horizontal split" }) +vim.keymap.set("n", "-s", ":vsplit", { noremap = true, silent = true, desc = "Open a vertical split" }) +vim.keymap.set("n", "", ":bp", { noremap = true, silent = true, desc = "Previous buffer" }) local function is_git_repo() vim.fn.system("git rev-parse --is-inside-work-tree 2>/dev/null") @@ -54,3 +51,59 @@ vim.keymap.set("n", "-", function() Snacks.bufdelete() end end, { noremap = true, desc = "Close buffer" }) + +vim.cmd([[ +" Buffer switching: https://vi.stackexchange.com/a/9255 +function! EvanSwitchBufNum(num) + let l:buffers = filter(range(1, bufnr('$')), 'buflisted(v:val)') + let l:input = a:num . '' + while 1 + let l:cnt = 0 + let l:i = 0 + + " count matches + while l:i0 + echo 'no buffer [' . l:input . ']' + return '' + elseif l:cnt==1 && l:input==l:example + return ':b ' . l:example . "\" + endif + + echo ':b ' . l:input + let l:n = getchar() + if l:n==char2nr("\") || l:n==char2nr("\") + " delete one word + if len(l:input)>=2 + let l:input = l:input[0:len(l:input)-2] + else + let l:input = '' + endif + elseif l:n==char2nr("\") || (l:nchar2nr('9')) + return ':b ' . l:input . "\" + else + let l:input = l:input . nr2char(l:n) + endif + let g:n = l:n + endwhile +endfunc + +nnoremap 1 EvanSwitchBufNum(1) +nnoremap 2 EvanSwitchBufNum(2) +nnoremap 3 EvanSwitchBufNum(3) +nnoremap 4 EvanSwitchBufNum(4) +nnoremap 5 EvanSwitchBufNum(5) +nnoremap 6 EvanSwitchBufNum(6) +nnoremap 7 EvanSwitchBufNum(7) +nnoremap 8 EvanSwitchBufNum(8) +nnoremap 9 EvanSwitchBufNum(9) +]]) diff --git a/nvim/lua/plugins/builtins.lua b/nvim/lua/plugins/builtins.lua index c11acda6..01ce1be3 100644 --- a/nvim/lua/plugins/builtins.lua +++ b/nvim/lua/plugins/builtins.lua @@ -1,17 +1,7 @@ return { { - "nvim-neo-tree/neo-tree.nvim", - keys = { - { "e", false }, - { "E", false }, - { - "t", - function() - require("neo-tree.command").execute({ toggle = true, dir = LazyVim.root() }) - end, - desc = "Explorer NeoTree (Root Dir)", - }, - }, + "folke/noice.nvim", + enabled = false, }, { "saghen/blink.cmp", @@ -109,6 +99,9 @@ return { hint = icons.diagnostics.Hint, }, }, + }, + lualine_y = { + { "filetype", icon_only = false, separator = "", padding = { left = 1, right = 1 } }, { "diff", symbols = { @@ -128,11 +121,8 @@ return { end, }, }, - lualine_y = { - { "filetype", icon_only = false, separator = "", padding = { left = 1, right = 1 } }, - }, lualine_z = { - { "location", padding = { left = 0, right = 1 } }, + { "location", padding = { left = 1, right = 1 } }, }, }, extensions = { "neo-tree", "lazy", "fzf" }, @@ -161,4 +151,32 @@ return { return opts end, }, + { + "akinsho/bufferline.nvim", + opts = { + highlights = { + buffer_selected = { + fg = { + attribute = "fg", + highlight = "CursorLineNr", + }, + }, + buffer_visible = { + fg = { + attribute = "fg", + highlight = "LineNr", + }, + }, + }, + options = { + always_show_bufferline = true, + indicator = { style = "underline" }, + show_buffer_close_icons = false, + show_close_icon = false, + modified_icon = "[+]", + numbers = "buffer_id", + tab_size = 12, + }, + }, + }, } diff --git a/nvim/lua/plugins/colorscheme.lua b/nvim/lua/plugins/colorscheme.lua index 1e562273..b97280d6 100644 --- a/nvim/lua/plugins/colorscheme.lua +++ b/nvim/lua/plugins/colorscheme.lua @@ -17,6 +17,8 @@ return { return { LineNr = { fg = colors.peach }, CursorLineNr = { fg = colors.teal, bg = colors.overlay0, style = { "bold" } }, + Folded = { bg = colors.surface2 }, + Conceal = { fg = colors.yellow }, Identifier = { style = { "bold" } }, Include = { fg = colors.green }, @@ -24,6 +26,7 @@ return { PreProc = { fg = colors.maroon, style = { "bold" } }, Special = { fg = colors.green, style = { "bold" } }, Statement = { fg = colors.sapphire, style = { "bold" } }, + texTitleArg = { fg = colors.base, style = { "bold" } }, texEnvArgName = { fg = colors.red, style = { "bold" } }, texEnvOpt = { fg = colors.text, style = { "bold" } },