From 9b564fcfeec95ed965252ef4acc6ee42702ded88 Mon Sep 17 00:00:00 2001 From: Hsieh Chin Fan Date: Sun, 28 Jul 2024 21:01:19 +0800 Subject: Update --- vim/init/basic.vim | 133 ++++++++--- vim/init/config.vim | 30 +-- vim/init/keymaps.vim | 115 ++++----- vim/mini.lua | 659 ++++++++++++++++++++++++++++++++------------------- 4 files changed, 585 insertions(+), 352 deletions(-) diff --git a/vim/init/basic.vim b/vim/init/basic.vim index 2394045..e18d51f 100644 --- a/vim/init/basic.vim +++ b/vim/init/basic.vim @@ -4,7 +4,7 @@ " Used for general usecases. No keymap and personal preference "====================================================================== -" Vimscript file settings ---------------------- {{{ +" For Vimscript {{{ " Usage: type --- for foldmark augroup filetype_vim @@ -14,13 +14,63 @@ augroup filetype_vim augroup END " }}} -" GERERNAL ----------------{{{ +" For Buffer and Tab {{{ +augroup tabinfo + au! + let g:tab_group = {} + " BufEnter {{{ + function! AddBufToTabGroup(tab_group) + let l:tabId = tabpagenr() + let l:bufnr = bufnr() + + if has_key(a:tab_group, l:tabId) + for v in a:tab_group[l:tabId] + if v == l:bufnr + return + endif + endfor + call add(a:tab_group[l:tabId], l:bufnr) + else + let a:tab_group[l:tabId] = [l:bufnr] + endif + + endfunc + autocmd BufWinEnter * if &buflisted | call AddBufToTabGroup(g:tab_group) | endif + " }}} + " BufDelete {{{ + function! RemoveBufFromTabGroup(tab_group) + let l:tabId = tabpagenr() + + if has_key(a:tab_group, l:tabId) + let l:new_tab_group = {} + + for [k, tab_list] in items(a:tab_group) + let l:list = [] + for buf in tab_list + if buflisted(buf) > 0 && buf != expand('') + call add(l:list, buf) + end + endfor + if !empty(l:list) + let l:new_tab_group[k] = l:list + endif + endfor + let g:tab_group = l:new_tab_group + + endif + + endfunc + autocmd BufDelete * call RemoveBufFromTabGroup(g:tab_group) + "}}} +augroup END +"}}} +" GERERNAL {{{ -let mapleader = "," " Always use comma as leader key -set nocompatible " Disable vi compatible, today is 20XX -set path=.,** " Allow :find with completion -set mouse= " Disable mouse selection -set winaltkeys=no " Allow alt key for mapping +let mapleader = "," " Always use comma as leader key +set nocompatible " Disable vi compatible, today is 20XX +set path=.,** " Allow :find with completion +set mouse= " Disable mouse selection +set winaltkeys=no " Allow alt key for mapping " Turn persistent undo on " means that you can undo even when you close a buffer/VIM @@ -43,22 +93,20 @@ set spellfile="/tmp/spell" sign define piet text=>> texthl=Search " }}} -" VISUAL ----------------{{{ +" VISUAL {{{ " colorscheme desert " Editing Area -set wrap " enable wrap by default -set scrolloff=3 " Leave some buffer when scrolling down -set showmatch " Show pairing brackets +set wrap " enable wrap by default +set scrolloff=3 " Leave some buffer when scrolling down +set showmatch " Show pairing brackets set display=lastline set lazyredraw -set formatoptions+=m " 遇到Unicode值大於255的文本,不必等到空格再折行 -set formatoptions+=B " 合併兩行中文時,不在中間加空格 set whichwrap=b,s " Side column -set signcolumn=yes number relativenumber +set number relativenumber " Cursor set cursorline @@ -67,30 +115,40 @@ set matchtime=2 " In most of the cases, it is overrides by lightline.vim set statusline=\ %F%m%r%h\ %w\ \ CWD:\ %r%{getcwd()}%h\ \ \ Line:\ %l\ \ Column:\ %c -set laststatus=2 " Always show the status line -set ruler " Show cursor position +set laststatus=2 " Always show the status line +set ruler " Show cursor position set wildmenu wildoptions=pum,fuzzy " Format of error message set errorformat+=[%f:%l]\ ->\ %m,[%f:%l]:%m +" Direction for new window +set splitright + " }}} -" EDIT ----------------{{{ +" EDIT {{{ + +" overrides ftplugin in runtimepath +" Don't wrap line when typing CJK characters +" Don't add spaces for CJK +" Don't add comment at next line +autocmd Filetype * set fo+=mB fo-=cro -set backspace=eol,start,indent " Set Backspace behaviors -set autoindent smartindent set shiftwidth=2 +set autoindent smartindent set cindent set ttimeout set timeoutlen=500 + +set backspace=eol,start,indent " Set Backspace behaviors + " set updatetime=4000 " autocmd CursorHold * normal! m' -" TAB and special Chars ----------------{{{ +" TAB and special Chars {{{ -set tabstop=8 +set tabstop=8 softtabstop=8 set expandtab -set softtabstop=-1 " Invisible chars set nolist @@ -99,23 +157,23 @@ set listchars=tab:»·,extends:>,precedes:< " }}} " }}} -" JUMP to anoterh file ----------------{{{ +" JUMP to anoterh file {{{ set isfname=@,48-57,/,.,-,_,+,,,#,$,%,~ " This affects filename recognition for gf (go to file) -set suffixesadd=.md " Enable reference markdown file without extension +set suffixesadd=.md " Enable reference markdown file without extension " }}} -" SEARCH ----------------{{{ +" SEARCH {{{ -set ignorecase " Search case without case sensation +set ignorecase " Search case without case sensation set smartcase -set hlsearch " Hilight all matched texts -set incsearch " Show matched strings when typing +set hlsearch " Highlight all matched texts +set incsearch " Show matched strings when typing " }}} -" BUFFERS ----------------{{{ +" BUFFERS {{{ -" Go to last cursor position ----------------{{{ +" Go to last cursor position {{{ augroup vimStartup au! " When editing a file, always jump to the last known cursor position. @@ -131,21 +189,22 @@ augroup END " }}} " }}} -" FOLD ----------------{{{ +" FOLD {{{ + set foldenable " Allow fold set foldmethod=indent " Fold contents by indent set foldlevel=2 set fillchars+=foldopen:▽,foldsep:│,foldclose:▶ let g:defaut_foldcolumn = "" if has('nvim') - let g:defaut_foldcolumn = "auto:5" + let g:defaut_foldcolumn = "auto:3" else - let g:defaut_foldcolumn = 5 + let g:defaut_foldcolumn = 3 endif let &foldcolumn = g:defaut_foldcolumn " }}} -" ENCODING_PREFERENCE ----------------{{{ +" ENCODING_PREFERENCE {{{ if has('multi_byte') set encoding=utf-8 @@ -155,7 +214,7 @@ if has('multi_byte') endif " }}} -" BACKUP ----------------{{{ +" BACKUP {{{ " Allow backup set backup @@ -170,7 +229,7 @@ set backupdir=~/.vim/tmp set writebackup " }}} -" HIGHLIGHT ----------------{{{ +" HIGHLIGHT {{{ syntax enable set conceallevel=1 @@ -185,7 +244,7 @@ highlight ExtraWhitespace ctermbg=red guibg=red match ExtraWhitespace /\s\+$/ " }}} -" MISC ----------------{{{ +" MISC {{{ " Use Unix way to add newline set ffs=unix,dos,mac diff --git a/vim/init/config.vim b/vim/init/config.vim index 4e1c06c..4181ad3 100644 --- a/vim/init/config.vim +++ b/vim/init/config.vim @@ -3,7 +3,7 @@ " Do some autocommand for by contexts "====================================================================== -" Unnamed Buffer ----------------{{{ +" Unnamed Buffer {{{ " Automatically delete unnamed empty buffer when leaving augroup DeleteUnnamedEmptBuffer! @@ -12,7 +12,7 @@ augroup DeleteUnnamedEmptBuffer! augroup END " }}} -" Small Terminal ----------------{{{ +" Small Terminal {{{ augroup TerminalSize au! @@ -27,13 +27,13 @@ augroup TerminalSize augroup END " }}} -" X11 ----------------{{{ +" X11 {{{ " Change IM to US when exit to Normal mode autocmd InsertLeave * :silent !fcitx-remote -c &>/dev/null || true " }}} -" TMUX ----------------{{{ +" TMUX {{{ " 有 tmux 何没有的功能键超时(毫秒) if $TMUX != '' @@ -60,7 +60,7 @@ if !has('gui_running') && &term =~ '^\%(screen\|tmux\)' endif " }}} -" KeyCode ----------------{{{ +" KeyCode {{{ "---------------------------------------------------------------------- " 终端下允许 ALT,详见:http://www.skywind.me/blog/archives/2021 @@ -114,22 +114,22 @@ call s:key_escape('', '[23;2~') call s:key_escape('', '[24;2~') " }}} -" Filetype ----------------{{{ +" Filetype {{{ augroup InitFileTypes au! - " Filetype for Vim ----------------{{{ + " Filetype for Vim {{{ " Help page - autocmd BufEnter *.txt if &filetype == 'help' | wincmd T | endif + autocmd BufEnter * if &filetype == 'help' | wincmd T | set buflisted | endif " quickfix: hide line number autocmd FileType quickfix setlocal nonumber " }}} - " Shebeng: Set filetype from shebeng ----------------{{{ + " Shebeng: Set filetype from shebeng {{{ function! s:ApplyShebang() let l:filetype = matchstr(getline(1), '^#!.*[ /]\zs[[:alnum:]]\+$') let l:shebangMatch = #{ node: "javascript" } @@ -143,7 +143,7 @@ augroup InitFileTypes endfunction autocmd BufReadPost * call ApplyShebang() " }}} - " Markdown ----------------{{{ + " Markdown {{{ augroup Config_Markdown au! @@ -168,7 +168,7 @@ augroup InitFileTypes augroup END " }}} - " HTML ----------------{{{ + " HTML {{{ " Usage: cl(ass) or id to edit html tag attribute function! s:ChangeAttr(pattern) @@ -192,17 +192,17 @@ augroup InitFileTypes " Reload preview server autocmd BufWrite *.html,*.js,*.css call ReloadServer() - function ReloadServer() + function! ReloadServer() silent !browser-sync reload &>/dev/null endfunction " }}} - " Mail ----------------{{{ + " Mail {{{ autocmd BufRead /tmp/mutt-* set tw=72 " }}} - " Password ----------------{{{ + " Password {{{ " Hide the first line of a file if editing password file " TODO a better way to determine a file is related to password-store, now use @@ -218,7 +218,7 @@ augroup InitFileTypes norm! ggzfl endfunction " }}} - " Beancount ----------------{{{ + " Beancount {{{ autocmd BufRead,BufNewFile *.bean call PrepareBean() function PrepareBean() diff --git a/vim/init/keymaps.vim b/vim/init/keymaps.vim index f13756b..1eb2b20 100644 --- a/vim/init/keymaps.vim +++ b/vim/init/keymaps.vim @@ -21,15 +21,15 @@ nnoremap W :set wrap! function! s:WriteOrEnterFileName() if !empty(expand('%')) | write! | else | call feedkeys(":w ") | endif endfunction -nmap w :call WriteOrEnterFileName() +nnoremap w :call WriteOrEnterFileName() " :W sudo saves the file " (useful for handling the permission-denied error) command! W execute 'w !sudo -S tee %' edit! " Quit -nmap q :q -nmap cq :cq +nnoremap q :q +nnoremap cq :cq " Remap in Quickfix, Cmdwin Location list augroup vimrc_CRfix @@ -57,7 +57,7 @@ augroup END " execute "set =\eh" " Spell -nnoremap sp :set spell!:set spell? +nnoremap \s :set spell!:set spell? nnoremap ss ]s nnoremap S [s @@ -68,6 +68,7 @@ nnoremap 1 vnoremap Tz :!trans -t zh-TW -b vnoremap Te :!trans -t en-US -b + " }}} " WORKING_DIR ----------------{{{ @@ -82,8 +83,8 @@ nnoremap cd :cd %:p:h:pwd nnoremap cd :cd nnoremap cdg :call CdToGitRepo():pwd -noremap :cd ..:pwd -noremap :call InCaseCdToLatestDir() +nnoremap :cd ..:pwd +nnoremap :call InCaseCdToLatestDir() " Switch CWD to root git directory function! CdToGitRepo() @@ -105,17 +106,21 @@ endfunction " MOTION ----------------{{{ " j/k will move virtual lines (lines that wrap) -noremap j (v:count == 0 ? 'gj' : 'j') -noremap k (v:count == 0 ? 'gk' : 'k') +nnoremap j (v:count == 0 ? 'gj' : 'j') +nnoremap k (v:count == 0 ? 'gk' : 'k') " Quick move in a line -noremap 30h -noremap 30l +nnoremap 30h +nnoremap 30l " File under the cursor nnoremap gf nnoremap gF :e +xnoremap iq i" +xnoremap aq a" + + " READLINE_FEATURES ----------------{{{ inoremap @@ -145,22 +150,22 @@ cnoremap d$ cnoremap de " Moving with wrap -noremap gj -noremap gk +nnoremap gj +nnoremap gk inoremap gj inoremap gk " }}} " JUMP_TO_TABS_WITH_ALT ----------------{{{ -noremap :tabn 1 -noremap :tabn 2 -noremap :tabn 3 -noremap :tabn 4 -noremap :tabn 5 -noremap :tabn 6 -noremap :tabn 7 -noremap :tabn 8 -noremap :tablast +nnoremap :tabn 1 +nnoremap :tabn 2 +nnoremap :tabn 3 +nnoremap :tabn 4 +nnoremap :tabn 5 +nnoremap :tabn 6 +nnoremap :tabn 7 +nnoremap :tabn 8 +nnoremap :tablast inoremap :tabn 1 inoremap :tabn 2 inoremap :tabn 3 @@ -211,23 +216,25 @@ nnoremap ee :edit $MYVIMRC " MANAGE_BUFFERS ----------------{{{ " Set options -noremap st :set -noremap ft :e'set filetype='..&filetype -noremap li :set list! -noremap sw :e'set shiftwidth='..&shiftwidth -noremap nu :set number! -noremap ru :set relativenumber! +nnoremap so :set +nnoremap ft :e'set filetype='..&filetype +nnoremap sw :e'set shiftwidth='..&shiftwidth +nnoremap ts :e'set tabstop='..&tabstop +nnoremap \e :set expandtab!:set expandtab? +nnoremap \l :set list!:set list? +nnoremap \n :set nu!:set nu? +nnoremap \r :set relativenumber!:set rnu? " Open a new buffer -nmap B :enew -nmap O :e /tmp/buffer +nnoremap B :enew +nnoremap O :e /tmp/buffer " Let l toggle between this and the last accessed buffer augroup SaveLastBuffer let g:lastbuffer = 1 - au BufLeave * let g:lastbuffer = bufnr() + au BufLeave * if &buflisted | let g:lastbuffer = expand('') | endif augroup END -noremap l :exe "buffer ".g:lastbuffer +nnoremap l :exe "buffer ".g:lastbuffer " Use Ctrl-C for buffer delete or quit vim ----------------{{{ @@ -238,9 +245,11 @@ function! ToggleQuit() let message = g:quitVimWhenPressingCtrlC ? "Unlock" : "Lock" echo message endfunction -nnoremap gl :call ToggleQuit() +nnoremap \q :call ToggleQuit() function! CloseBufferSafely() + let l:bufnr = bufnr() + " Ask Saving if &modified let answer = confirm("Save changes?", "&Yes\n&No\n&Cancel") if answer == 1 | write | endif @@ -248,27 +257,22 @@ function! CloseBufferSafely() if answer == "" | return | endif endif - let bufs = getbufinfo({'buflisted': 1}) - if len(bufs) == 1 - bdelete! + if g:tab_group[tabpagenr()] == [l:bufnr] + bdelete else - b# | bd! # + bprevious | bd # endif endfunction func! QuitWithCheck() if g:quitVimWhenPressingCtrlC silent! quit else - echo "Press gl to allow quit with " + echo "Press \\q to allow quit with " endif endfunc function! Bye() let windows = gettabinfo(tabpagenr())[0]['windows'] - try - let bufs = gettabinfo(tabpagenr())[0]['variables']['bufs'] - catch - let bufs = getbufinfo({'buflisted': 1}) - endtry + let bufs = getbufinfo({'buflisted': 1}) if len(windows) == 1 && len(bufs) == 1 call QuitWithCheck() @@ -282,8 +286,8 @@ function! Bye() endfunction nnoremap :call Bye() - -" Diff Mode ---------------- +" }}} +" Diff Mode {{{ function! CloseBuffersForDiff() windo | if &diff && &buftype == "nofile" | bdelete | endif @@ -329,10 +333,10 @@ nnoremap sb :windo set scrollbind! " 传统的 CTRL+hjkl 移动窗口不适用于 vim 8.1 的终端模式,CTRL+hjkl 在 " bash/zsh 及带文本界面的程序中都是重要键位需要保留,不能 tnoremap 的 "---------------------------------------------------------------------- -noremap h -noremap l -noremap j -noremap k +nnoremap h +nnoremap l +nnoremap j +nnoremap k inoremap h inoremap l inoremap j @@ -365,12 +369,12 @@ map tc :tabclose map tm :tabmove map to :tabonly -noremap :call Tab_MoveLeft() -noremap :call Tab_MoveRight() +nnoremap :call Tab_MoveLeft() +nnoremap :call Tab_MoveRight() " Let tl toggle between this and the last accessed tab let g:lasttab = 1 -nmap tl :exe "tabn ".g:lasttab +nnoremap tl :exe "tabn ".g:lasttab autocmd TabLeave * let g:lasttab = tabpagenr() " Opens a new tab with the current buffer's path @@ -394,8 +398,8 @@ endfunc " FOLD ----------------{{{ " Set fold options -noremap fm :e'set foldmethod='..&foldmethod -noremap fc :e'set foldcolumn='..&foldcolumn +nnoremap fm :e'set foldmethod='..&foldmethod +nnoremap fc :e'set foldcolumn='..&foldcolumn nnoremap zi zizz @@ -463,7 +467,7 @@ endfunction " HIGHLIGHT ----------------{{{ " Disable highlight when is pressed -noremap :noh +nnoremap :noh function! HiFile() let i = 1 @@ -501,7 +505,6 @@ inoremap ( () inoremap [ [] inoremap { {} -vnoremap S sa vnoremap ' ``>la' vnoremap q ``>la" vnoremap ( ``>la) @@ -591,6 +594,8 @@ vnoremap call SubstituteBySearch() " }}} " SIGN ----------------{{{ +nnoremap sc :e'set signcolumn='..&signcolumn + nnoremap si :exe ":sign place " .. line('.') .. " line=" .. line('.') .. " name=piet file=" .. expand("%:p") nnoremap sI :exe ":sign unplace * file=" .. expand("%:p") diff --git a/vim/mini.lua b/vim/mini.lua index e693db2..15f4c42 100644 --- a/vim/mini.lua +++ b/vim/mini.lua @@ -13,8 +13,7 @@ end vim.opt.rtp:prepend(lazypath) -- }}} require("lazy").setup({ - - "tpope/vim-sleuth", + -- "tpope/vim-sleuth", -- Telescope {{{ { "nvim-telescope/telescope.nvim", @@ -236,7 +235,6 @@ require("lazy").setup({ indent_markers = { enable = true, }, - -- icons = { show = { file = true, @@ -244,7 +242,6 @@ require("lazy").setup({ folder_arrow = true, git = true, }, - -- glyphs = { default = "󰈚", symlink = "", @@ -336,192 +333,278 @@ require("lazy").setup({ end, }, --}}} + -- lualine {{{ + { + "nvim-lualine/lualine.nvim", + event = "VeryLazy", + init = function() + vim.g.lualine_laststatus = vim.o.laststatus + if vim.fn.argc(-1) > 0 then + -- set an empty statusline till lualine loads + vim.o.statusline = " " + else + -- hide the statusline on the starter page + vim.o.laststatus = 0 + end + end, + opts = function() + -- PERF: we don't need this lualine require madness 🤷 + local lualine_require = require("lualine_require") + lualine_require.require = require - -- -- lspconfig {{{ - -- -- Use :help lspconfig-all to check servers - -- { - -- "neovim/nvim-lspconfig", - -- lazy = false, - -- config = function() - -- local lspconfig = require "lspconfig" - -- -- - -- -- typescript - -- lspconfig.lua_ls.setup {} - -- lspconfig.tsserver.setup {} - -- lspconfig.vimls.setup {} - -- lspconfig.html.setup {} - -- -- - -- vim.keymap.set("n", "F", function() - -- vim.lsp.buf.format() - -- end, { desc = "format files" }) - -- end, - -- }, - -- -- }}} - -- -- Mason {{{ - -- { - -- "williamboman/mason.nvim", - -- config = function() - -- require('mason').setup { - -- automatically_installation = true, - -- ensure_installed = { - -- "vim-language-server", - -- "lua-language-server", - -- "css-lsp", - -- "html-lsp", - -- "prettier", - -- "stylua", - -- }, - -- } - -- end - -- }, - -- -- }}} - -- -- treesitter {{{ - -- { - -- "nvim-treesitter/nvim-treesitter", - -- event = { "BufReadPost", "BufNewFile" }, - -- cmd = { "TSInstall", "TSBufEnable", "TSBufDisable", "TSModuleInfo" }, - -- build = ":TSUpdate", - -- config = function() - -- require("nvim-treesitter.configs").setup({ - -- ensure_installed = { "lua", "luadoc", "printf", "vim", "vimdoc" }, - -- -- - -- highlight = { - -- enable = true, - -- use_languagetree = true, - -- }, - -- -- - -- indent = { enable = true }, - -- }) - -- end, - -- }, - -- -- }}} - -- -- nvim-cmp {{{ - -- { - -- "hrsh7th/nvim-cmp", - -- event = { - -- "InsertEnter", - -- "CmdlineEnter" - -- }, - -- dependencies = { -- {{{ - -- { - -- -- snippet plugin - -- "L3MON4D3/LuaSnip", - -- build = "make install_jsregexp", - -- dependencies = { - -- "rafamadriz/friendly-snippets", - -- "saadparwaiz1/cmp_luasnip", - -- "onsails/lspkind-nvim", - -- }, - -- opts = { - -- history = true, - -- updateevents = "TextChanged,TextChangedI" - -- }, - -- config = function(_, opts) - -- require("luasnip").config.set_config(opts) - -- require("luasnip.loaders.from_vscode").lazy_load() - -- require("luasnip.loaders.from_lua").load() - -- require("luasnip.loaders.from_lua").lazy_load { paths = vim.g.lua_snippets_path or "" } - -- -- - -- vim.api.nvim_create_autocmd("InsertLeave", { - -- callback = function() - -- if - -- require("luasnip").session.current_nodes[vim.api.nvim_get_current_buf()] - -- and not require("luasnip").session.jump_active - -- then - -- require("luasnip").unlink_current() - -- end - -- end, - -- }) - -- end, - -- }, - -- -- - -- -- cmp sources plugins - -- { - -- "hrsh7th/cmp-nvim-lua", - -- "hrsh7th/cmp-nvim-lsp", - -- "hrsh7th/cmp-buffer", - -- "hrsh7th/cmp-path", - -- "hrsh7th/cmp-cmdline", - -- }, - -- }, -- }}} - -- config = function() - -- local cmp = require "cmp" - -- local default_mapping = { - -- [""] = cmp.mapping.select_prev_item(), - -- [""] = cmp.mapping.select_next_item(), - -- [""] = cmp.mapping.select_prev_item(), - -- [""] = cmp.mapping.select_next_item(), - -- [""] = cmp.mapping.scroll_docs(-4), - -- [""] = cmp.mapping.scroll_docs(4), - -- [""] = cmp.mapping.complete(), - -- [""] = cmp.mapping.close(), - -- [''] = cmp.mapping.confirm(), - -- [''] = cmp.mapping.abort(), - -- } - -- - -- require("cmp").setup({ - -- completion = { - -- completeopt = "menu,menuone,noselect", - -- }, - -- window = { - -- documentation = cmp.config.window.bordered(), - -- completion = cmp.config.window.bordered({ - -- winhighlight = 'Normal:CmpPmenu,CursorLine:PmenuSel,Search:None' - -- }), - -- }, - -- snippet = { - -- expand = function(args) - -- require("luasnip").lsp_expand(args.body) - -- end, - -- }, - -- formatting = { - -- format = require('lspkind').cmp_format({ - -- with_text = true, -- do not show text alongside icons - -- maxwidth = 50, -- prevent the popup from showing more than provided characters (e.g 50 will not show more than 50 characters) - -- before = function(entry, vim_item) - -- -- Source 显示提示来源 - -- vim_item.menu = '<' .. entry.source.name .. '>' - -- return vim_item - -- end - -- }) - -- }, - -- mapping = default_mapping, - -- sources = cmp.config.sources { - -- { name = "nvim_lsp" }, - -- { name = "luasnip" }, - -- { name = "buffer" }, - -- { name = "nvim_lua" }, - -- { name = "path" }, - -- }, - -- experimental = { - -- ghost_text = true, - -- } - -- }) - -- cmp.setup.cmdline(':', { - -- mapping = cmp.mapping.preset.cmdline { - -- [''] = cmp.config.disable, - -- [''] = cmp.config.disable, - -- [''] = cmp.mapping.abort(), - -- }, - -- sources = cmp.config.sources( - -- { { name = 'path' } }, - -- { { name = 'cmdline' } } - -- ) - -- }) - -- cmp.setup.cmdline({ '/', '?' }, { - -- mapping = cmp.mapping.preset.cmdline { - -- [''] = cmp.config.disable, - -- [''] = cmp.config.disable, - -- [''] = cmp.mapping.abort(), - -- }, - -- sources = { { name = 'buffer' } } - -- }) - -- - -- vim.opt.complete = "" - -- end, - -- }, - -- - -- -- }}} + vim.o.laststatus = vim.g.lualine_laststatus + + local opts = { + options = { + theme = "auto", + globalstatus = vim.o.laststatus == 3, + disabled_filetypes = { statusline = { "dashboard", "alpha", "ministarter" } }, + }, + sections = { + lualine_a = { "mode" }, + lualine_b = { "branch" }, + + lualine_x = { + -- stylua: ignore + { + function() return require("noice").api.status.command.get() end, + cond = function() return package.loaded["noice"] and require("noice").api.status.command.has() end, + }, + -- stylua: ignore + { + function() return require("noice").api.status.mode.get() end, + cond = function() return package.loaded["noice"] and require("noice").api.status.mode.has() end, + }, + -- stylua: ignore + { + function() return " " .. require("dap").status() end, + cond = function() return package.loaded["dap"] and require("dap").status() ~= "" end, + }, + -- stylua: ignore + { + require("lazy.status").updates, + cond = require("lazy.status").has_updates, + }, + { + "diff", + source = function() + local gitsigns = vim.b.gitsigns_status_dict + if gitsigns then + return { + added = gitsigns.added, + modified = gitsigns.changed, + removed = gitsigns.removed, + } + end + end, + }, + }, + lualine_y = { + { "progress", separator = " ", padding = { left = 1, right = 0 } }, + { "location", padding = { left = 0, right = 1 } }, + }, + lualine_z = { + function() + return " " .. os.date("%R") + end, + }, + }, + extensions = { "neo-tree", "lazy" }, + } + + return opts + end, + }, + -- }}} + + -- lspconfig {{{ + -- Use :help lspconfig-all to check servers + { + "neovim/nvim-lspconfig", + lazy = false, + config = function() + local lspconfig = require "lspconfig" + -- + -- typescript + lspconfig.lua_ls.setup {} + lspconfig.tsserver.setup {} + lspconfig.vimls.setup {} + lspconfig.html.setup {} + -- + vim.keymap.set("n", "F", function() + vim.lsp.buf.format() + end, { desc = "format files" }) + end, + }, + -- }}} + -- Mason {{{ + { + "williamboman/mason.nvim", + dependencies = { + "williamboman/mason-lspconfig.nvim", + }, + config = function() + require('mason').setup { + automatically_installation = true, + ensure_installed = { + "vim-language-server", + "lua-language-server", + "css-lsp", + "html-lsp", + "prettier", + "stylua", + }, + } + end + }, + -- }}} + -- treesitter {{{ + { + "nvim-treesitter/nvim-treesitter", + event = { "BufReadPost", "BufNewFile" }, + cmd = { "TSInstall", "TSBufEnable", "TSBufDisable", "TSModuleInfo" }, + build = ":TSUpdate", + config = function() + require("nvim-treesitter.configs").setup({ + ensure_installed = { "lua", "luadoc", "printf", "vim", "vimdoc" }, + -- + highlight = { + enable = true, + use_languagetree = true, + }, + -- + indent = { enable = true }, + }) + end, + }, + -- }}} + -- nvim-cmp {{{ + { + "hrsh7th/nvim-cmp", + event = { + "InsertEnter", + "CmdlineEnter" + }, + dependencies = { -- {{{ + { + -- snippet plugin + "L3MON4D3/LuaSnip", + build = "make install_jsregexp", + dependencies = { + "rafamadriz/friendly-snippets", + "saadparwaiz1/cmp_luasnip", + "onsails/lspkind-nvim", + }, + opts = { + history = true, + updateevents = "TextChanged,TextChangedI" + }, + config = function(_, opts) + require("luasnip").config.set_config(opts) + require("luasnip.loaders.from_vscode").lazy_load() + require("luasnip.loaders.from_lua").load() + require("luasnip.loaders.from_lua").lazy_load { paths = vim.g.lua_snippets_path or "" } + -- + vim.api.nvim_create_autocmd("InsertLeave", { + callback = function() + if + require("luasnip").session.current_nodes[vim.api.nvim_get_current_buf()] + and not require("luasnip").session.jump_active + then + require("luasnip").unlink_current() + end + end, + }) + end, + }, + -- + -- cmp sources plugins + { + "hrsh7th/cmp-nvim-lua", + "hrsh7th/cmp-nvim-lsp", + "hrsh7th/cmp-buffer", + "hrsh7th/cmp-path", + "hrsh7th/cmp-cmdline", + }, + }, -- }}} + config = function() + local cmp = require "cmp" + local default_mapping = { + [""] = cmp.mapping.select_prev_item(), + [""] = cmp.mapping.select_next_item(), + [""] = cmp.mapping.select_prev_item(), + [""] = cmp.mapping.select_next_item(), + [""] = cmp.mapping.scroll_docs(-4), + [""] = cmp.mapping.scroll_docs(4), + [""] = cmp.mapping.complete(), + [""] = cmp.mapping.close(), + [''] = cmp.mapping.confirm(), + [''] = cmp.mapping.abort(), + } + + require("cmp").setup({ + completion = { + completeopt = "menu,menuone,noselect", + }, + window = { + documentation = cmp.config.window.bordered(), + completion = cmp.config.window.bordered({ + winhighlight = 'Normal:CmpPmenu,CursorLine:PmenuSel,Search:None' + }), + }, + snippet = { + expand = function(args) + require("luasnip").lsp_expand(args.body) + end, + }, + formatting = { + format = require('lspkind').cmp_format({ + with_text = true, -- do not show text alongside icons + maxwidth = 50, -- prevent the popup from showing more than provided characters (e.g 50 will not show more than 50 characters) + before = function(entry, vim_item) + -- Source 显示提示来源 + vim_item.menu = '<' .. entry.source.name .. '>' + return vim_item + end + }) + }, + mapping = default_mapping, + sources = cmp.config.sources { + { name = "nvim_lsp" }, + { name = "luasnip" }, + { name = "buffer" }, + { name = "nvim_lua" }, + { name = "path" }, + }, + experimental = { + ghost_text = true, + } + }) + cmp.setup.cmdline(':', { + mapping = cmp.mapping.preset.cmdline { + [''] = cmp.config.disable, + [''] = cmp.config.disable, + [''] = cmp.mapping.abort(), + }, + sources = cmp.config.sources( + { { name = 'path' } }, + { { name = 'cmdline' } } + ) + }) + cmp.setup.cmdline({ '/', '?' }, { + mapping = cmp.mapping.preset.cmdline { + [''] = cmp.config.disable, + [''] = cmp.config.disable, + [''] = cmp.mapping.abort(), + }, + sources = { { name = 'buffer' } } + }) + + vim.opt.complete = "" + end, + }, + + -- }}} -- -- lspsaga {{{ -- { -- 'nvimdev/lspsaga.nvim', @@ -555,7 +638,6 @@ require("lazy").setup({ -- end, -- }, -- -- }}} - }) -- Install mini.nvim {{{ @@ -658,52 +740,6 @@ vim.cmd("hi BufferLineTab guibg=Gray") -- mini.icons {{{ require("mini.icons").setup({}) --}}} --- mini.statusline {{{ --- -require("mini.statusline").setup({ - content = { - active = status_config, - }, -}) -local function diagnostics_table(args) - local info = vim.b.coc_diagnostic_info - if MiniStatusline.is_truncated(args.trunc_width) or info == nil then - return {} - end - local table = {} - table.e = (info["error"] or 0) > 0 and "E" .. info["error"] or "" - table.w = (info["warning"] or 0) > 0 and "W" .. info["warning"] or "" - table.h = (info["hint"] or 0) > 0 and "H" .. info["hint"] or "" - table.i = (info["information"] or 0) > 0 and "I" .. info["information"] or "" - table.s = vim.g.coc_status - return table -end --- -function status_config() - local mode, mode_hl = MiniStatusline.section_mode({ trunc_width = 120 }) - local git = MiniStatusline.section_git({ trunc_width = 75 }) - local diagnostics = diagnostics_table({ trunc_width = 75 }) - local filename = MiniStatusline.section_filename({ trunc_width = 140 }) - local fileinfo = MiniStatusline.section_fileinfo({ trunc_width = 120 }) - local location = MiniStatusline.section_location({ trunc_width = 75 }) - -- - return MiniStatusline.combine_groups({ - { hl = mode_hl, strings = { mode } }, - { hl = "MiniStatuslineDevinfo", strings = { git, diagnostics["s"] } }, - { hl = "MiniStatuslineError", strings = { diagnostics["e"] } }, - { hl = "MiniStatuslineWarning", strings = { diagnostics["w"] } }, - { hl = "MiniStatuslineInfo", strings = { diagnostics["i"] } }, - { hl = "MiniStatuslineHint", strings = { diagnostics["h"] } }, - "%<", -- Mark general truncate point - { hl = "MiniStatuslineFilename", strings = { filename } }, - "%=", -- End left alignment - { hl = "MiniStatuslineFileinfo", strings = { fileinfo } }, - { hl = mode_hl, strings = { location } }, - }) -end - --- --- }}} -- mini.comment {{{ require("mini.comment").setup({ -- Module mappings. Use `''` (empty string) to disable one. @@ -754,17 +790,20 @@ vim.keymap.set("n", "\\m", function() end, { desc = "Minimap", buffer = bufnr }) -- }}} -- mini.visits {{{ + require("mini.visits").setup() -- vim.keymap.set("n", "li", function() -- MiniVisits.list_paths() -- end, { buffer = bufnr, desc = "" }) +-- -- }}} -- mini.surround {{{ -require("mini.surround").setup({ +require("mini.surround").setup { mappings = { - add = "s", - }, -}) + add = 'S' + } +} +vim.keymap.set('v', 's', 'S', { remap = true }) -- }}} -- mini.indentscope {{{ require("mini.indentscope").setup() @@ -798,6 +837,51 @@ end, { buffer = bufnr, desc = "Toggle hex color highlight" }) -- mini.pairs {{{ require("mini.pairs").setup() -- }}} +-- -- mini.statusline {{{ +-- -- +-- require("mini.statusline").setup({ +-- content = { +-- active = status_config, +-- }, +-- }) +-- local function diagnostics_table(args) +-- local info = vim.b.coc_diagnostic_info +-- if MiniStatusline.is_truncated(args.trunc_width) or info == nil then +-- return {} +-- end +-- local table = {} +-- table.e = (info["error"] or 0) > 0 and "E" .. info["error"] or "" +-- table.w = (info["warning"] or 0) > 0 and "W" .. info["warning"] or "" +-- table.h = (info["hint"] or 0) > 0 and "H" .. info["hint"] or "" +-- table.i = (info["information"] or 0) > 0 and "I" .. info["information"] or "" +-- table.s = vim.g.coc_status +-- return table +-- end +-- +-- function status_config() +-- local mode, mode_hl = MiniStatusline.section_mode({ trunc_width = 120 }) +-- local git = MiniStatusline.section_git({ trunc_width = 75 }) +-- local diagnostics = diagnostics_table({ trunc_width = 75 }) +-- local filename = MiniStatusline.section_filename({ trunc_width = 140 }) +-- local fileinfo = MiniStatusline.section_fileinfo({ trunc_width = 120 }) +-- local location = MiniStatusline.section_location({ trunc_width = 75 }) +-- +-- return MiniStatusline.combine_groups({ +-- { hl = mode_hl, strings = { mode } }, +-- { hl = "MiniStatuslineDevinfo", strings = { git, diagnostics["s"] } }, +-- { hl = "MiniStatuslineError", strings = { diagnostics["e"] } }, +-- { hl = "MiniStatuslineWarning", strings = { diagnostics["w"] } }, +-- { hl = "MiniStatuslineInfo", strings = { diagnostics["i"] } }, +-- { hl = "MiniStatuslineHint", strings = { diagnostics["h"] } }, +-- "%<", -- Mark general truncate point +-- { hl = "MiniStatuslineFilename", strings = { filename } }, +-- "%=", -- End left alignment +-- { hl = "MiniStatuslineFileinfo", strings = { fileinfo } }, +-- { hl = mode_hl, strings = { location } }, +-- }) +-- end +-- +-- -- }}} -- -- mini.completion {{{ -- require('mini.completion').setup() -- -- }}} @@ -878,7 +962,7 @@ require("mini.pairs").setup() -- }) -- vim.keymap.set("n", "z", ":TZAtaraxis") -- -- }}} --- bufferline {{{ +-- -- bufferline {{{ Add({ source = "akinsho/bufferline.nvim", depends = { @@ -886,8 +970,9 @@ Add({ "tiagovla/scope.nvim", }, }) -require("bufferline").setup({ +require('bufferline').setup{ options = { + numbers = 'ordinal', tab_size = 14, separator_style = { "", "" }, themable = true, @@ -898,9 +983,66 @@ require("bufferline").setup({ require("bufferline.groups").builtin.pinned:with({ icon = "󰐃" }), }, }, - }, -}) -require("scope").setup({}) + enforce_regular_tabs = false, + diagnostics = "coc", + diagnostics_update_in_insert = true, + diagnostics_indicator = function(count, level) + local icon = level:match("error") and " " or " " + return " " .. icon .. count + end, + offsets = { + { + filetype = "NvimTree", + text = "File Explorer", + highlight = "Directory", + text_align = "left" + }, + { + filetype = "coc-explorer", + text = function() + return vim.fn.getcwd() + end, + highlight = "Directory", + text_align = "left" + }, + { + filetype = 'vista', + text = function() + return vim.fn.getcwd() + end, + highlight = "Tags", + text_align = "right" + } + }, + custom_filter = function (buf_number) + local tabId = tostring(vim.fn.tabpagenr()) + if vim.g.tab_group[tabId] then + for _, p in ipairs(vim.g.tab_group[tabId]) do + if p == buf_number then + return true + end + end + end + return false + end + } +}; + +-- require("bufferline").setup({ +-- options = { +-- custom_filter = function(buf_number) +-- local tabId = vim.fn.tabpagenr() +-- if vim.g.tab_group[tabId] then +-- for _, p in ipairs(vim.g.tab_group[tabId]) do +-- if p == buf_number then +-- return true +-- end +-- end +-- end +-- return false +-- end +-- }, +-- }) -- keymaps {{{ for i = 1, 9, 1 do vim.keymap.set("n", string.format("", i), function() @@ -914,4 +1056,31 @@ vim.keymap.set("n", "", "BufferLineMovePrev", opts) vim.keymap.set("n", "", "BufferLineMoveNext", opts) vim.keymap.set("n", "", "BufferLineTogglePin", opts) -- }}} +-- -- TODO: tabpages +-- -- }}} + +-- KEYMAPS {{{ + +-- Use floating window for translation +vim.keymap.set("v", "Tz", function() + vim.cmd('norm o^zt"ty') + local translated_text = vim.fn.system("trans -t zh-TW -b", vim.fn.getreg("t")) + local lines = vim.split(translated_text, "\n") + table.remove(lines) + + local new_buf = vim.api.nvim_create_buf(false, true) + vim.api.nvim_buf_set_lines(new_buf, 0, -1, true, lines) + + vim.api.nvim_open_win(new_buf, true, { + relative = "cursor", + width = 80, + height = #lines, + row = #lines, + col = 0, + }) + + vim.cmd("setl nocul nonu nornu") + vim.cmd("hi ActiveWindow guibg=#2a5a6a guifg=White | setl winhighlight=Normal:ActiveWindow") + vim.cmd(":silent! %s/\\%x1b\\[[0-9;]*m//g") +end, { desc = "Description" }) -- }}} -- cgit v1.2.3-70-g09d2