From b57c461014f585655d897abf0e0ac982807396b7 Mon Sep 17 00:00:00 2001 From: Hsieh Chin Fan Date: Mon, 5 Aug 2024 18:41:51 +0800 Subject: Update --- vim/init/basic.vim | 35 ++++++--- vim/init/config.vim | 24 +++--- vim/init/keymaps.vim | 71 ++++++++--------- vim/mini.lua | 212 ++++++++++++++++++++++++++++++++------------------- 4 files changed, 208 insertions(+), 134 deletions(-) (limited to 'vim') diff --git a/vim/init/basic.vim b/vim/init/basic.vim index c4dfa61..fd20476 100644 --- a/vim/init/basic.vim +++ b/vim/init/basic.vim @@ -4,6 +4,17 @@ " Used for general usecases. No keymap and personal preference "====================================================================== +" Initial for terminal emulator {{{ +augroup Enter + au! + function! SetEmulaterBackground() + redir => output | hi Normal | redir END + let bg_color = matchstr(output, 'guibg=\zs[^\s]\+\ze') + exe "!alacritty msg config 'colors.primary.background=\"\\"..bg_color.."\"'" + endfunc + autocmd VimEnter * call SetEmulaterBackground() +augroup END +"}}} " For Vimscript {{{ " Usage: type --- for foldmark @@ -27,7 +38,9 @@ augroup tabinfo endfunc function! RemoveBufFromTabs() for tab in gettabinfo() - call filter(tab.variables.bufs, "v:val != "..expand('')) + if has_key(t:, 'bufs') + call filter(tab.variables.bufs, "v:val != "..expand('')) + endif endfor endfunc @@ -78,7 +91,7 @@ set showtabline=2 set number relativenumber " Cursor -set cursorline +" set cursorline set guicursor=n-v-c-sm:block,i-ci-ve:ver25,r-cr-o:hor20 set matchtime=2 @@ -95,7 +108,7 @@ set errorformat+=[%f:%l]\ ->\ %m,[%f:%l]:%m set splitright " Set signcolumn -set signcolumn=auto:3 +set signcolumn=yes:3 " Custom sign from help page :h sign sign define piet text=>> texthl=Search @@ -107,7 +120,7 @@ sign define piet text=>> texthl=Search " 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 +autocmd Filetype * set formatoptions+=mB formatoptions-=cro set shiftwidth=2 set autoindent smartindent @@ -140,10 +153,9 @@ set suffixesadd=.md " Enable reference markdown file without " }}} " SEARCH {{{ -set ignorecase " Search case without case sensation -set smartcase -set hlsearch " Highlight all matched texts -set incsearch " Show matched strings when typing +set ignorecase smartcase " Search case without case sensation +set hlsearch " Highlight all matched texts +set incsearch " Show matched strings when typing " }}} " BUFFERS {{{ @@ -209,16 +221,17 @@ set writebackup " HIGHLIGHT {{{ syntax enable -set conceallevel=1 +set syntax=filetype +set conceallevel=2 " Defualt highlight for matched parenthesis is so weird in many colorscheme " Why the background color is lighter than my caret !? " highlight MatchParen ctermfg=NONE ctermbg=darkgrey cterm=NONE -highlight LuaParen ctermfg=NONE ctermbg=darkgrey cterm=NONE +hi LuaParen ctermfg=NONE ctermbg=darkgrey cterm=NONE " Show trailing spaces -highlight ExtraWhitespace ctermbg=red guibg=red match ExtraWhitespace /\s\+$/ +hi ExtraWhitespace ctermbg=red guibg=red " }}} " MISC {{{ diff --git a/vim/init/config.vim b/vim/init/config.vim index 318bc58..3870ac4 100644 --- a/vim/init/config.vim +++ b/vim/init/config.vim @@ -20,7 +20,7 @@ augroup TerminalSize if &lines < a:bound || g:alacritty_extra_padding silent! set laststatus=0 showtabline=0 signcolumn=0 nowrap scrolloff=1 else - silent! set laststatus& showtabline& signcolumn& scrolloff& + silent! set laststatus& showtabline=2 signcolumn& scrolloff& endif endfunc autocmd VimEnter,VimResized * silent call LayoutForSmallTerminal(20) @@ -147,17 +147,23 @@ augroup InitFileTypes augroup Config_Markdown au! - au FileType markdown call InitMarkdown() - au FileType markdown let b:in_frontmatter = 0 - function! InitMarkdown() + au FileType markdown call InitMarkdownFile() + function! InitMarkdownFile() setlocal wrap sw=2 ts=2 + + let b:in_frontmatter = 0 setlocal foldexpr=MarkdownLevel() foldmethod=expr setlocal foldtext=MarkdownFoldTextHeading() - syn match Details '^
' conceal cchar=▶ - syn match Summary '' conceal cchar= - syn match SummaryEnd '' conceal - syn match DetailsEnd '^
' conceal cchar=E + + call MarkdownHighlights() + endfunc + + function MarkdownHighlights() + syn match MarkdownHtmlDetails '^
' conceal cchar=▶ + syn match MarkdownHtmlSummary '' conceal cchar= + syn match MarkdownHtmlSummaryEnd '' conceal + syn match MarkdownHtmlDetailsEnd '^
' conceal cchar=E endfunc function! MarkdownLevel() @@ -196,7 +202,7 @@ augroup InitFileTypes let origin = split(MarkdownFoldText()[2:], ' ') let heading = substitute(join(origin[:-3], ' '), '\#', ' ', 'g') let lines = join(origin[-2:], ' ')[1:-2] - let fills = repeat('.', 48 - len(heading) - len(lines)) + let fills = repeat('.', 48 - strwidth(heading) - len(lines)) return heading.." "..fills.." "..lines endfunc diff --git a/vim/init/keymaps.vim b/vim/init/keymaps.vim index a423c20..e8cb61d 100644 --- a/vim/init/keymaps.vim +++ b/vim/init/keymaps.vim @@ -3,7 +3,7 @@ "====================================================================== " vim: sw=2 ts=2 foldmethod=marker foldmarker={{{,}}} -" COMMON_MAPPING {{{ +" COMMON {{{ " Space for searching map / @@ -37,9 +37,7 @@ augroup vimrc_CRfix augroup END " Spell -nnoremap \s :set spell!:set spell? -nnoremap ss ]s -nnoremap S [s +nnoremap \sp :set spell!:set spell? " Show full path by default nnoremap 1 @@ -48,6 +46,8 @@ nnoremap 1 vnoremap Tz :!trans -t zh-TW -b vnoremap Te :!trans -t en-US -b +nnoremap q: : + " }}} " WORKING_DIR {{{ @@ -157,6 +157,16 @@ inoremap :tablast " }}} +" }}} +" EDIT {{{ + +" Move one line up and down +nnoremap ddp +nnoremap ddkP + +" Clear current line +nnoremap S S + " }}} " REGISTER {{{ " Paste register 0 @@ -176,7 +186,7 @@ vnoremap Y "+y function! DeleteMark(mark) let mark = nr2char(a:mark) echo mark - if mark =~ '[a-Z]' + if mark =~ '\a' execute "delmarks " . mark endif endfunc @@ -259,7 +269,7 @@ function! ChangeUnfold(downward, count) let foldend -= move endif norm! zd - exe foldstart..","..foldend.."fold" + try | silent! exe foldstart..","..foldend.."fold" | endtry " Get back to origin cursor position norm! '' @@ -268,16 +278,6 @@ nnoremap z> ":\call ChangeUnfold(1,"..v:count..")\" nnoremap z< ":\call ChangeUnfold(0,"..v:count..")\" "}}} -" EDIT {{{ - -" Move one line up and down -nnoremap ddp -nnoremap ddkP - -" Clear current line -nnoremap S S - -" }}} " TERMINAL {{{ " Use z to toggle @@ -285,13 +285,17 @@ let g:alacritty_extra_padding = 0 function! ToggleWinPadding() if g:alacritty_extra_padding !alacritty msg config --window-id $WINDOWID --reset + call SetEmulaterBackground() hi EndOfBuffer None hi MsgArea None else redir => output | hi LineNr | redir END let bg_color = matchstr(output, 'guibg=\zs[^\s]\+\ze') - exe "hi EndOfBuffer guifg="..bg_color.." guibg="..bg_color - exe "hi MsgArea guibg="..bg_color + + try + exe "hi EndOfBuffer guifg="..bg_color.." guibg="..bg_color + exe "hi MsgArea guibg="..bg_color + endtry exe "!alacritty msg config --window-id $WINDOWID window.padding.x=300 'colors.primary.background=\"\\"..bg_color.."\"'" endif @@ -380,24 +384,16 @@ function! CloseBufferSafely() if answer == "" | return | endif endif - let l:bufnr = bufnr() - + let bufnr = bufnr() if len(t:bufs) == 1 " Close tab for last buffer tabclose else " Switch to proper buffer - let l:next_buf = get(t:bufs, bufnr('#')) ? bufnr('#') : filter(t:bufs, 'v:val != '..l:bufnr)[0] - exe "b "..l:next_buf - call filter(t:bufs, 'v:val != '..l:bufnr) + let next_buf = get(t:bufs, bufnr('#')) ? bufnr('#') : filter(t:bufs, 'v:val != '..bufnr)[0] + exe "b "..next_buf + call filter(t:bufs, 'v:val != '..bufnr) endif - - " Delete buffer if every t:buf doesn't have it - for tab in gettabinfo() - if get(tab.variables.bufs, l:bufnr) | return | endif - endfor - exe "bd! "..l:bufnr - endfunction function! Bye() let windows = gettabinfo(tabpagenr())[0]['windows'] @@ -493,10 +489,10 @@ endif " MANAGE_TABS {{{ " Useful mappings for managing tabs -map tn :tabnew -map tc :tabclose -map tm :tabmove -map to :tabonly +nnoremap tn :tabnew +nnoremap tc :tabclose +nnoremap tm :tabmove +nnoremap to :tabonly nnoremap :call Tab_MoveLeft() nnoremap :call Tab_MoveRight() @@ -508,7 +504,7 @@ autocmd TabLeave * let g:lasttab = tabpagenr() " Opens a new tab with the current buffer's path " Super useful when editing files in the same directory -map te :tabedit =expand("%:p:h") +nnoremap te :tabedit =expand("%:p:h") " Tab move functions function! Tvab_MoveLeft() @@ -598,6 +594,11 @@ endfunction " }}} " HIGHLIGHT {{{ +nnoremap \sy exists("g:syntax_on") ? ":syntax off " : ":syntax enable" + +" Toggle conceallevel0/2 +nnoremap \c ":set conceallevel="..(&cole ? 0 : 2)..":set cole?" + " Disable highlight when is pressed nnoremap :noh diff --git a/vim/mini.lua b/vim/mini.lua index 1b5507d..8a19d63 100644 --- a/vim/mini.lua +++ b/vim/mini.lua @@ -325,20 +325,30 @@ require("mini.pairs").setup() -- -- suda {{{ -- add { source = "lambdalisue/suda.vim" } -- }}} --- -- true-zen {{{ --- Add({ --- source = "Pocco81/true-zen.nvim", --- }) --- vim.keymap.set("n", "z", ":TZAtaraxis") --- -- }}} -- marks.nvim {{{ Add { source = "chentoast/marks.nvim" } require('marks').setup { + bookmark_0 = { + sign = "⚑", + virt_text = "hello world", + -- explicitly prompt for a virtual line annotation when setting a bookmark from this group. + -- defaults to false. + annotate = false, + }, } vim.cmd("hi MarkSignHL gui=bold guifg=#f85e84 guibg=#37343a") -- }}} +-- highlight-match-under-cursor {{{ +Add { + source = "adamheins/vim-highlight-match-under-cursor" +} +-- }}} +Add { + source ='shime/vim-livedown' +} + -- Install Lazy {{{ -- Bootstrap lazy.nvim @@ -513,7 +523,9 @@ require("lazy").setup({ end, config = function() require('lualine').setup(opts) - vim.cmd('set laststatus=0') + if vim.o.lines < 20 then + vim.o.laststatus=0 + end end }, -- }}} @@ -826,7 +838,7 @@ require("lazy").setup({ persist_size = false, direction = "float", }) - -- + vim.keymap.set({ "n", "t" }, "", function() vim.cmd("ToggleTerm direction=float") end, { desc = "terminal toggle floating term" }) @@ -836,6 +848,10 @@ require("lazy").setup({ vim.keymap.set({ "n", "t" }, "", function() vim.cmd("ToggleTerm direction=horizontal") end, { desc = "terminal toggle floating term" }) + vim.keymap.set("v", ",s", function() + require("toggleterm").send_lines_to_terminal("single_line", trim_spaces, { args = vim.v.count }) + vim.cmd("ToggleTerm direction=float") + end) end, }, --}}} @@ -945,68 +961,89 @@ require("lazy").setup({ end, }, -- }}} - - -- -- lspconfig {{{ - -- -- Use :help lspconfig-all to check servers + -- -- markview.nvim {{{ -- { - -- "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", + -- "OXY2DEV/markview.nvim", + -- enable = false, + -- ft = "markdown", + -- -- dependencies = { - -- "williamboman/mason-lspconfig.nvim", + -- -- You may not need this if you don't lazy load + -- -- Or if the parsers are in your $RUNTIMEPATH + -- "nvim-treesitter/nvim-treesitter", + -- + -- "nvim-tree/nvim-web-devicons" -- }, - -- 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, - -- }, - -- -- }}} + -- },-- }}} + + -- 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 = { "markdown", "markdown_inline", "lua", "luadoc", "printf", "vim", "vimdoc" }, + + highlight = { + enable = true, + use_languagetree = true, + additional_vim_regex_highlighting = true, + }, + + indent = { enable = true }, + }) + vim.cmd([[ + syn match MarkdownHtmlDetails '^
' conceal cchar=▶ + syn match MarkdownHtmlSummary '' conceal cchar= + syn match MarkdownHtmlSummaryEnd '' conceal + syn match MarkdownHtmlDetailsEnd '^
' conceal cchar=E + ]]) + end, + }, + -- }}} -- nvim-cmp {{{ { "hrsh7th/nvim-cmp", @@ -1133,18 +1170,35 @@ require("lazy").setup({ }, -- }}} - -- -- lspsaga {{{ - -- { - -- 'nvimdev/lspsaga.nvim', - -- dependencies = { - -- 'nvim-treesitter/nvim-treesitter', -- optional - -- 'nvim-tree/nvim-web-devicons', -- optional - -- }, - -- config = function() - -- require('lspsaga').setup({}) - -- end, - -- }, - -- -- }}} + -- lspsaga {{{ + { + 'nvimdev/lspsaga.nvim', + dependencies = { + 'nvim-treesitter/nvim-treesitter', -- optional + 'nvim-tree/nvim-web-devicons', -- optional + }, + config = function() + require('lspsaga').setup({ + autochdir = true, + }) + vim.api.nvim_create_autocmd("LspAttach", { + group = custom_autocommands, + pattern = "*", + callback = function(args) + local map = vim.api.nvim_buf_set_keymap + map(0, "n", "gd", "Lspsaga goto_definition", {silent = true, noremap = true}) + map(0, "n", "gr", "Lspsaga rename", {silent = true, noremap = true}) + map(0, "n", "gx", "Lspsaga code_action", {silent = true, noremap = true}) + map(0, "x", "gx", ":Lspsaga range_code_action", {silent = true, noremap = true}) + map(0, "n", "K", "Lspsaga hover_doc", {silent = true, noremap = true}) + map(0, "n", "go", "Lspsaga show_line_diagnostics", {silent = true, noremap = true}) + map(0, "n", "gj", "Lspsaga diagnostic_jump_next", {silent = true, noremap = true}) + map(0, "n", "gk", "Lspsaga diagnostic_jump_prev", {silent = true, noremap = true}) + end, + }) + end + }, + -- }}} -- -- conform {{{ -- { -- "stevearc/conform.nvim", -- cgit v1.2.3-70-g09d2