From 7bb59cf349e3fa43e15bef4b4fc365900dae5f43 Mon Sep 17 00:00:00 2001 From: Sureshkumar Thangavel Date: Fri, 14 Jul 2023 02:36:38 +0530 Subject: [PATCH] some stuff --- dots/dot-config/nvim/copy_matches.vim | 112 ++++++++++++++++++++++++++ dots/dot-config/nvim/init.vim | 9 ++- dots/dot-config/nvim/lua/lsp.lua | 4 +- dots/dot-config/nvim/lua/utils.lua | 9 ++- dots/dot-oh-my-zshrc | 4 +- dots/dot-zshrc | 5 +- 6 files changed, 134 insertions(+), 9 deletions(-) create mode 100644 dots/dot-config/nvim/copy_matches.vim diff --git a/dots/dot-config/nvim/copy_matches.vim b/dots/dot-config/nvim/copy_matches.vim new file mode 100644 index 0000000..7346b04 --- /dev/null +++ b/dots/dot-config/nvim/copy_matches.vim @@ -0,0 +1,112 @@ +" Plugin to copy matches (search hits which may be multiline). +" Version 2012-05-03 from http://vim.wikia.com/wiki/VimTip478 +" +" :CopyMatches copy matches to clipboard (each match has newline added) +" :CopyMatches x copy matches to register x +" :CopyMatches X append matches to register x +" :CopyMatches - display matches in a scratch buffer (does not copy) +" :CopyMatches pat (after any of above options) use 'pat' as search pattern +" :CopyMatches! (with any of above options) insert line numbers +" Same options work with the :CopyLines command (which copies whole lines). + +" Jump to first scratch window visible in current tab, or create it. +" This is useful to accumulate results from successive operations. +" Global function that can be called from other scripts. +function! GoScratch() + let done = 0 + for i in range(1, winnr('$')) + execute i . 'wincmd w' + if &buftype == 'nofile' + let done = 1 + break + endif + endfor + if !done + new + setlocal buftype=nofile bufhidden=hide noswapfile + endif +endfunction + +" Append match, with line number as prefix if wanted. +function! s:Matcher(hits, match, linenums, subline) + if !empty(a:match) + let prefix = a:linenums ? printf('%3d ', a:subline) : '' + call add(a:hits, prefix . a:match) + endif + return a:match +endfunction + +" Append line numbers for lines in match to given list. +function! s:MatchLineNums(numlist, match) + let newlinecount = len(substitute(a:match, '\n\@!.', '', 'g')) + if a:match =~ "\n$" + let newlinecount -= 1 " do not copy next line after newline + endif + call extend(a:numlist, range(line('.'), line('.') + newlinecount)) + return a:match +endfunction + +" Return list of matches for given pattern in given range. +" If 'wholelines' is 1, whole lines containing a match are returned. +" This works with multiline matches. +" Work on a copy of buffer so unforeseen problems don't change it. +" Global function that can be called from other scripts. +function! GetMatches(line1, line2, pattern, wholelines, linenums) + let savelz = &lazyredraw + set lazyredraw + let lines = getline(1, line('$')) + new + setlocal buftype=nofile bufhidden=delete noswapfile + silent put =lines + 1d + let hits = [] + let sub = a:line1 . ',' . a:line2 . 's/' . escape(a:pattern, '/') + if a:wholelines + let numlist = [] " numbers of lines containing a match + let rep = '/\=s:MatchLineNums(numlist, submatch(0))/e' + else + let rep = '/\=s:Matcher(hits, submatch(0), a:linenums, line("."))/e' + endif + silent execute sub . rep . (&gdefault ? '' : 'g') + close + if a:wholelines + let last = 0 " number of last copied line, to skip duplicates + for lnum in numlist + if lnum > last + let last = lnum + let prefix = a:linenums ? printf('%3d ', lnum) : '' + call add(hits, prefix . getline(lnum)) + endif + endfor + endif + let &lazyredraw = savelz + return hits +endfunction + +" Copy search matches to a register or a scratch buffer. +" If 'wholelines' is 1, whole lines containing a match are returned. +" Works with multiline matches. Works with a range (default is whole file). +" Search pattern is given in argument, or is the last-used search pattern. +function! s:CopyMatches(bang, line1, line2, args, wholelines) + let l = matchlist(a:args, '^\%(\([a-zA-Z"*+-]\)\%($\|\s\+\)\)\?\(.*\)') + let reg = empty(l[1]) ? '+' : l[1] + let pattern = empty(l[2]) ? @/ : l[2] + let hits = GetMatches(a:line1, a:line2, pattern, a:wholelines, a:bang) + let msg = 'No non-empty matches' + if !empty(hits) + if reg == '-' + call GoScratch() + normal! G0m' + silent put =hits + " Jump to first line of hits and scroll to middle. + ''+1normal! zz + else + execute 'let @' . reg . ' = join(hits, "\n") . "\n"' + endif + let msg = 'Number of matches: ' . len(hits) + endif + redraw " so message is seen + echo msg +endfunction +command! -bang -nargs=? -range=% CopyMatches call s:CopyMatches(0, , , , 0) +command! -bang -nargs=? -range=% CopyLines call s:CopyMatches(0, , , , 1) diff --git a/dots/dot-config/nvim/init.vim b/dots/dot-config/nvim/init.vim index 5e3b2e5..2d529f8 100755 --- a/dots/dot-config/nvim/init.vim +++ b/dots/dot-config/nvim/init.vim @@ -26,7 +26,7 @@ Plug 'dense-analysis/ale' Plug 'jose-elias-alvarez/null-ls.nvim' Plug 'lukas-reineke/indent-blankline.nvim' Plug 'nvim-lua/plenary.nvim' -Plug 'nvim-telescope/telescope.nvim', { 'tag': '0.1.1' } +Plug 'nvim-telescope/telescope.nvim', { 'tag': '0.1.2' } Plug 'neovim/nvim-lspconfig' Plug 'williamboman/mason.nvim' Plug 'williamboman/mason-lspconfig.nvim' @@ -39,7 +39,7 @@ Plug 'nvim-treesitter/nvim-treesitter-textobjects' Plug 'lewis6991/gitsigns.nvim' Plug 'epwalsh/obsidian.nvim' Plug 'junegunn/vim-easy-align' -Plug 'preservim/nerdtree' +Plug 'scrooloose/nerdtree' Plug 'github/copilot.vim' if has('nvim') @@ -53,6 +53,7 @@ endif Plug 'Shougo/neosnippet.vim' Plug 'Shougo/neosnippet-snippets' +Plug 'iamcco/markdown-preview.nvim', { 'do': 'cd app && yarn install' } Plug 'lervag/vimtex' " golang @@ -340,7 +341,9 @@ require("lsp") require("completion") require("treesitter") require("nullls") ---require("metals_config") +require("metals_config") +require("copilot-config") + require("telescope_config") require("copilot-config") require("latex") diff --git a/dots/dot-config/nvim/lua/lsp.lua b/dots/dot-config/nvim/lua/lsp.lua index 8333657..1f03212 100644 --- a/dots/dot-config/nvim/lua/lsp.lua +++ b/dots/dot-config/nvim/lua/lsp.lua @@ -28,7 +28,7 @@ capabilities = require('cmp_nvim_lsp').default_capabilities(capabilities) require('mason').setup() -local servers = { 'pyright', 'tsserver', 'lua-language-servers' } +local servers = { 'pyright', 'tsserver', 'lua_ls', 'yaml-language-server' } require('mason-lspconfig').setup { ensure_installed = servers, @@ -46,7 +46,7 @@ local runtime_path = vim.split(package.path, ';') table.insert(runtime_path, 'lua/?.lua') table.insert(runtime_path, 'lua/?/init.lua') -require('lspconfig').lua.setup { +require('lspconfig').lua_ls.setup { on_attach = on_attach, capabilities = capabilities, settings = { diff --git a/dots/dot-config/nvim/lua/utils.lua b/dots/dot-config/nvim/lua/utils.lua index 6c8aa11..1a90744 100644 --- a/dots/dot-config/nvim/lua/utils.lua +++ b/dots/dot-config/nvim/lua/utils.lua @@ -77,4 +77,11 @@ local function switch_case() end end -return { switch_case = switch_case } +local function ConvertToSnakeCase() + local word = vim.fn.expand("") -- Get the current word under the cursor + local snake_case_word = string.gsub(word, "(%w)(%u)", "%1_%2") -- Convert to snake case with underscores + vim.cmd("normal! viw\"sy") -- Yank the converted word to the "s" register + vim.cmd("normal! viwp") -- Replace the word with the converted version +end + +return { switch_case = switch_case, ConvertToSnakeCase = ConvertToSnakeCase } diff --git a/dots/dot-oh-my-zshrc b/dots/dot-oh-my-zshrc index 6b94b7d..cb8b226 100644 --- a/dots/dot-oh-my-zshrc +++ b/dots/dot-oh-my-zshrc @@ -85,10 +85,10 @@ ZSH_THEME="robbyrussell" # Custom plugins may be added to ~/.oh-my-zsh/custom/plugins/ # Example format: plugins=(rails git textmate ruby lighthouse) # Add wisely, as too many plugins slow down shell startup. +# git +# git-extras plugins+=( git - git-extras - git-flow cabal docker encode64 diff --git a/dots/dot-zshrc b/dots/dot-zshrc index d23c4c3..942c4fc 100644 --- a/dots/dot-zshrc +++ b/dots/dot-zshrc @@ -57,7 +57,6 @@ fi unset __conda_setup # <<< conda initialize <<< -conda deactivate || : export PATH="/usr/local/opt/ruby/bin:$PATH" export LDFLAGS="-L/usr/local/opt/ruby/lib" export CPPFLAGS="-I/usr/local/opt/ruby/include" @@ -162,3 +161,7 @@ if [ -f '/Users/tsureshkumar/bin/google-cloud-sdk/path.zsh.inc' ]; then . '/User # The next line enables shell command completion for gcloud. if [ -f '/Users/tsureshkumar/bin/google-cloud-sdk/completion.zsh.inc' ]; then . '/Users/tsureshkumar/bin/google-cloud-sdk/completion.zsh.inc'; fi + +test -f ~/.zshrc-office && source ~/.zshrc-office + +export PATH="/opt/homebrew/opt/node@16/bin:$PATH"