From 33626be5de9f0b8e29bc6a88751e08a0435f4cda Mon Sep 17 00:00:00 2001 From: Prashantha T P Date: Sun, 21 Nov 2021 19:07:59 +0530 Subject: [PATCH 01/50] Feat(nvim): add lua config for neovim note: set to C:\Users\Prashanth T P/.config/nvim/init.lua --- .config/nvim/init.lua | 37 +++++++ .config/nvim/lua/autoload/cursor.lua | 25 +++++ .config/nvim/lua/general/init.lua | 4 + .config/nvim/lua/general/keymappings.lua | 57 +++++++++++ .config/nvim/lua/general/languages.lua | 0 .config/nvim/lua/general/leader.lua | 26 +++++ .config/nvim/lua/general/settings.lua | 118 +++++++++++++++++++++++ 7 files changed, 267 insertions(+) create mode 100644 .config/nvim/init.lua create mode 100644 .config/nvim/lua/autoload/cursor.lua create mode 100644 .config/nvim/lua/general/init.lua create mode 100644 .config/nvim/lua/general/keymappings.lua create mode 100644 .config/nvim/lua/general/languages.lua create mode 100644 .config/nvim/lua/general/leader.lua create mode 100644 .config/nvim/lua/general/settings.lua diff --git a/.config/nvim/init.lua b/.config/nvim/init.lua new file mode 100644 index 0000000..51ceb12 --- /dev/null +++ b/.config/nvim/init.lua @@ -0,0 +1,37 @@ +-- +--------------------------------------------------------------------------+ +-- | | +-- | NEOVIM CONFIG | +-- | | +-- +--------------------------------------------------------------------------+ +-------------------------------------------------------------------------------- +--[[ + +lua ++---autoload +| cursor.lua +| ++---general +| init.lua +| keymappings.lua +| languages.lua +| leader.lua +| settings.lua +| +\---plugins + lsp.lua + +]]-- +-------------------------------------------------------------------------------- +--add init.lua's directory to runtime path +--https://github.com/LunarVim/LunarVim/blob/109c766809760f7a9aba5dfb467d8299d2996de0/init.lua#L1-L6 + +local init_path = debug.getinfo(1, "S").source:sub(2) -- ~.config/nvim/init.lua +local base_dir = init_path:match("(.*[/\\])"):sub(1, -2) --~.config/nvim + +--add init.lua's directory to runtime path +if not vim.tbl_contains(vim.opt.rtp:get(), base_dir) then + vim.opt.rtp:append(base_dir) +end + +-------------------------------------------------------------------------------- +require('general.init') diff --git a/.config/nvim/lua/autoload/cursor.lua b/.config/nvim/lua/autoload/cursor.lua new file mode 100644 index 0000000..d79bf25 --- /dev/null +++ b/.config/nvim/lua/autoload/cursor.lua @@ -0,0 +1,25 @@ +vim.cmd([[ + +" cursor ----- {{{ +" Cursor in terminal +" https//vim.fandom.com/wiki/Configuring_the_cursor +" 1 or 0 -> blinking block +" 2 solid block +" 3 -> blinking underscore +" 4 solid underscore +" Recent versions of xterm (282 or above) also support +" 5 -> blinking vertical bar +" 6 -> solid vertical bar +if &term =~ '^xterm' + " normal mode || + " .= means shorthand for appending : see help .= + let &t_EI .= "\[1 q" + " replace mode _ + let &t_SR .= "\e[4 q" + " insert mode | + let &t_SI .= "\[6 q" +endif +" +" }}} + +]]) diff --git a/.config/nvim/lua/general/init.lua b/.config/nvim/lua/general/init.lua new file mode 100644 index 0000000..91d2550 --- /dev/null +++ b/.config/nvim/lua/general/init.lua @@ -0,0 +1,4 @@ +require('general.settings') +require('general.leader') +require('general.keymappings') + diff --git a/.config/nvim/lua/general/keymappings.lua b/.config/nvim/lua/general/keymappings.lua new file mode 100644 index 0000000..5061ba3 --- /dev/null +++ b/.config/nvim/lua/general/keymappings.lua @@ -0,0 +1,57 @@ +vim.cmd([[ +" MODES ----- {{{ +"use jk in insert mode to switch to normal mode +inoremap jk +" }}} + +" yanking ----- {{{ +"to match the behaviour of 'C' and 'D' +nnoremap Y y$ +"replace with yanked word +"https://vim.fandom.com/wiki/Replace_a_word_with_yanked_text +nnoremap S "_diwP +vnoremap S "_d"0P +"highlight the yanked area for an extened period +augroup highlight_yank + autocmd! + au TextYankPost * silent! lua vim.highlight.on_yank{higroup="IncSearch", timeout=300} +augroup END +" }}} + +" searching : the primeagen : top 5 keybindings ----- {{{ +"put the cursor at screen center while going to next search result +nnoremap n nzz +nnoremap N Nzz + +" }}} +" +" breakpoints ----- {{{ +"puts the next line at the end of current line : mz = create a mark called z , do J, `z = goto mark z +nnoremap J mzJ`z +"undo breakpoints +inoremap . .u +inoremap , ,u +inoremap ! !u +inoremap ? ?u +" }}} +" +" moving lines with ALT key ----- {{{ +"https://vim.fandom.com/wiki/Moving_lines_up_or_down +nnoremap :m .+1== +nnoremap :m .-2== +inoremap :m .+1==gi +inoremap :m .-2==gi +vnoremap :m '>+1gv=gv +vnoremap :m '<-2gv=gv +" }}} + +"htmlhttps://stackoverflow.com/questions/130734/how-can-one-close-html-tags-in-vim-quickly +"inoremap > >Fo">O + +" better indentation ----- {{{ +vnoremap > >gv +vnoremap < vs :source $MYVIMRC +nmap vo :e $MYVIMRC +" nmap so :vsplit :e $LOCALAPPDATA/nvim/init.vim +nnoremap n :bnext +nnoremap p :bprev +nnoremap b :buffers + +" splits ----- {{{ +"nnoremap w w "removed to support vimwiki +nnoremap h h +nnoremap l l +nnoremap j j +nnoremap k k +" +nnoremap r= = +nnoremap = :exe "resize " . (winheight(0) * 3/2) +nnoremap - :exe "resize " . (winheight(0) * 2/3) +nnoremap 0 :exe "vertical resize " . (winwidth(0) * 3/2) +nnoremap 9 :exe "vertical resize " . (winwidth(0) * 2/3) +" }}} +]] +) diff --git a/.config/nvim/lua/general/settings.lua b/.config/nvim/lua/general/settings.lua new file mode 100644 index 0000000..4a74e0a --- /dev/null +++ b/.config/nvim/lua/general/settings.lua @@ -0,0 +1,118 @@ +vim.cmd( [[ + +"General Settings +set mouse=a +" CLIPBOARD ----- {{{ +"vim clipboard and system clipboard same now +set clipboard^=unnamed +"wrap backspace +set backspace=indent,eol,start +"https://stackoverflow.com/a/53872985/12988588 +"dont save character deleted using `x` +"send it to The blackhole-register +nnoremap x "_x +"set autochdir +" }}} + +" EDITOR ----- {{{ +syntax on +set conceallevel=0 + +" filetype on +" filetype plugin on +" filetype indent on +set ignorecase +set smartcase +" use 4 spaces for tabs +set tabstop=4 +set softtabstop=4 +set shiftwidth=4 +set number +set scrolloff=8 +set showtabline=2 +set lazyredraw +"set colorcolumn=80 +" Show white spaces https://gist.github.com/jdavid82/d40f40e6f124aad6223eba0ff0c7ad65#file-vimrc-L37-L39 +"set listchars=tab:>·,trail:~,extends:>,precedes:<,space:· +"set list +" }}} + +" SEARCHING ----- {{{ +set incsearch "on by default" +set nohlsearch +" clear last used search pattern:http://vimdoc.sourceforge.net/htmldoc/pattern.html#last-pattern +" +let @/="" +" }}} + +" FOLDING ----- {{{ +" use pattern {{{ #code# }}} to detect fold region +" use zm to fold all markers and zr to release all folds with markers +set foldmethod=marker +" }}} + +" BUFFERS ----- {{{ +" remember foldings is nvim/general/augroups.vim +" }}} + +" SPLITS ----- {{{ +set splitbelow +set splitright +nnoremap +nnoremap +nnoremap +nnoremap + +"}}} + +" Nice menu like when typing `:find *.py` ---{{{ +set wildmode=longest,list,full +set wildmenu +" Ignore files +set wildignore+=*.pyc +set wildignore+=*_build/* +set wildignore+=**/coverage/* +set wildignore+=**/node_modules/* +set wildignore+=**/android/* +set wildignore+=**/ios/* +set wildignore+=**/.git/* +" }}} + +" misc----- {{{ +" Set internal encoding of vim, not needed on neovim, since coc.nvim using some +" unicode characters in the file autoload/float.vim +set encoding=utf-8 + +" TextEdit might fail if hidden is not set. +set hidden + +" Some servers have issues with backup files, see #649. +set nobackup +set nowritebackup + +" Give more space for displaying messages. +set cmdheight=2 + +" Having longer updatetime (default is 4000 ms = 4 s) leads to noticeable +" delays and poor user experience. +set updatetime=300 +set ttimeoutlen=0 +" Don't pass messages to |ins-completion-menu|. +set shortmess+=c +" }}} + +" tabline ---{{{ +" " show tabline +" set showtabline=2 +" if has('gui_running') + " set guioptions-=e +" endif +" +"---}}} + +" +let g:netrw_cursor=0 " to use userdefined CursorLine and ColorColumn +let g:netrw_winsize=30 + +]] +) From b5ba85a3a68c1c94a2e28accc1b4836c93ff96d5 Mon Sep 17 00:00:00 2001 From: Prashantha T P Date: Sun, 21 Nov 2021 21:30:30 +0530 Subject: [PATCH 02/50] Feat(nvim): add fzf helper functions --- AppData/Local/nvim/plugs/fzf.vim | 59 +++++++++++++++++++++++++++++--- 1 file changed, 54 insertions(+), 5 deletions(-) diff --git a/AppData/Local/nvim/plugs/fzf.vim b/AppData/Local/nvim/plugs/fzf.vim index eff8c2e..b8ac91a 100644 --- a/AppData/Local/nvim/plugs/fzf.vim +++ b/AppData/Local/nvim/plugs/fzf.vim @@ -1,10 +1,13 @@ " fzf ----- {{{ +"https://github.com/junegunn/fzf.vim#example-customizing-files-command " put search prompt at the top - let $FZF_DEFAULT_OPTS ='--reverse' - nnoremap fg :GFiles - nnoremap ff :Files - nnoremap fb :Buffers -let g:fzf_preview_window = [] +let $FZF_DEFAULT_COMMAND="rg --files --hidden --follow --no-ignore-vcs --glob \!{.git,.svn,.hg} --glob \!node_modules" +let $FZF_DEFAULT_OPTS='--ansi --reverse --bind ctrl-a:select-all --preview="bat --color=always {1}"' +set grepprg=rg\ --vimgrep\ --smart-case\ --hidden\ --follow\ --ignore-vcs + +command! -bang -nargs=? -complete=dir Files + \ call fzf#vim#files(, {'options': ['--layout=reverse', '--preview', 'bat --color=always {1}']}, 0) +"let g:fzf_preview_window = [] " let g:fzf_action = { " \ 'ctrl-t': 'tab split', " \ 'ctrl-s': 'split', @@ -12,4 +15,50 @@ let g:fzf_preview_window = [] " \} " }}} +" CTRL-A CTRL-Q to select all and build quickfix list + +function! s:build_quickfix_list(lines) + call setqflist(map(copy(a:lines), '{ "filename": v:val }')) + copen + cc +endfunction + +let g:fzf_action = { + \ 'ctrl-q': function('s:build_quickfix_list'), + \ 'ctrl-t': 'tab split', + \ 'ctrl-x': 'split', + \ 'ctrl-v': 'vsplit' } + +function! s:format_qf_line(line) + let parts = split(a:line, ':') + return { 'filename': parts[0] + \,'lnum': parts[1] + \,'col': parts[2] + \,'text': join(parts[3:], ':') + \ } +endfunction +function! s:qf_to_fzf(key, line) abort + let l:filepath = expand('#' . a:line.bufnr . ':p') + return l:filepath . ':' . a:line.lnum . ':' . a:line.col . ':' . a:line.text +endfunction + +function! s:fzf_to_qf(filtered_list) abort + let list = map(a:filtered_list, 's:format_qf_line(v:val)') + if len(list) > 0 + call setqflist(list) + copen + endif +endfunction + +command! FzfQF call fzf#run({ + \ 'source': map(getqflist(), function('qf_to_fzf')), + \ 'down': '20', + \ 'sink*': function('fzf_to_qf'), + \ 'options': '--reverse --multi --bind=ctrl-a:select-all,ctrl-d:deselect-all --prompt "quickfix> "', + \ }) + + nnoremap fg :GFiles + nnoremap ff :Files + nnoremap fb :Buffers + nnoremap fq :FzfQF From 92ba13ca5ad09bb2e85fe716b8031ce878b0fb64 Mon Sep 17 00:00:00 2001 From: Prashantha T P Date: Sun, 21 Nov 2021 21:31:43 +0530 Subject: [PATCH 03/50] Exp(nvim): use fzy for buffer switching --- AppData/Local/nvim/helpers/commands.vim | 25 +++++++++++++++++++++++++ 1 file changed, 25 insertions(+) diff --git a/AppData/Local/nvim/helpers/commands.vim b/AppData/Local/nvim/helpers/commands.vim index 4631fdc..14c2dcb 100644 --- a/AppData/Local/nvim/helpers/commands.vim +++ b/AppData/Local/nvim/helpers/commands.vim @@ -24,3 +24,28 @@ augroup PANDOC command! Pandoc :call MD2PDF() augroup end + +" Run a given vim command on the results of fuzzy selecting from a given shell +" command. See usage below. +function! FzyCommand(choice_command, vim_command) + try + let output = system(a:choice_command . " | fzy ") + catch /Vim:Interrupt/ + " Swallow errors from ^C, allow redraw! below + endtry + redraw! + if v:shell_error == 0 && !empty(output) + exec a:vim_command . ' ' . output + endif +endfunction + +function! SelectaBuffer() + let bufnrs = filter(range(1, bufnr("$")), 'buflisted(v:val)') + let buffers = map(bufnrs, 'bufname(v:val)') + call FzyCommand('echo "' . join(buffers, "\n") . '"', ":b") +endfunction + +if !has('nvim') + " Fuzzy select a buffer. Open the selected buffer with :b. + nnoremap b :call SelectaBuffer() +endif From c3415dd8cac473718a06edeef3e463e4c1b3e619 Mon Sep 17 00:00:00 2001 From: Prashantha T P Date: Sun, 21 Nov 2021 21:57:07 +0530 Subject: [PATCH 04/50] Chore,Exp(nvim): experiment with settings --- .../nvim/general/colorscheme_settings.vim | 2 +- AppData/Local/nvim/general/general.vim | 2 +- AppData/Local/nvim/plugs/ale.vim | 10 ++--- AppData/Local/nvim/plugs/lightline_v1.vim | 2 +- AppData/Local/nvim/plugs/plugins.vim | 8 ++-- AppData/Local/nvim/plugs/telescope_plug.vim | 38 ++++++++++++++++++- 6 files changed, 48 insertions(+), 14 deletions(-) diff --git a/AppData/Local/nvim/general/colorscheme_settings.vim b/AppData/Local/nvim/general/colorscheme_settings.vim index 2e2b4ab..32b2c2f 100644 --- a/AppData/Local/nvim/general/colorscheme_settings.vim +++ b/AppData/Local/nvim/general/colorscheme_settings.vim @@ -41,7 +41,7 @@ let g:gruvbox_contrast_dark="hard" let g:gruvbox_bold=1 let g:gruvbox_italic=1 -colorscheme gruvbox +colorscheme gruvbox-material "endif " }}} diff --git a/AppData/Local/nvim/general/general.vim b/AppData/Local/nvim/general/general.vim index 41d4e01..3ccccdd 100644 --- a/AppData/Local/nvim/general/general.vim +++ b/AppData/Local/nvim/general/general.vim @@ -26,7 +26,7 @@ set smartcase set tabstop=4 set softtabstop=4 set shiftwidth=4 -set number relativenumber +set number set scrolloff=8 set showtabline=2 set lazyredraw diff --git a/AppData/Local/nvim/plugs/ale.vim b/AppData/Local/nvim/plugs/ale.vim index d819226..44190c7 100644 --- a/AppData/Local/nvim/plugs/ale.vim +++ b/AppData/Local/nvim/plugs/ale.vim @@ -1,10 +1,10 @@ " ALE ----- {{{ " ALE (Asynchronous Lint Engine) -" let g:ale_fixers = { - " \ 'javascript': ['eslint'] - " \ } -" let g:ale_sign_error = '❌' -" let g:ale_sign_warning = '⚠️' + let g:ale_fixers = { + \ 'javascript': ['eslint'] + \ } + let g:ale_sign_error = '❌' + let g:ale_sign_warning = '⚠️' " let g:ale_fix_on_save = 1 " }}} diff --git a/AppData/Local/nvim/plugs/lightline_v1.vim b/AppData/Local/nvim/plugs/lightline_v1.vim index 1734d14..4523441 100644 --- a/AppData/Local/nvim/plugs/lightline_v1.vim +++ b/AppData/Local/nvim/plugs/lightline_v1.vim @@ -4,7 +4,7 @@ " + Gruvbox Material " Lightline let g:lightline = { - \ 'colorscheme': 'gruvbox', + \ 'colorscheme': 'gruvbox_material', \ 'active': { \ 'left': [ [ 'mode', 'paste' ],['readonly', 'modified','fugitive']], \ 'right' : [['cocstatus', 'currentfunction'],['lineinfo'], ['percent'],['filetype','fileencoding']] diff --git a/AppData/Local/nvim/plugs/plugins.vim b/AppData/Local/nvim/plugs/plugins.vim index 38f5a02..77f69cc 100644 --- a/AppData/Local/nvim/plugs/plugins.vim +++ b/AppData/Local/nvim/plugs/plugins.vim @@ -4,7 +4,7 @@ let s:PLUGIN_DIR = s:NVIM."/nvim/plugged" call plug#begin(s:PLUGIN_DIR) "https://github.com/junegunn/vim-plug#plug-options Plug 'morhetz/gruvbox' - "Plug 'sainnhe/gruvbox-material' + Plug 'sainnhe/gruvbox-material' " NERD tree will be loaded on the first invocation of NERDTreeToggle command" Plug 'preservim/nerdtree',{ 'on': 'NERDTreeToggle'} "Plug 'tiagofumo/vim-nerdtree-syntax-highlight' @@ -19,11 +19,11 @@ call plug#begin(s:PLUGIN_DIR) Plug 'honza/vim-snippets' Plug 'junegunn/fzf', { 'do': { -> fzf#install() } } Plug 'junegunn/fzf.vim' - "Plug 'nvim-lua/plenary.nvim' + Plug 'nvim-lua/plenary.nvim' Plug 'nvim-telescope/telescope.nvim' - Plug 'neoclide/coc.nvim', {'branch': 'release'} + "Plug 'neoclide/coc.nvim', {'branch': 'release'} "Plug 'w0rp/ale' - "Plug 'sheerun/vim-polyglot' + Plug 'sheerun/vim-polyglot' Plug 'itchyny/lightline.vim' "Plug 'preservim/nerdcommenter' Plug 'tpope/vim-surround' diff --git a/AppData/Local/nvim/plugs/telescope_plug.vim b/AppData/Local/nvim/plugs/telescope_plug.vim index 9738d23..4e745a8 100644 --- a/AppData/Local/nvim/plugs/telescope_plug.vim +++ b/AppData/Local/nvim/plugs/telescope_plug.vim @@ -1,10 +1,44 @@ " Find files using Telescope command-line sugar. "https://github.com/nvim-telescope/telescope.nvim/issues/1144 -nnoremap tf Telescope find_files +nnoremap tf :lua require'telescope.builtin'.find_files(require('telescope.themes').get_dropdown({previewer=false})) nnoremap tg Telescope git_files nnoremap tl Telescope live_grep nnoremap tb Telescope buffers nnoremap th Telescope help_tags -lua << EOF require('telescope').setup{ defaults = { vimgrep_arguments = { 'rg', '--color=never', '--no-heading', '--with-filename', '--line-number', '--column', '--smart-case', '--ignore-file', '.gitignore' }}} +"lua << EOF +"require('telescope').setup{ defaults = { vimgrep_arguments = { 'rg', '--color=never', '--no-heading', '--with-filename', '--line-number', '--column', '--smart-case', '--ignore-file', '.gitignore' }}} +" +"EOF + +lua << EOF +--local previewers = require('telescope.previewers') +--local Job = require('plenary.job') +--local new_maker = function(filepath, bufnr, opts) + --filepath = vim.fn.expand(filepath) + --Job:new({ + --command = 'file', + --args = { '--mime-type', '-b', filepath }, + --on_exit = function(j) + --local mime_type = vim.split(j:result()[1], '/')[1] + --if mime_type == "text" then + --previewers.buffer_previewer_maker(filepath, bufnr, opts) + --else + ---- maybe we want to write something to the buffer here + --vim.schedule(function() + --vim.api.nvim_buf_set_lines(bufnr, 0, -1, false, { 'BINARY' }) + --end) + --end + --end + --}):sync() +--end + +--require('telescope').setup { + -- defaults = { + -- buffer_previewer_maker = new_maker, + --vimgrep_arguments = { 'rg', '--color=never', '--no-heading', '--with-filename', '--line-number', '--column', '--smart-case', '--ignore-file', '.gitignore' } + --} +--} + +EOF From 7516dde621f5d313095695f2723378881c63cba2 Mon Sep 17 00:00:00 2001 From: Prashantha T P Date: Sun, 21 Nov 2021 22:06:10 +0530 Subject: [PATCH 05/50] Fix(tmux): change ~ to HOME variable in popup cmd --- .config/tmux/tmux.conf | 3 +-- 1 file changed, 1 insertion(+), 2 deletions(-) diff --git a/.config/tmux/tmux.conf b/.config/tmux/tmux.conf index f9b1eda..ec8b152 100644 --- a/.config/tmux/tmux.conf +++ b/.config/tmux/tmux.conf @@ -1,10 +1,9 @@ set -s default-terminal 'xterm-256color' - ###################### # Custom scripts ###################### bind-key O run-shell -b "bash ~/.config/tmux/scripts/wiki.sh" -bind-key I display-popup -h 85% -w 85% -E "source ~/.profile;vi \"$(find ~/.config | fzy)\"" +bind-key I display-popup -h 85% -w 85% -E "source ~/.profile;vi \"$(find \"$HOME/.config\" | fzy)\"" bind-key N display-popup -h 85% -w 85% -E "source ~/.profile;vi ~/.config/tmux/tmux.conf" # credits : https://www.hamvocke.com/blog/a-guide-to-customizing-your-tmux-conf/ From cb6272c7a0430ddd28a40a5943837d83b5da4375 Mon Sep 17 00:00:00 2001 From: Prashantha T P Date: Sun, 21 Nov 2021 22:14:01 +0530 Subject: [PATCH 06/50] Feat(Powershell): add more aliases to profile update PATH variable, support cmdline tools --- .../Microsoft.PowerShell_profile.ps1 | 46 ++++++++++++++++++- 1 file changed, 44 insertions(+), 2 deletions(-) diff --git a/Documents/WindowsPowerShell/Microsoft.PowerShell_profile.ps1 b/Documents/WindowsPowerShell/Microsoft.PowerShell_profile.ps1 index e21f517..587a313 100644 --- a/Documents/WindowsPowerShell/Microsoft.PowerShell_profile.ps1 +++ b/Documents/WindowsPowerShell/Microsoft.PowerShell_profile.ps1 @@ -10,7 +10,7 @@ Invoke-Expression (oh-my-posh --init --shell pwsh --config "C://Users//Prashanth $env:LC_ALL='C.UTF-8' -#$env:TERM='xterm-256color' +$env:TERM='xterm-256color' function configfiles_fn{ git --git-dir=D:/dotfiles/dotfiles --work-tree=$HOME $args } @@ -122,4 +122,46 @@ $wtsettings = (Get-ChildItem "$env:LOCALAPPDATA\Packages\Microsoft.WindowsTermin $env:GVIMINIT='let $MYGVIMRC=has("nvim")?$MYGVIMRC:"$HOME/.config/vim/vimrc" | source $MYGVIMRC' #export VIMINIT='let $MYVIMRC=has("nvim")?$MYVIMRC:"$HOME/.config/vim/vimrc" | source $MYVIMRC' -$env:VIMINIT='let $MYVIMRC=has("nvim")?"$LOCALAPPDATA/nvim/init.vim":"$HOME/.config/vim/vimrc" | source $MYVIMRC' +#$env:VIMINIT='let $MYVIMRC=has("nvim")?"$LOCALAPPDATA/nvim/init.vim":"$HOME/.config/vim/vimrc" | source $MYVIMRC' +$env:VIMINIT='let $MYVIMRC=has("nvim")?"$HOME/.config/nvim/init.lua":"$HOME/.config/vim/vimrc" | source $MYVIMRC' +$env:DEV_DIR='E:/Users/VS_Code_Workspace' + +$env:NVIM_CONFIG=$env:LOCALAPPDATA+'/nvim' + +#temp directories +function cd_proj_dir{ + cd $env:PROJ_DIR + } +# add clangd to path +$env:path+=';D:\Applications\Clangd\clangd_12.0.1\bin' +#add ripgrep to path : +#https://github.com/BurntSushi/ripgrep +$env:path+=';D:\Applications\Unix\ripgrep-13.0.0-x86_64-pc-windows-gnu' +#add bat program +#https://github.com/sharkdp/bat#using-bat-on-windows +$env:path+=';D:\Applications\Unix\bat-v0.18.3-x86_64-pc-windows-gnu\bat-v0.18.3-x86_64-pc-windows-gnu' + +$env:FZF_DEFAULT_COMMAND = 'rg --files --hidden --follow --no-ignore-vcs' +$env:FZF_DEFAULT_OPTS='--height 40% --layout=reverse --border' +########################################################### +# FZY +#set-alias -name fzy -value $env:ProgramFiles/Git/usr/bin/fzy.exe +#$env:path+=';D:\Applications\FZF\fzy\usr\bin' # added to system env variables + +set-alias -name which -value $env:ProgramFiles/Git/usr/bin/which.exe + + +######################################### +# vim +# ###################################### +function open_vim{ + & "C:/Program Files/Git/usr/bin/vim.exe" $args + } +set-alias -name vim -value open_vim + + +function bash_ls{ + & "C:/Program Files/Git/usr/bin/ls.exe" $args + } +set-alias -name lsb -value bash_ls + From ec7678e4b76257450b822cc8d5c70576a056316f Mon Sep 17 00:00:00 2001 From: Prashantha T P Date: Sun, 21 Nov 2021 22:38:38 +0530 Subject: [PATCH 07/50] Feat(vim): use fzf for vim buffer switching --- .config/vim/general/leader.vim | 25 ++++++++++++++++++++++++- 1 file changed, 24 insertions(+), 1 deletion(-) diff --git a/.config/vim/general/leader.vim b/.config/vim/general/leader.vim index c2510dc..7505f82 100644 --- a/.config/vim/general/leader.vim +++ b/.config/vim/general/leader.vim @@ -20,5 +20,28 @@ nnoremap - :exe "resize " . (winheight(0) * 2/3) nnoremap 0 :exe "vertical resize " . (winwidth(0) * 3/2) nnoremap 9 :exe "vertical resize " . (winwidth(0) * 2/3) " }}} +" +" Run a given vim command on the results of fuzzy selecting from a given shell +" command. See usage below. +function! FzyCommand(choice_command, vim_command) + try + let output = system(a:choice_command . " | fzy ") + catch /Vim:Interrupt/ + " Swallow errors from ^C, allow redraw! below + endtry + redraw! + if v:shell_error == 0 && !empty(output) + exec a:vim_command . ' ' . output + endif +endfunction + +function! SelectaBuffer() + let bufnrs = filter(range(1, bufnr("$")), 'buflisted(v:val)') + let buffers = map(bufnrs, 'bufname(v:val)') + call FzyCommand('echo "' . join(buffers, "\n") . '"', ":b") +endfunction + +" Fuzzy select a buffer. Open the selected buffer with :b. +nnoremap b :call SelectaBuffer() + -"nmap ws : From 187dc867322cc44be3c096f5322126425a1f3b8b Mon Sep 17 00:00:00 2001 From: Prashantha T P Date: Sun, 21 Nov 2021 22:42:07 +0530 Subject: [PATCH 08/50] Feat(nvim,lua): add util functions related to finding basedir,vim-plug installation --- .config/nvim/lua/utils/init.lua | 31 +++++++++++++++++++++++++++++++ 1 file changed, 31 insertions(+) create mode 100644 .config/nvim/lua/utils/init.lua diff --git a/.config/nvim/lua/utils/init.lua b/.config/nvim/lua/utils/init.lua new file mode 100644 index 0000000..b7cbd91 --- /dev/null +++ b/.config/nvim/lua/utils/init.lua @@ -0,0 +1,31 @@ +local M = M or {} + +--add init.lua's directory to runtime path +--https://github.com/LunarVim/LunarVim/blob/109c766809760f7a9aba5dfb467d8299d2996de0/init.lua#L1-L6 +M.get_base_dir = function () + local init_path = debug.getinfo(1, "S").source:sub(2) -- get script file full path + local base_dir = init_path:match("(.*[/\\])"):sub(1, -2) -- get base dir + return base_dir +end + + +M.add_runtimepath = function(folder_path) +if not vim.tbl_contains(vim.opt.rtp:get(), folder_path) then + vim.opt.rtp:append(folder_path) +end + +end + +M.install_vim_plug = function() +vim.cmd( [[ +let data_dir = has('nvim')?stdpath('data').'/site':"$HOME/.vim" +if empty(glob(data_dir.'/autoload/plug.vim')) + execute "echo 'Vim-plug not installed.\nInstalling now in \n ".data_dir."'" + silent execute "!curl -fLo ".data_dir."/autload --create-dirs https://raw.githubusercontent.com/junegunn/vim-plug/master/plug.vim" +endif +]] +) + +end + +return M -- module table From 123a23ef5691b7fa703153eb890e6342b2642a1c Mon Sep 17 00:00:00 2001 From: Prashantha T P Date: Sun, 21 Nov 2021 22:43:44 +0530 Subject: [PATCH 09/50] Feat(nvim,lua): add cursor management --- .config/nvim/lua/autoload/cursor.lua | 21 +++++++++++++++++++++ .config/nvim/lua/autoload/init.lua | 1 + 2 files changed, 22 insertions(+) create mode 100644 .config/nvim/lua/autoload/init.lua diff --git a/.config/nvim/lua/autoload/cursor.lua b/.config/nvim/lua/autoload/cursor.lua index d79bf25..f93df05 100644 --- a/.config/nvim/lua/autoload/cursor.lua +++ b/.config/nvim/lua/autoload/cursor.lua @@ -22,4 +22,25 @@ endif " " }}} +augroup CURSOR_MANAGEMENT + autocmd! + +" powershell requires different format for escape codes +" see : +" (i) https://docs.microsoft.com/en-us/powershell/module/psreadline/set-psreadlineoption?view=powershell-5.1#example-6--use-vimodechangehandler-to-display-vi-mode-changes +" (ii) https://github.com/microsoft/terminal/issues/1604 +if has('win32') + "https://github.com/neovim/neovim/issues/4867#issuecomment-291249173" + autocmd VimEnter * silent !echo -ne "\e[2 q" + autocmd VimLeave * set guicursor=a:ver25 + +else + autocmd VimEnter * silent !echo -ne "\e[2 q" + autocmd VimLeave * silent !echo -ne "\e[6 q" +" autocmd VimLeave * let &t_me="\]50;CursorShape=1\x7" +" autocmd VimLeave * let &t_SI.="\[6 q" +endif +augroup END + ]]) + diff --git a/.config/nvim/lua/autoload/init.lua b/.config/nvim/lua/autoload/init.lua new file mode 100644 index 0000000..e2d53e9 --- /dev/null +++ b/.config/nvim/lua/autoload/init.lua @@ -0,0 +1 @@ +require('autoload.cursor') From dd343c7fb7a7729571fa1dfa9df07c9635b41a06 Mon Sep 17 00:00:00 2001 From: Prashantha T P Date: Sun, 21 Nov 2021 22:47:59 +0530 Subject: [PATCH 10/50] Chore(nvim,lua); import general settings modules --- .config/nvim/init.lua | 4 +++- .config/nvim/lua/general/settings.lua | 2 +- 2 files changed, 4 insertions(+), 2 deletions(-) diff --git a/.config/nvim/init.lua b/.config/nvim/init.lua index 51ceb12..4b69716 100644 --- a/.config/nvim/init.lua +++ b/.config/nvim/init.lua @@ -24,7 +24,6 @@ lua -------------------------------------------------------------------------------- --add init.lua's directory to runtime path --https://github.com/LunarVim/LunarVim/blob/109c766809760f7a9aba5dfb467d8299d2996de0/init.lua#L1-L6 - local init_path = debug.getinfo(1, "S").source:sub(2) -- ~.config/nvim/init.lua local base_dir = init_path:match("(.*[/\\])"):sub(1, -2) --~.config/nvim @@ -35,3 +34,6 @@ end -------------------------------------------------------------------------------- require('general.init') +require('general') +require('autoload') +require('plugins') diff --git a/.config/nvim/lua/general/settings.lua b/.config/nvim/lua/general/settings.lua index 4a74e0a..bb84e38 100644 --- a/.config/nvim/lua/general/settings.lua +++ b/.config/nvim/lua/general/settings.lua @@ -113,6 +113,6 @@ set shortmess+=c " let g:netrw_cursor=0 " to use userdefined CursorLine and ColorColumn let g:netrw_winsize=30 - +let g:netrw_liststyle=3 ]] ) From 554669fcbe9eab02536d1dd06eebd8dcc924023e Mon Sep 17 00:00:00 2001 From: Prashantha T P Date: Sun, 21 Nov 2021 22:49:14 +0530 Subject: [PATCH 11/50] Dev(git): update gitignore to track nvim files --- .gitignore | 3 +++ 1 file changed, 3 insertions(+) diff --git a/.gitignore b/.gitignore index a0038ef..7998eb8 100644 --- a/.gitignore +++ b/.gitignore @@ -14,6 +14,9 @@ !.config/vim !.config/vim/** +!.config/nvim +!.config/nvim/** + !.config/tmux !.config/tmux/** From e300f44145b025e5afb1962aa7a412688835f667 Mon Sep 17 00:00:00 2001 From: PrashanthaTP Date: Thu, 25 Nov 2021 19:42:42 +0530 Subject: [PATCH 12/50] Refactor(Powershell): organize code inside powershell profile separate sections for aliases,git utilities,env vars,vim --- .../Microsoft.PowerShell_profile.ps1 | 142 +++++++++++------- 1 file changed, 84 insertions(+), 58 deletions(-) diff --git a/Documents/WindowsPowerShell/Microsoft.PowerShell_profile.ps1 b/Documents/WindowsPowerShell/Microsoft.PowerShell_profile.ps1 index 587a313..03abc38 100644 --- a/Documents/WindowsPowerShell/Microsoft.PowerShell_profile.ps1 +++ b/Documents/WindowsPowerShell/Microsoft.PowerShell_profile.ps1 @@ -1,3 +1,7 @@ +############################################################################## +# THEME Settings +############################################################################## + # Import-Module posh-git # Import-Module oh-my-posh # Set-PoshPrompt -Theme paradox @@ -9,16 +13,93 @@ Invoke-Expression (oh-my-posh --init --shell pwsh --config "C://Users//Prashanth T P//Documents//WindowsPowerShell//negligible_custom.omp.json") +############################################################################## +# Path +############################################################################## +# add clangd to path +$env:path+=';D:\Applications\Clangd\clangd_12.0.1\bin' +#add ripgrep to path : +#https://github.com/BurntSushi/ripgrep +$env:path+=';D:\Applications\Unix\ripgrep-13.0.0-x86_64-pc-windows-gnu' +#add bat program +#https://github.com/sharkdp/bat#using-bat-on-windows +$env:path+=';D:\Applications\Unix\bat-v0.18.3-x86_64-pc-windows-gnu\bat-v0.18.3-x86_64-pc-windows-gnu' + +#LLVM (Clang) +$env:path+=';D:\Applications\CPP\LLVM\bin' +############################################################################## +# Environment variables +############################################################################## $env:LC_ALL='C.UTF-8' $env:TERM='xterm-256color' + +$wtsettings = (Get-ChildItem "$env:LOCALAPPDATA\Packages\Microsoft.WindowsTerminal_8wekyb3d8bbwe\LocalState" -Filter settings.json).FullName + +$env:GVIMINIT='let $MYGVIMRC=has("nvim")?$MYGVIMRC:"$HOME/.config/vim/vimrc" | source $MYGVIMRC' + +#export VIMINIT='let $MYVIMRC=has("nvim")?$MYVIMRC:"$HOME/.config/vim/vimrc" | source $MYVIMRC' +#$env:VIMINIT='let $MYVIMRC=has("nvim")?"$LOCALAPPDATA/nvim/init.vim":"$HOME/.config/vim/vimrc" | source $MYVIMRC' +$env:VIMINIT='let $MYVIMRC=has("nvim")?"$HOME/.config/nvim/init.lua":"$HOME/.config/vim/vimrc" | source $MYVIMRC' +$env:DEV_DIR='E:/Users/VS_Code_Workspace' + +$env:NVIM_CONFIG=$env:LOCALAPPDATA+'/nvim' + +############################################################################## +# Aliases +############################################################################## function configfiles_fn{ git --git-dir=D:/dotfiles/dotfiles --work-tree=$HOME $args } + +function wikifiles_fn{ + git --git-dir=D:/dotfiles/wiki/vimwiki/.git --work-tree=D:/dotfiles/wiki/vimwiki $args + } + set-alias -name configfiles -value configfiles_fn -########################################################################## +set-alias -name wikifiles -value wikifiles_fn +function cd_proj_dir{ + cd $env:PROJ_DIR + } +set-alias -name cdp -value cd_proj_dir + +$env:FZF_DEFAULT_COMMAND = 'rg --files --hidden --follow --no-ignore-vcs' +$env:FZF_DEFAULT_OPTS='--height 40% --layout=reverse --border' +########################################################### +# FZY +#set-alias -name fzy -value $env:ProgramFiles/Git/usr/bin/fzy.exe +#$env:path+=';D:\Applications\FZF\fzy\usr\bin' # added to system env variables +set-alias -name which -value $env:ProgramFiles/Git/usr/bin/which.exe + + +######################################### +# Git Bin Utilities +# ###################################### + +function run_git_utility{ + param($exe_name,$exe_args) + Write-Host Running "$exe_name $exe_args" + $local:git_bin="C:/Program Files/Git/usr/bin" + & "$git_bin/$exe_name.exe" $exe_args +} + +function vim{ + run_git_utility "vim" $Args +} + +function ls{ + run_git_utility "ls" $args +} + +function grep{ + run_git_utility "grep" $args +} +#set-alias -name vim -value open_vim +#set-alias -name lsb -value bash_ls + +############################################################################## # vi mode # https://docs.microsoft.com/en-us/powershell/module/psreadline/set-psreadlineoption?view=powershell-5.1 -# +############################################################################## $PSReadLineOptions = @{ EditMode = "Vi" HistoryNoDuplicates = $true @@ -109,59 +190,4 @@ function replaceWithExit { } #Set-PSReadLineKeyHandler -Chord ";" -ScriptBlock { mapTwoLetterFunc ';' 'q' -func $function:replaceWithExit } -############################################ -function wikifiles_fn{ - git --git-dir=D:/dotfiles/wiki/vimwiki/.git --work-tree=D:/dotfiles/wiki/vimwiki $args - } - -set-alias -name wikifiles -value wikifiles_fn -############################################ -# Windows terminal settings -$wtsettings = (Get-ChildItem "$env:LOCALAPPDATA\Packages\Microsoft.WindowsTerminal_8wekyb3d8bbwe\LocalState" -Filter settings.json).FullName - -$env:GVIMINIT='let $MYGVIMRC=has("nvim")?$MYGVIMRC:"$HOME/.config/vim/vimrc" | source $MYGVIMRC' - -#export VIMINIT='let $MYVIMRC=has("nvim")?$MYVIMRC:"$HOME/.config/vim/vimrc" | source $MYVIMRC' -#$env:VIMINIT='let $MYVIMRC=has("nvim")?"$LOCALAPPDATA/nvim/init.vim":"$HOME/.config/vim/vimrc" | source $MYVIMRC' -$env:VIMINIT='let $MYVIMRC=has("nvim")?"$HOME/.config/nvim/init.lua":"$HOME/.config/vim/vimrc" | source $MYVIMRC' -$env:DEV_DIR='E:/Users/VS_Code_Workspace' - -$env:NVIM_CONFIG=$env:LOCALAPPDATA+'/nvim' - -#temp directories -function cd_proj_dir{ - cd $env:PROJ_DIR - } -# add clangd to path -$env:path+=';D:\Applications\Clangd\clangd_12.0.1\bin' -#add ripgrep to path : -#https://github.com/BurntSushi/ripgrep -$env:path+=';D:\Applications\Unix\ripgrep-13.0.0-x86_64-pc-windows-gnu' -#add bat program -#https://github.com/sharkdp/bat#using-bat-on-windows -$env:path+=';D:\Applications\Unix\bat-v0.18.3-x86_64-pc-windows-gnu\bat-v0.18.3-x86_64-pc-windows-gnu' - -$env:FZF_DEFAULT_COMMAND = 'rg --files --hidden --follow --no-ignore-vcs' -$env:FZF_DEFAULT_OPTS='--height 40% --layout=reverse --border' -########################################################### -# FZY -#set-alias -name fzy -value $env:ProgramFiles/Git/usr/bin/fzy.exe -#$env:path+=';D:\Applications\FZF\fzy\usr\bin' # added to system env variables - -set-alias -name which -value $env:ProgramFiles/Git/usr/bin/which.exe - - -######################################### -# vim -# ###################################### -function open_vim{ - & "C:/Program Files/Git/usr/bin/vim.exe" $args - } -set-alias -name vim -value open_vim - - -function bash_ls{ - & "C:/Program Files/Git/usr/bin/ls.exe" $args - } -set-alias -name lsb -value bash_ls - +############################################################################## From 742981f7df269e5f9f64e3bf4715b0b348863459 Mon Sep 17 00:00:00 2001 From: PrashanthaTP Date: Thu, 25 Nov 2021 20:41:14 +0530 Subject: [PATCH 13/50] Feat(nvim): address #12, syntax hightlighting support Lua syntax highlighting inside vim files inside lua << EOF and EOF block Not working but implemented: + support Vim syntax hightling inside Lua files Ref: + see vim :help g:vimsyn_embed + https://www.reddit.com/r/neovim/comments/mjtde1/handy_syntax_highlighting_for_vimcmd_snippets_and/ tags: syntax,syntax-highlighting,embedded-language,neovim,nvim --- .config/nvim/after/syntax/lua.vim | 16 ++++++++++++++++ .config/nvim/after/syntax/vim.vim | 7 +++++++ .config/nvim/lua/general/settings.lua | 1 + 3 files changed, 24 insertions(+) create mode 100644 .config/nvim/after/syntax/lua.vim create mode 100644 .config/nvim/after/syntax/vim.vim diff --git a/.config/nvim/after/syntax/lua.vim b/.config/nvim/after/syntax/lua.vim new file mode 100644 index 0000000..b440020 --- /dev/null +++ b/.config/nvim/after/syntax/lua.vim @@ -0,0 +1,16 @@ +unlet b:current_syntax + +syn include @Vim $VIMRUNTIME/syntax/vim.vim +syn region embedvim matchgroup=luaEmbedError start="^vim\.api\.nvim_command(\[\[" end="\]\])" keepend contains=@Vim +syn region embedvim matchgroup=luaEmbedError start="^vim\.api\.nvim_command \[\[" end="\]\]" keepend contains=@Vim +syn region embedvim matchgroup=luaEmbedError start="^vim\.api\.nvim_exec(\[\[" end="\]\])" keepend contains=@Vim +syn region embedvim matchgroup=luaEmbedError start="^vim\.api\.nvim_exec \[\[" end="\]\]" keepend contains=@Vim +syn region embedvim matchgroup=luaEmbedError start="^vim\.cmd \[\[" end="\]\]" keepend contains=@Vim +syn region embedvim matchgroup=luaEmbedError start="^vim\.cmd(\[\[" end="\]\])" keepend contains=@Vim +syn region embedvim matchgroup=luaEmbedError start="^vim\.cmd \"" end="\"" keepend contains=@Vim +syn region embedvim matchgroup=luaEmbedError start="^vim\.cmd(\"" end="\")" keepend contains=@Vim +syn region embedvim matchgroup=luaEmbedError start="^vim\.cmd '" end="'" keepend contains=@Vim +syn region embedvim matchgroup=luaEmbedError start="^vim\.cmd('" end="')" keepend contains=@Vim + +let b:current_syntax = 'lua' + diff --git a/.config/nvim/after/syntax/vim.vim b/.config/nvim/after/syntax/vim.vim new file mode 100644 index 0000000..a459ed3 --- /dev/null +++ b/.config/nvim/after/syntax/vim.vim @@ -0,0 +1,7 @@ +unlet b:current_syntax + +syn include @Lua $VIMRUNTIME/syntax/lua.vim +syn region embedlua matchgroup=vimEmbedError start="^lua << EOF$" end="^EOF$" keepend contains=@Lua + +let b:current_syntax = 'vim' + diff --git a/.config/nvim/lua/general/settings.lua b/.config/nvim/lua/general/settings.lua index bb84e38..acc0ae8 100644 --- a/.config/nvim/lua/general/settings.lua +++ b/.config/nvim/lua/general/settings.lua @@ -18,6 +18,7 @@ nnoremap x "_x syntax on set conceallevel=0 +let g:vimsyn_embed = 'l' " syntax heightlighting for embedded lua " filetype on " filetype plugin on " filetype indent on From 3b7a23256bfa0efcd6d1c4b83e55bf26aeca0cc8 Mon Sep 17 00:00:00 2001 From: PrashanthaTP Date: Thu, 25 Nov 2021 21:10:03 +0530 Subject: [PATCH 14/50] Chore(nvim): add util functions nvim lua --- .config/nvim/lua/utils/init.lua | 27 +++++++++++++++------------ 1 file changed, 15 insertions(+), 12 deletions(-) diff --git a/.config/nvim/lua/utils/init.lua b/.config/nvim/lua/utils/init.lua index b7cbd91..1c5f14d 100644 --- a/.config/nvim/lua/utils/init.lua +++ b/.config/nvim/lua/utils/init.lua @@ -1,31 +1,34 @@ -local M = M or {} +local M = {} --add init.lua's directory to runtime path --https://github.com/LunarVim/LunarVim/blob/109c766809760f7a9aba5dfb467d8299d2996de0/init.lua#L1-L6 -M.get_base_dir = function () +M.get_base_dir = function() local init_path = debug.getinfo(1, "S").source:sub(2) -- get script file full path - local base_dir = init_path:match("(.*[/\\])"):sub(1, -2) -- get base dir + local base_dir = init_path:match("(.*[/\\])"):sub(1, -2) -- get base dir return base_dir end - M.add_runtimepath = function(folder_path) -if not vim.tbl_contains(vim.opt.rtp:get(), folder_path) then - vim.opt.rtp:append(folder_path) -end - + if not vim.tbl_contains(vim.opt.rtp:get(), folder_path) then + vim.opt.rtp:append(folder_path) + end end +-- install vim-plug if not already installed +-- @param : nil +-- @return : nil M.install_vim_plug = function() -vim.cmd( [[ + vim.cmd([[ let data_dir = has('nvim')?stdpath('data').'/site':"$HOME/.vim" if empty(glob(data_dir.'/autoload/plug.vim')) execute "echo 'Vim-plug not installed.\nInstalling now in \n ".data_dir."'" silent execute "!curl -fLo ".data_dir."/autload --create-dirs https://raw.githubusercontent.com/junegunn/vim-plug/master/plug.vim" endif -]] -) +]]) +end -end +M.replace_termcodes = function(str) + return vim.api.nvim_replace_termcodes(str, true, true, true) +end return M -- module table From 3b0c40f013b3df4332a3ce1458816d5828e397d2 Mon Sep 17 00:00:00 2001 From: PrashanthaTP Date: Thu, 25 Nov 2021 21:21:14 +0530 Subject: [PATCH 15/50] Chore(nvim): reorganize init.lua, add constants.lua add condition to ensure vim-plug installation --- .config/nvim/init.lua | 42 ++++++++++++---------------------- .config/nvim/lua/constants.lua | 3 +++ 2 files changed, 18 insertions(+), 27 deletions(-) create mode 100644 .config/nvim/lua/constants.lua diff --git a/.config/nvim/init.lua b/.config/nvim/init.lua index 4b69716..1daf46a 100644 --- a/.config/nvim/init.lua +++ b/.config/nvim/init.lua @@ -1,27 +1,8 @@ -- +--------------------------------------------------------------------------+ --- | | --- | NEOVIM CONFIG | +-- | | +-- | NEOVIM CONFIG | -- | | -- +--------------------------------------------------------------------------+ --------------------------------------------------------------------------------- ---[[ - -lua -+---autoload -| cursor.lua -| -+---general -| init.lua -| keymappings.lua -| languages.lua -| leader.lua -| settings.lua -| -\---plugins - lsp.lua - -]]-- --------------------------------------------------------------------------------- --add init.lua's directory to runtime path --https://github.com/LunarVim/LunarVim/blob/109c766809760f7a9aba5dfb467d8299d2996de0/init.lua#L1-L6 local init_path = debug.getinfo(1, "S").source:sub(2) -- ~.config/nvim/init.lua @@ -29,11 +10,18 @@ local base_dir = init_path:match("(.*[/\\])"):sub(1, -2) --~.config/nvim --add init.lua's directory to runtime path if not vim.tbl_contains(vim.opt.rtp:get(), base_dir) then - vim.opt.rtp:append(base_dir) + vim.opt.rtp:append(base_dir) end - -------------------------------------------------------------------------------- -require('general.init') -require('general') -require('autoload') -require('plugins') +require("constants") +-------------------------------------------------------------------------------- +--make sure vim-plug installed to manage plugins +local utils = require("utils") -- should be called after adding curr dir to rtp +utils.install_vim_plug() +-------------------------------------------------------------------------------- +vim.cmd([[ let $TERM="xterm-256color" ]]) + +require("general") +require("autoload") +require("plugins") + diff --git a/.config/nvim/lua/constants.lua b/.config/nvim/lua/constants.lua new file mode 100644 index 0000000..3a1cb5d --- /dev/null +++ b/.config/nvim/lua/constants.lua @@ -0,0 +1,3 @@ +OS = "Windows" +local NVIM_DIR = "D:/applications/nvim/nvim" +PLUGINS_DIR = NVIM_DIR .. "/plugged" From 28390d3971d1afbc74230701980c8cb3e1cd644c Mon Sep 17 00:00:00 2001 From: PrashanthaTP Date: Thu, 25 Nov 2021 21:22:28 +0530 Subject: [PATCH 16/50] Chore(nvim): add function for file reloading add keybinding for vim or lua file reloading --- .config/nvim/lua/general/leader.lua | 22 +++++++++++++++++++--- 1 file changed, 19 insertions(+), 3 deletions(-) diff --git a/.config/nvim/lua/general/leader.lua b/.config/nvim/lua/general/leader.lua index 04a7d1a..1f386ce 100644 --- a/.config/nvim/lua/general/leader.lua +++ b/.config/nvim/lua/general/leader.lua @@ -1,5 +1,21 @@ +--https://sbulav.github.io/vim/neovim-telescope-github/ +function _G.save_and_exec() + vim.cmd([[silent! write]]) + if vim.bo.filetype == "lua" then + require("plenary.reload").reload_module(vim.fn.expand("%")) + vim.cmd([[:luafile %]]) + elseif vim.bo.filetype == "vim" then + vim.cmd([[:source %]]) + else + end + + print("Reloaded buffer : ",vim.fn.expand("%")) +end + vim.cmd([[ + let mapleader="\" + " Mappings with leader key " source vim file nmap vs :source $MYVIMRC @@ -8,7 +24,7 @@ nmap vo :e $MYVIMRC nnoremap n :bnext nnoremap p :bprev nnoremap b :buffers - +nnoremap r :call v:lua.save_and_exec() " splits ----- {{{ "nnoremap w w "removed to support vimwiki nnoremap h h @@ -22,5 +38,5 @@ nnoremap - :exe "resize " . (winheight(0) * 2/3) nnoremap 0 :exe "vertical resize " . (winwidth(0) * 3/2) nnoremap 9 :exe "vertical resize " . (winwidth(0) * 2/3) " }}} -]] -) + +]]) From f20854b966e0ef5b130d5d1b836bc72c01633d47 Mon Sep 17 00:00:00 2001 From: PrashanthaTP Date: Thu, 25 Nov 2021 21:23:44 +0530 Subject: [PATCH 17/50] Chore(nvim): add general settings related to editor related to termguicolors,tabs,cursorcolumn --- .config/nvim/lua/general/settings.lua | 9 ++++++++- 1 file changed, 8 insertions(+), 1 deletion(-) diff --git a/.config/nvim/lua/general/settings.lua b/.config/nvim/lua/general/settings.lua index acc0ae8..cd8b68d 100644 --- a/.config/nvim/lua/general/settings.lua +++ b/.config/nvim/lua/general/settings.lua @@ -15,6 +15,7 @@ nnoremap x "_x " }}} " EDITOR ----- {{{ +set termguicolors syntax on set conceallevel=0 @@ -26,13 +27,19 @@ set ignorecase set smartcase " use 4 spaces for tabs set tabstop=4 +set autoindent +set smarttab +set expandtab +set tabstop=4 set softtabstop=4 set shiftwidth=4 set number set scrolloff=8 set showtabline=2 set lazyredraw -"set colorcolumn=80 +set cursorline +set colorcolumn=80 +set signcolumn=yes " Show white spaces https://gist.github.com/jdavid82/d40f40e6f124aad6223eba0ff0c7ad65#file-vimrc-L37-L39 "set listchars=tab:>·,trail:~,extends:>,precedes:<,space:· "set list From 9f47d49fc7e470d12ed5590fa71d4c580286adb4 Mon Sep 17 00:00:00 2001 From: PrashanthaTP Date: Thu, 25 Nov 2021 21:26:12 +0530 Subject: [PATCH 18/50] Feat(nvim): add list of plugins for installing/loading --- .config/nvim/lua/plugins/init.lua | 39 +++++++++++++++++++++++++++++++ 1 file changed, 39 insertions(+) create mode 100644 .config/nvim/lua/plugins/init.lua diff --git a/.config/nvim/lua/plugins/init.lua b/.config/nvim/lua/plugins/init.lua new file mode 100644 index 0000000..872ec86 --- /dev/null +++ b/.config/nvim/lua/plugins/init.lua @@ -0,0 +1,39 @@ +-- PLUGINS +--https://dev.to/vonheikemen/neovim-using-vim-plug-in-lua-3oom +local Plug = function(plugin, ...) + vim.call("plug#", plugin, ...) +end + +vim.call("plug#begin", PLUGINS_DIR) +Plug("sainnhe/gruvbox-material") +Plug("preservim/nerdtree", { on = { "NERDTreeToggle", "NERDTreeFind" } }) +Plug("sbdchd/neoformat") +--[===[ Plug ('prettier/vim-prettier', + { ['do']= 'yarn install', ['for']= {'python', + 'lua', + 'javascript', + 'typescript', + 'css', + 'scss', + 'json', + 'markdown', + 'html' + } + }) +--]===] +Plug("nvim-lua/plenary.nvim") +Plug("neovim/nvim-lspconfig") +--Plug('hrsh7th/nvim-compe') --deprecated +Plug("hrsh7th/cmp-nvim-lsp") +Plug("hrsh7th/cmp-buffer") +Plug("hrsh7th/cmp-path") +Plug("hrsh7th/cmp-cmdline") +Plug("hrsh7th/nvim-cmp") +--Plug("onsails/lspkind-nvim")--awesome menu styling +Plug("hrsh7th/vim-vsnip") +Plug("hrsh7th/cmp-vsnip") +--Plug 'hrsh7th/vim-vsnip-integ' +Plug("nvim-treesitter/nvim-treesitter", { ["do"] = ":TSUpdate" }) +Plug("nvim-lualine/lualine.nvim") + +vim.call("plug#end") From 13595292f826deeab67e8946455859d490596341 Mon Sep 17 00:00:00 2001 From: PrashanthaTP Date: Thu, 25 Nov 2021 21:29:13 +0530 Subject: [PATCH 19/50] Plug(nvim): add nerdtree and gruvbox-material plugins --- .../lua/plugins/gruvbox-material/init.lua | 21 +++++++++++++++++++ .config/nvim/lua/plugins/init.lua | 6 ++++++ .config/nvim/lua/plugins/nerdtree/init.lua | 8 +++++++ 3 files changed, 35 insertions(+) create mode 100644 .config/nvim/lua/plugins/gruvbox-material/init.lua create mode 100644 .config/nvim/lua/plugins/nerdtree/init.lua diff --git a/.config/nvim/lua/plugins/gruvbox-material/init.lua b/.config/nvim/lua/plugins/gruvbox-material/init.lua new file mode 100644 index 0000000..9f3d50f --- /dev/null +++ b/.config/nvim/lua/plugins/gruvbox-material/init.lua @@ -0,0 +1,21 @@ +vim.cmd([[ +augroup SET_COLORSCHEME + autocmd! + autocmd User LoadGruvbox ++nested colorscheme gruvbox-material +augroup end + +"call with +]]) +-- use as vim.cmd([[doautocmd User LoadGruvbox ]]) +vim.cmd([[ +set termguicolors +if exists('+termguicolors') + let &term="xterm-256color" + set t_Co=256 + let &t_8f = "\[38;2;%lu;%lu;%lum" + let &t_8b = "\[48;2;%lu;%lu;%lum" +endif +"let g:gruvbox_contrast_dark = 'hard' +doautocmd User LoadGruvbox + +]]) diff --git a/.config/nvim/lua/plugins/init.lua b/.config/nvim/lua/plugins/init.lua index 872ec86..1897c05 100644 --- a/.config/nvim/lua/plugins/init.lua +++ b/.config/nvim/lua/plugins/init.lua @@ -37,3 +37,9 @@ Plug("nvim-treesitter/nvim-treesitter", { ["do"] = ":TSUpdate" }) Plug("nvim-lualine/lualine.nvim") vim.call("plug#end") + +require("plugins.nerdtree") + +vim.cmd([[colorscheme gruvbox-material]]) +--require('plugins.syntax.gruvbox') + diff --git a/.config/nvim/lua/plugins/nerdtree/init.lua b/.config/nvim/lua/plugins/nerdtree/init.lua new file mode 100644 index 0000000..e7d0688 --- /dev/null +++ b/.config/nvim/lua/plugins/nerdtree/init.lua @@ -0,0 +1,8 @@ +vim.cmd([[ +nnoremap t :NERDTreeToggle +nnoremap y :NERDTreeFind + +" Exit Vim if NERDTree is the only window remaining in the only tab. +autocmd BufEnter * if tabpagenr('$') == 1 && winnr('$') == 1 && exists('b:NERDTree') && b:NERDTree.isTabTree() | quit | endif +]]) + From 703cbbf9db2d6b7682b51bb9bfcefbf5d1bb4d33 Mon Sep 17 00:00:00 2001 From: PrashanthaTP Date: Thu, 25 Nov 2021 21:34:06 +0530 Subject: [PATCH 20/50] Feat(nvim): configure LSP for nvim efm server is mainly for supporting formatting --- .config/nvim/lua/plugins/init.lua | 36 +++++ .config/nvim/lua/plugins/nvim-cmp/init.lua | 127 ++++++++++++++++++ .config/nvim/lua/plugins/nvim-compe/init.lua | 72 ++++++++++ .../nvim/lua/plugins/nvim-lspconfig/init.lua | 24 ++++ .../plugins/nvim-lspconfig/servers/clangd.lua | 0 .../plugins/nvim-lspconfig/servers/cmake.lua | 0 .../plugins/nvim-lspconfig/servers/cssls.lua | 31 +++++ .../plugins/nvim-lspconfig/servers/efm.lua | 43 ++++++ .../plugins/nvim-lspconfig/servers/init.vim | 0 .../nvim-lspconfig/servers/sumneko_lua.lua | 42 ++++++ .../nvim-lspconfig/servers/tsserver.lua | 16 +++ .../nvim/lua/plugins/nvim-lspconfig/utils.lua | 53 ++++++++ 12 files changed, 444 insertions(+) create mode 100644 .config/nvim/lua/plugins/nvim-cmp/init.lua create mode 100644 .config/nvim/lua/plugins/nvim-compe/init.lua create mode 100644 .config/nvim/lua/plugins/nvim-lspconfig/init.lua create mode 100644 .config/nvim/lua/plugins/nvim-lspconfig/servers/clangd.lua create mode 100644 .config/nvim/lua/plugins/nvim-lspconfig/servers/cmake.lua create mode 100644 .config/nvim/lua/plugins/nvim-lspconfig/servers/cssls.lua create mode 100644 .config/nvim/lua/plugins/nvim-lspconfig/servers/efm.lua create mode 100644 .config/nvim/lua/plugins/nvim-lspconfig/servers/init.vim create mode 100644 .config/nvim/lua/plugins/nvim-lspconfig/servers/sumneko_lua.lua create mode 100644 .config/nvim/lua/plugins/nvim-lspconfig/servers/tsserver.lua create mode 100644 .config/nvim/lua/plugins/nvim-lspconfig/utils.lua diff --git a/.config/nvim/lua/plugins/init.lua b/.config/nvim/lua/plugins/init.lua index 1897c05..ae16ad2 100644 --- a/.config/nvim/lua/plugins/init.lua +++ b/.config/nvim/lua/plugins/init.lua @@ -39,7 +39,43 @@ Plug("nvim-lualine/lualine.nvim") vim.call("plug#end") require("plugins.nerdtree") +require("plugins.nvim-lspconfig") +require("plugins.nvim-cmp") +require("plugins.vim-vsnip") vim.cmd([[colorscheme gruvbox-material]]) --require('plugins.syntax.gruvbox') +vim.cmd([[ +"highlight! LspDiagnosticsVirtualTextHint guifg=#FF0000 ctermfg=Red +highlight! LspDiagnosticsVirtualTextWarning guifg=Red ctermfg=Red +highlight! LspDiagnosticsVirtualTextError guifg=Red ctermfg=Red +highlight! LspDiagnosticsDefaultWarning guifg=#FF0000 ctermfg=Red +highlight! LspDiagnosticsDefaultError guifg=#FF0000 ctermfg=Red +]]) + +vim.cmd([[ +" auto-format +autocmd BufWritePre *.js lua vim.lsp.buf.formatting_sync(nil, 100) +autocmd BufWritePre *.jsx lua vim.lsp.buf.formatting_sync(nil, 100) +autocmd BufWritePre *.py lua vim.lsp.buf.formatting_sync(nil, 100) +]]) + +vim.cmd([[ +"let g:prettier#config#single_quote = 'true' +"let g:prettier#config#trailing_comma = 'all' + +let g:neoformat_python_autopep8 = { + \ 'exe': 'python -m autopep8', + \ 'args': ['-s 4', '-E'], + \ 'replace': 1 , + \ 'stdin': 1, + \ 'env': ["DEBUG=1"], + \ 'valid_exit_codes': [0, 23], + \ 'no_append': 1, + \ } + +let g:neoformat_enabled_python = ['autopep8'] + +]]) + diff --git a/.config/nvim/lua/plugins/nvim-cmp/init.lua b/.config/nvim/lua/plugins/nvim-cmp/init.lua new file mode 100644 index 0000000..bc2d33b --- /dev/null +++ b/.config/nvim/lua/plugins/nvim-cmp/init.lua @@ -0,0 +1,127 @@ +local cmp = require("cmp") +--local lspkind = require("lspkind") +--set completeopt=menu,menuone,noselect +local has_words_before = function() + local line, col = unpack(vim.api.nvim_win_get_cursor(0)) + return col ~= 0 and vim.api.nvim_buf_get_lines(0, line - 1, line, true)[1]:sub(col, col):match("%s") == nil +end + +local feedkey = function(key, mode) + vim.api.nvim_feedkeys(vim.api.nvim_replace_termcodes(key, true, true, true), mode, true) +end + +local kind_icons = { + Text = "", + Method = "", + Function = "", + Constructor = "", + Field = "", + Variable = "", + Class = "ﴯ", + Interface = "", + Module = "", + Property = "ﰠ", + Unit = "", + Value = "", + Enum = "", + Keyword = "", + Snippet = "", + Color = "", + File = "", + Reference = "", + Folder = "", + EnumMember = "", + Constant = "", + Struct = "", + Event = "", + Operator = "", + TypeParameter = "", +} + +cmp.setup({ + --https://github.com/hrsh7th/nvim-cmp/wiki/Menu-Appearance#basic-customisations + formatting = { + format = function(entry, vim_item) + -- Kind icons + vim_item.kind = string.format("%s %s", kind_icons[vim_item.kind], vim_item.kind) -- This concatonates the icons with the name of the item kind + -- Source + vim_item.menu = ({ + buffer = "[Buffer]", + nvim_lsp = "[LSP]", + luasnip = "[LuaSnip]", + nvim_lua = "[Lua]", + latex_symbols = "[LaTeX]", + })[entry.source.name] + return vim_item + end, + }, + snippet = { + -- REQUIRED - you must specify a snippet engine + expand = function(args) + vim.fn["vsnip#anonymous"](args.body) -- For `vsnip` users. + -- require('luasnip').lsp_expand(args.body) -- For `luasnip` users. + -- vim.fn["UltiSnips#Anon"](args.body) -- For `ultisnips` users. + -- require'snippy'.expand_snippet(args.body) -- For `snippy` users. + end, + }, + mapping = { + [""] = cmp.mapping(cmp.mapping.scroll_docs(-4), { "i", "c" }), + [""] = cmp.mapping(cmp.mapping.scroll_docs(4), { "i", "c" }), + [""] = cmp.mapping(cmp.mapping.complete(), { "i", "c" }), + [""] = cmp.config.disable, -- Specify `cmp.config.disable` if you want to remove the default `` mapping. + [""] = cmp.mapping({ + i = cmp.mapping.abort(), + c = cmp.mapping.close(), + }), + [""] = cmp.mapping.confirm({ select = true }), + + [""] = cmp.mapping(function(fallback) + if cmp.visible() then + cmp.select_next_item() + elseif vim.fn["vsnip#available"](1) == 1 then + feedkey("(vsnip-expand-or-jump)", "") + elseif has_words_before() then + cmp.complete() + else + fallback() -- The fallback function sends a already mapped key. In this case, it's probably ``. + end + end, { "i", "s" }), + + [""] = cmp.mapping(function() + if cmp.visible() then + cmp.select_prev_item() + elseif vim.fn["vsnip#jumpable"](-1) == 1 then + feedkey("(vsnip-jump-prev)", "") + end + end, { "i", "s" }), + }, + sources = cmp.config.sources({ + { name = "nvim_lsp" }, + { name = "vsnip" }, -- For vsnip users. + -- { name = 'luasnip' }, -- For luasnip users. + -- { name = 'ultisnips' }, -- For ultisnips users. + -- { name = 'snippy' }, -- For snippy users. + }, { + { name = "buffer" }, + { name = 'path' }, + }), + experimental = { + ghost_text = true, + }, +}) + +-- Use buffer source for `/` (if you enabled `native_menu`, this won't work anymore). +cmp.setup.cmdline("/", { + sources = { + { name = "buffer" }, + }, +}) + +-- Use cmdline & path source for ':' (if you enabled `native_menu`, this won't work anymore). +cmp.setup.cmdline(":", { + sources = cmp.config.sources({ + { name = "path" }, + }, { + { name = "cmdline" }, + }), +}) diff --git a/.config/nvim/lua/plugins/nvim-compe/init.lua b/.config/nvim/lua/plugins/nvim-compe/init.lua new file mode 100644 index 0000000..a93cdf0 --- /dev/null +++ b/.config/nvim/lua/plugins/nvim-compe/init.lua @@ -0,0 +1,72 @@ +vim.o.completeopt = "menuone,noselect" + +require'compe'.setup { + enabled = true; + autocomplete = true; + debug = false; + min_length = 1; + preselect = 'enable'; + throttle_time = 80; + source_timeout = 200; + incomplete_delay = 400; + max_abbr_width = 100; + max_kind_width = 100; + max_menu_width = 100; + documentation = false; + + source = { + path = true; + buffer = true; + calc = true; + vsnip = true; + nvim_lsp = true; + nvim_lua = true; + spell = true; + tags = true; + snippets_nvim = true; + treesitter = true; + }; +} + +local t = function(str) + return vim.api.nvim_replace_termcodes(str, true, true, true) +end + +local check_back_space = function() + local col = vim.fn.col('.') - 1 + if col == 0 or vim.fn.getline('.'):sub(col, col):match('%s') then + return true + else + return false + end +end + +-- Use (s-)tab to: +--- move to prev/next item in completion menuone +--- jump to prev/next snippet's placeholder +_G.tab_complete = function() + if vim.fn.pumvisible() == 1 then + return t "" +elseif vim.fn.call("vsnip#available", {1}) == 1 then + return t "(vsnip-expand-or-jump)" + elseif check_back_space() then + return t "" + else + return vim.fn['compe#complete']() + end +end +_G.s_tab_complete = function() + if vim.fn.pumvisible() == 1 then + return t "" + elseif vim.fn.call("vsnip#jumpable", {-1}) == 1 then + return t "(vsnip-jump-prev)" + else + -- If is not working in your terminal, change it to + return t "" + end +end + +vim.api.nvim_set_keymap("i", "", "v:lua.tab_complete()", {expr = true}) +vim.api.nvim_set_keymap("s", "", "v:lua.tab_complete()", {expr = true}) +vim.api.nvim_set_keymap("i", "", "v:lua.s_tab_complete()", {expr = true}) +vim.api.nvim_set_keymap("s", "", "v:lua.s_tab_complete()", {expr = true}) diff --git a/.config/nvim/lua/plugins/nvim-lspconfig/init.lua b/.config/nvim/lua/plugins/nvim-lspconfig/init.lua new file mode 100644 index 0000000..dfb7210 --- /dev/null +++ b/.config/nvim/lua/plugins/nvim-lspconfig/init.lua @@ -0,0 +1,24 @@ +local nvim_lsp = require("lspconfig") +local utils = require("plugins.nvim-lspconfig.utils") +local on_attach = utils.on_attach + +-- Use a loop to conveniently call 'setup' on multiple servers and +-- map buffer local keybindings when the language server attaches +local servers = { "pyright", "clangd", "cmake", "tsserver", "cssls", "sumneko_lua" } + +local capabilities = require("cmp_nvim_lsp").update_capabilities(vim.lsp.protocol.make_client_capabilities()) + +for _, lsp in ipairs(servers) do + nvim_lsp[lsp].setup({ + capabilities = capabilities, + on_attach = on_attach, + flags = { + debounce_text_changes = 150, + }, + }) +end + +require("plugins.nvim-lspconfig.servers.cssls").setup(on_attach) +require("plugins.nvim-lspconfig.servers.sumneko_lua").setup(on_attach) +require("plugins.nvim-lspconfig.servers.efm").setup(on_attach) +require("plugins.nvim-lspconfig.servers.tsserver").setup(on_attach) diff --git a/.config/nvim/lua/plugins/nvim-lspconfig/servers/clangd.lua b/.config/nvim/lua/plugins/nvim-lspconfig/servers/clangd.lua new file mode 100644 index 0000000..e69de29 diff --git a/.config/nvim/lua/plugins/nvim-lspconfig/servers/cmake.lua b/.config/nvim/lua/plugins/nvim-lspconfig/servers/cmake.lua new file mode 100644 index 0000000..e69de29 diff --git a/.config/nvim/lua/plugins/nvim-lspconfig/servers/cssls.lua b/.config/nvim/lua/plugins/nvim-lspconfig/servers/cssls.lua new file mode 100644 index 0000000..bb39698 --- /dev/null +++ b/.config/nvim/lua/plugins/nvim-lspconfig/servers/cssls.lua @@ -0,0 +1,31 @@ +local lspconfig = require('lspconfig') +local M = {} + +M.setup = function (on_attach) + local capabilities = vim.lsp.protocol.make_client_capabilities() + capabilities.textDocument.completion.completionItem.snippetSupport = true + lspconfig.cssls.setup{ + capabilities=capabilities, + cmd = { "vscode-css-language-server.cmd", "--stdio" }, + filetypes = { "css", "scss", "less" }, + on_attach=on_attach, + --root_dir = root_pattern("package.json", ".git") or bufdir, + --https://stackoverflow.com/questions/64868071/i-cannot-activate-nvims-built-in-lsps-for-javascript-and-html + root_dir = function() return vim.loop.cwd() end , + settings = { + css = { + validate = true + }, + less = { + validate = true + }, + scss = { + validate = true + } + }, + single_file_support = true + } + +end + +return M diff --git a/.config/nvim/lua/plugins/nvim-lspconfig/servers/efm.lua b/.config/nvim/lua/plugins/nvim-lspconfig/servers/efm.lua new file mode 100644 index 0000000..2bfa711 --- /dev/null +++ b/.config/nvim/lua/plugins/nvim-lspconfig/servers/efm.lua @@ -0,0 +1,43 @@ +local lspconfig = require('lspconfig') +local M = {} + +--[===[ +--local eslint = { + lintCommand = 'eslint_d -f unix --stdin --stdin-filename ${INPUT}', + lintIgnoreExitCode = true, + lintStdin = true, + lintFormats = { '%f:%l:%c: %m' }, + formatCommand = 'eslint_d --fix-to-stdout --stdin --stdin-filename=${INPUT}', + formatStdin = true, +} + +local clang_format = { formatCommand = 'clang-format -style=LLVM ${INPUT}', formatStdin = true } +local prettier = { formatCommand = 'prettier --stdin-filepath ${INPUT}', formatStdin = true } +local stylua = { formatCommand = 'stylua -s -', formatStdin = true } +local black = { formatCommand = 'black --quiet -', formatStdin = true } +--]===] +-- +local lua_format_cmd = function() + local buf_name = vim.fn.fnameescape(vim.api.nvim_buf_get_name(0)) + return LUA_LANG_SERVER_EXE.." -i '"..buf_name.."'" +end + +local python_formatter = {formatCommand = "python -m autopep8 -", formatStdin = true} + +local lua_formatter = {formatCommand = FORMATTERS_DIR.."/stylua -s -", formatStdin = true } +local languages = { python={python_formatter}, lua={lua_formatter} } + +M.setup = function (on_attach) + +require "lspconfig".efm.setup { + init_options = {documentFormatting = true}, + cmd ={LANGUAGE_SERVERS_DIR .."/efm-langserver"}, + settings = { + languages = languages + }, + single_file_support = true +} + +end + +return M diff --git a/.config/nvim/lua/plugins/nvim-lspconfig/servers/init.vim b/.config/nvim/lua/plugins/nvim-lspconfig/servers/init.vim new file mode 100644 index 0000000..e69de29 diff --git a/.config/nvim/lua/plugins/nvim-lspconfig/servers/sumneko_lua.lua b/.config/nvim/lua/plugins/nvim-lspconfig/servers/sumneko_lua.lua new file mode 100644 index 0000000..0d1ed17 --- /dev/null +++ b/.config/nvim/lua/plugins/nvim-lspconfig/servers/sumneko_lua.lua @@ -0,0 +1,42 @@ +local capabilities = require('cmp_nvim_lsp').update_capabilities(vim.lsp.protocol.make_client_capabilities()) +local luaconfig = require('lspconfig') +local M = {} + +M.setup = function(on_attach) + -- Make runtime files discoverable to the server + local runtime_path = vim.split(package.path, ';')--package path is nvim installation dir/bin/lua + + luaconfig.sumneko_lua.setup { + capabilities=capabilities, + cmd = {LUA_LANG_SERVER_EXE, "-E", LUA_LANG_SERVER_MAIN_LUA}, + on_attach=on_attach, + init_options = { + provideFormatter = true + }, + Format = { + function() + vim.lsp.buf.range_formatting({},{0,0},{vim.fn.line("$"),0}) + end + }, + settings = { + Lua = { + runtime = { + -- Tell the language server which version of Lua you're using (most likely LuaJIT in the case of Neovim) + version = 'LuaJIT', + -- Setup your lua path + path = runtime_path + }, + diagnostics = { + -- Get the language server to recognize the `vim` global + globals = {'vim'} + }, + workspace = { + -- Make the server aware of Neovim runtime files + library = {[vim.fn.expand('$VIMRUNTIME/lua')] = true, [vim.fn.expand('$VIMRUNTIME/lua/vim/lsp')] = true} + } + } + } + } +end + +return M diff --git a/.config/nvim/lua/plugins/nvim-lspconfig/servers/tsserver.lua b/.config/nvim/lua/plugins/nvim-lspconfig/servers/tsserver.lua new file mode 100644 index 0000000..0d3740e --- /dev/null +++ b/.config/nvim/lua/plugins/nvim-lspconfig/servers/tsserver.lua @@ -0,0 +1,16 @@ +local M = {} + +M.setup = function (on_attach) + +require "lspconfig".tsserver.setup { + cmd = { "typescript-language-server.cmd", "--stdio" }, + filetypes = { "javascript", "javascriptreact", "javascript.jsx", "typescript", "typescriptreact", "typescript.tsx" }, + init_options = { + hostInfo = "neovim" + }, + root_dir = require('lspconfig').util.root_pattern("package.json", "tsconfig.json", "jsconfig.json", ".git") + +} + +end +return M diff --git a/.config/nvim/lua/plugins/nvim-lspconfig/utils.lua b/.config/nvim/lua/plugins/nvim-lspconfig/utils.lua new file mode 100644 index 0000000..3b079fa --- /dev/null +++ b/.config/nvim/lua/plugins/nvim-lspconfig/utils.lua @@ -0,0 +1,53 @@ +local t = require("utils").replace_termcodes +local M = {} + +M.set_keymappings = function(bufnr) + local buf_set_keymap = function(...) + vim.api.nvim_buf_set_keymap(bufnr, ...) + end + + local opts = { noremap = true, silent = true } + + -- See `:help vim.lsp.*` for documentation on any of the below functions + buf_set_keymap("n", "gD", "lua vim.lsp.buf.declaration()", opts) + buf_set_keymap("n", "gd", "lua vim.lsp.buf.definition()", opts) + buf_set_keymap("n", "K", "lua vim.lsp.buf.hover()", opts) + buf_set_keymap("n", "gi", "lua vim.lsp.buf.implementation()", opts) + buf_set_keymap("n", t(""), "lua vim.lsp.buf.signature_help()", opts) + buf_set_keymap("n", t("wa"), "lua vim.lsp.buf.add_workspace_folder()", opts) + buf_set_keymap("n", t("wr"), "lua vim.lsp.buf.remove_workspace_folder()", opts) + buf_set_keymap("n", t("wl"), "lua print(vim.inspect(vim.lsp.buf.list_workspace_folders()))", opts) + buf_set_keymap("n", t("D"), "lua vim.lsp.buf.type_definition()", opts) + buf_set_keymap("n", t("rn"), "lua vim.lsp.buf.rename()", opts) + buf_set_keymap("n", t("ca"), "lua vim.lsp.buf.code_action()", opts) + buf_set_keymap("n", "gr", "lua vim.lsp.buf.references()", opts) + buf_set_keymap("n", t("e"), "lua vim.lsp.diagnostic.show_line_diagnostics()", opts) + buf_set_keymap("n", "[d", "lua vim.lsp.diagnostic.goto_prev()", opts) + buf_set_keymap("n", "]d", "lua vim.lsp.diagnostic.goto_next()", opts) + buf_set_keymap("n", t("q"), "lua vim.lsp.diagnostic.set_loclist()", opts) + buf_set_keymap("n", t("f"), "lua vim.lsp.buf.formatting()", opts) +end + +-- Use an on_attach function to only map the following keys +-- after the language server attaches to the current buffer +M.on_attach = function(client, bufnr) + local buf_set_option = function(...) + vim.api.nvim_buf_set_option(bufnr, ...) + end + -- Enable completion triggered by + buf_set_option("omnifunc", "v:lua.vim.lsp.omnifunc") + -- Mappings. + M.set_keymappings(bufnr) + if client.resolved_capabilities.document_formatting then + vim.api.nvim_command([[augroup FORMAT]]) + vim.api.nvim_command([[autocmd! * ]]) + vim.api.nvim_command([[autocmd BufWritePre lua vim.lsp.buf.formatting_seq_sync()]]) + vim.api.nvim_command([[augroup end]]) + end + vim.lsp.handlers["textDocument/publishDiagnostics"] = vim.lsp.with(vim.lsp.diagnostic.on_publish_diagnostics, { + virtual_text = {spacing=4,prefix='' }, signs = true, underline = true, + update_in_insert = true, + }) +end + +return M From 2f402afa7a51662f29ac0272c49e36f4d8ae64f4 Mon Sep 17 00:00:00 2001 From: PrashanthaTP Date: Thu, 25 Nov 2021 21:36:42 +0530 Subject: [PATCH 21/50] Plug(nvim): add lualine plugin to nvim --- .config/nvim/lua/plugins/init.lua | 1 + .config/nvim/lua/plugins/lualine/bubbles.lua | 62 ++++++ .config/nvim/lua/plugins/lualine/init.lua | 218 +++++++++++++++++++ 3 files changed, 281 insertions(+) create mode 100644 .config/nvim/lua/plugins/lualine/bubbles.lua create mode 100644 .config/nvim/lua/plugins/lualine/init.lua diff --git a/.config/nvim/lua/plugins/init.lua b/.config/nvim/lua/plugins/init.lua index ae16ad2..3e7a607 100644 --- a/.config/nvim/lua/plugins/init.lua +++ b/.config/nvim/lua/plugins/init.lua @@ -42,6 +42,7 @@ require("plugins.nerdtree") require("plugins.nvim-lspconfig") require("plugins.nvim-cmp") require("plugins.vim-vsnip") +require("plugins.lualine") vim.cmd([[colorscheme gruvbox-material]]) --require('plugins.syntax.gruvbox') diff --git a/.config/nvim/lua/plugins/lualine/bubbles.lua b/.config/nvim/lua/plugins/lualine/bubbles.lua new file mode 100644 index 0000000..c1ecf31 --- /dev/null +++ b/.config/nvim/lua/plugins/lualine/bubbles.lua @@ -0,0 +1,62 @@ +-- Bubbles config for lualine +-- Author: lokesh-krishna +-- MIT license, see LICENSE for more details. + +-- stylua: ignore +local colors = { + blue = '#80a0ff', + cyan = '#79dac8', + black = '#080808', + white = '#c6c6c6', + red = '#ff5189', + violet = '#d183e8', + grey = '#303030', +} + +local bubbles_theme = { + normal = { + a = { fg = colors.black, bg = colors.violet }, + b = { fg = colors.white, bg = colors.grey }, + c = { fg = colors.black, bg = colors.black }, + }, + + insert = { a = { fg = colors.black, bg = colors.blue } }, + visual = { a = { fg = colors.black, bg = colors.cyan } }, + replace = { a = { fg = colors.black, bg = colors.red } }, + + inactive = { + a = { fg = colors.white, bg = colors.black }, + b = { fg = colors.white, bg = colors.black }, + c = { fg = colors.black, bg = colors.black }, + }, +} + +require('lualine').setup { + options = { + theme = bubbles_theme, + component_separators = '|', + section_separators = { left = '', right = '' }, + }, + sections = { + lualine_a = { + { 'mode', separator = { left = '' }, right_padding = 2 }, + }, + lualine_b = { 'filename', 'branch' }, + lualine_c = { 'fileformat' }, + lualine_x = {}, + lualine_y = { 'filetype', 'progress' }, + lualine_z = { + { 'location', separator = { right = '' }, left_padding = 2 }, + }, + }, + inactive_sections = { + lualine_a = { 'filename' }, + lualine_b = {}, + lualine_c = {}, + lualine_x = {}, + lualine_y = {}, + lualine_z = { 'location' }, + }, + tabline = {}, + extensions = {}, +} diff --git a/.config/nvim/lua/plugins/lualine/init.lua b/.config/nvim/lua/plugins/lualine/init.lua new file mode 100644 index 0000000..4c60644 --- /dev/null +++ b/.config/nvim/lua/plugins/lualine/init.lua @@ -0,0 +1,218 @@ +-- Eviline config for lualine +-- Author: shadmansaleh +-- Credit: glepnir +local lualine = require("lualine") + +-- Color table for highlights +-- stylua: ignore +local colors = { + bg = '#202328', + fg = '#bbc2cf', + yellow = '#ECBE7B', + cyan = '#008080', + darkblue = '#081633', + green = '#98be65', + orange = '#FF8800', + violet = '#a9a1e1', + magenta = '#c678dd', + blue = '#51afef', + red = '#ec5f67', +} + +local conditions = { + buffer_not_empty = function() + return vim.fn.empty(vim.fn.expand("%:t")) ~= 1 + end, + hide_in_width = function() + return vim.fn.winwidth(0) > 80 + end, + check_git_workspace = function() + local filepath = vim.fn.expand("%:p:h") + local gitdir = vim.fn.finddir(".git", filepath .. ";") + return gitdir and #gitdir > 0 and #gitdir < #filepath + end, +} + +-- Config +local config = { + options = { + -- Disable sections and component separators + component_separators = "", + section_separators = "", + theme = { + -- We are going to use lualine_c an lualine_x as left and + -- right section. Both are highlighted by c theme . So we + -- are just setting default looks o statusline + normal = { c = { fg = colors.fg, bg = colors.bg } }, + inactive = { c = { fg = colors.fg, bg = colors.bg } }, + }, + }, + sections = { + -- these are to remove the defaults + lualine_a = {}, + lualine_b = {}, + lualine_y = {}, + lualine_z = {}, + -- These will be filled later + lualine_c = {}, + lualine_x = {}, + }, + inactive_sections = { + -- these are to remove the defaults + lualine_a = {}, + lualine_v = {}, + lualine_y = {}, + lualine_z = {}, + lualine_c = {}, + lualine_x = {}, + }, +} + +-- Inserts a component in lualine_c at left section +local function ins_left(component) + table.insert(config.sections.lualine_c, component) +end + +-- Inserts a component in lualine_x ot right section +local function ins_right(component) + table.insert(config.sections.lualine_x, component) +end + +ins_left({ + function() + return "▊" + end, + color = { fg = colors.blue }, -- Sets highlighting of component + padding = { left = 0, right = 1 }, -- We don't need space before this +}) + +ins_left({ + -- mode component + function() + -- auto change color according to neovims mode + local mode_color = { + n = colors.red, + i = colors.green, + v = colors.blue, + [""] = colors.blue, + V = colors.blue, + c = colors.magenta, + no = colors.red, + s = colors.orange, + S = colors.orange, + [""] = colors.orange, + ic = colors.yellow, + R = colors.violet, + Rv = colors.violet, + cv = colors.red, + ce = colors.red, + r = colors.cyan, + rm = colors.cyan, + ["r?"] = colors.cyan, + ["!"] = colors.red, + t = colors.red, + } + vim.api.nvim_command("hi! LualineMode guifg=" .. mode_color[vim.fn.mode()] .. " guibg=" .. colors.bg) + return "" + end, + color = "LualineMode", + padding = { right = 1 }, +}) + +ins_left({ + "filename", + cond = conditions.buffer_not_empty, + color = { fg = colors.magenta, gui = "bold" }, +}) + +ins_left({ + "branch", + icon = "", + color = { fg = colors.violet, gui = "bold" }, +}) + +ins_left({ + "diagnostics", + sources = { "nvim_lsp" }, + symbols = { error = " ", warn = " ", info = " " }, + diagnostics_color = { + color_error = { fg = colors.red }, + color_warn = { fg = colors.yellow }, + color_info = { fg = colors.cyan }, + }, +}) + +-- Insert mid section. You can make any number of sections in neovim :) +-- for lualine it's any number greater then 2 +ins_left({ + function() + return "%=" + end, +}) + +ins_right({ + -- Lsp server name . + function() + local msg = "No Active Lsp" + local buf_ft = vim.api.nvim_buf_get_option(0, "filetype") + local clients = vim.lsp.get_active_clients() + if next(clients) == nil then + return msg + end + for _, client in ipairs(clients) do + local filetypes = client.config.filetypes + if filetypes and vim.fn.index(filetypes, buf_ft) ~= -1 then + return client.name + end + end + return msg + end, + icon = " LSP:", + color = { fg = "#ffffff", gui = "bold" }, +}) + +ins_right({ "location" }) + +ins_right({ "progress", color = { fg = colors.fg, gui = "bold" } }) +-- Add components to right sections +ins_right({ + "o:encoding", -- option component same as &encoding in viml + fmt = string.upper, -- I'm not sure why it's upper case either ;) + cond = conditions.hide_in_width, + color = { fg = colors.green, gui = "bold" }, +}) + +ins_right({ + "fileformat", + fmt = string.upper, + icons_enabled = false, -- I think icons are cool but Eviline doesn't have them. sigh + color = { fg = colors.green, gui = "bold" }, +}) + +ins_right({ + "diff", + -- Is it me or the symbol for modified us really weird + symbols = { added = " ", modified = "柳 ", removed = " " }, + diff_color = { + added = { fg = colors.green }, + modified = { fg = colors.orange }, + removed = { fg = colors.red }, + }, + cond = conditions.hide_in_width, +}) + +ins_right({ + -- filesize component + "filesize", + cond = conditions.buffer_not_empty, +}) +ins_right({ + function() + return "▊" + end, + color = { fg = colors.blue }, + padding = { left = 1 }, +}) + +-- Now don't forget to initialize lualine +lualine.setup(config) From 557d2af48709dd6b1aed72e0c51821950e3b3cc2 Mon Sep 17 00:00:00 2001 From: PrashanthaTP Date: Thu, 25 Nov 2021 21:38:53 +0530 Subject: [PATCH 22/50] Feat(nvim): add nvim-treesitter plugin requires llvm-clang for making .so files --- .config/nvim/lua/plugins/init.lua | 5 ++-- .../nvim/lua/plugins/nvim-treesitter/init.lua | 28 +++++++++++++++++++ 2 files changed, 31 insertions(+), 2 deletions(-) create mode 100644 .config/nvim/lua/plugins/nvim-treesitter/init.lua diff --git a/.config/nvim/lua/plugins/init.lua b/.config/nvim/lua/plugins/init.lua index 3e7a607..6c6f463 100644 --- a/.config/nvim/lua/plugins/init.lua +++ b/.config/nvim/lua/plugins/init.lua @@ -43,6 +43,7 @@ require("plugins.nvim-lspconfig") require("plugins.nvim-cmp") require("plugins.vim-vsnip") require("plugins.lualine") +require("plugins.nvim-treesitter") vim.cmd([[colorscheme gruvbox-material]]) --require('plugins.syntax.gruvbox') @@ -70,8 +71,8 @@ let g:neoformat_python_autopep8 = { \ 'exe': 'python -m autopep8', \ 'args': ['-s 4', '-E'], \ 'replace': 1 , - \ 'stdin': 1, - \ 'env': ["DEBUG=1"], + \ 'stdin': 1, + \ 'env': ["DEBUG=1"], \ 'valid_exit_codes': [0, 23], \ 'no_append': 1, \ } diff --git a/.config/nvim/lua/plugins/nvim-treesitter/init.lua b/.config/nvim/lua/plugins/nvim-treesitter/init.lua new file mode 100644 index 0000000..bd2573d --- /dev/null +++ b/.config/nvim/lua/plugins/nvim-treesitter/init.lua @@ -0,0 +1,28 @@ +require("nvim-treesitter.configs").setup({ + highlight = { + enable = true, + disable = {}, + }, + indent = { + enable = false, + disable = {}, + }, + ensure_installed = { + "bash", + "c", + "cpp", + "json", + "html", + "lua", + "python", + "tsx", + "scss", + }, +}) +local parser_config = require("nvim-treesitter.parsers").get_parser_configs() +parser_config.tsx.used_by = { "javascript", "reactjavascript", "typescript.tsx" } +parser_config.scss.used_by = { "css" } + +--require 'nvim-treesitter.install'.compilers = { "clang","clangd" ,"gcc"} + +require("nvim-treesitter.install").compilers = { "clang" } From 7482b035cd2807a21ab41973551f0eee436db5dc Mon Sep 17 00:00:00 2001 From: PrashanthaTP Date: Thu, 25 Nov 2021 21:39:31 +0530 Subject: [PATCH 23/50] Chore(nvim): add constants mostly used for lsp servers --- .config/nvim/lua/constants.lua | 5 +++++ 1 file changed, 5 insertions(+) diff --git a/.config/nvim/lua/constants.lua b/.config/nvim/lua/constants.lua index 3a1cb5d..8ccf38e 100644 --- a/.config/nvim/lua/constants.lua +++ b/.config/nvim/lua/constants.lua @@ -1,3 +1,8 @@ OS = "Windows" local NVIM_DIR = "D:/applications/nvim/nvim" PLUGINS_DIR = NVIM_DIR .. "/plugged" +FORMATTERS_DIR = NVIM_DIR .. "/formatters" +LUA_FORMATTER_EXE = FORMATTERS_DIR .. "/lua-format" +LANGUAGE_SERVERS_DIR = NVIM_DIR .. "/language-servers" +LUA_LANG_SERVER_EXE = LANGUAGE_SERVERS_DIR .. "/lua-language-server/bin/Windows/lua-language-server" +LUA_LANG_SERVER_MAIN_LUA = LANGUAGE_SERVERS_DIR .. "/lua-language-server/main.lua" From 1fa9e3b0fc3c7a281ace70e7cf9de10342ede1b1 Mon Sep 17 00:00:00 2001 From: PrashanthaTP Date: Thu, 25 Nov 2021 21:40:50 +0530 Subject: [PATCH 24/50] Chore(nvim): add vim-vsnip settings same snippet settings for js, react-js, tsx --- .config/nvim/lua/plugins/vim-vsnip/init.lua | 6 ++++++ 1 file changed, 6 insertions(+) create mode 100644 .config/nvim/lua/plugins/vim-vsnip/init.lua diff --git a/.config/nvim/lua/plugins/vim-vsnip/init.lua b/.config/nvim/lua/plugins/vim-vsnip/init.lua new file mode 100644 index 0000000..b19835e --- /dev/null +++ b/.config/nvim/lua/plugins/vim-vsnip/init.lua @@ -0,0 +1,6 @@ +vim.cmd( +[[ +let g:vsnip_filetypes = {} +let g:vsnip_filetypes.javascriptreact = ['javascript'] +let g:vsnip_filetypes.typescriptreact = ['typescript'] +]]) From e4fa159891a853a132e437ab98d333e856b48e33 Mon Sep 17 00:00:00 2001 From: PrashanthaTP Date: Thu, 25 Nov 2021 22:12:29 +0530 Subject: [PATCH 25/50] Docs(nvim): add info about nvim-lua-lsp-treesitter and other useful links --- .config/nvim/README.md | 38 ++++++++++++++++++++++++++++++++++++++ 1 file changed, 38 insertions(+) create mode 100644 .config/nvim/README.md diff --git a/.config/nvim/README.md b/.config/nvim/README.md new file mode 100644 index 0000000..01b72ee --- /dev/null +++ b/.config/nvim/README.md @@ -0,0 +1,38 @@ +# Neovim Config + +## Help + +### Lua + ++ [nvim-lua-guide](https://github.com/nanotee/nvim-lua-guide) ++ [nvim :help lua](https://neovim.io/doc/user/lua.html) + +### Language Server Protocol [[Official Page]](https://microsoft.github.io/language-server-protocol/) + ++ [LSP plugin](https://github.com/neovim/nvim-lspconfig) and [Servers configurations](https://github.com/neovim/nvim-lspconfig/blob/master/doc/server_configurations.md) ++ [nvim-cmp](https://github.com/hrsh7th/nvim-cmp), [nvim-cmp completion + mappings wiki](https://github.com/hrsh7th/nvim-cmp/wiki/Example-mappings) + [nvim-cmp menu appearance](https://github.com/hrsh7th/nvim-cmp/wiki/Menu-Appearance) + +### Autocommands + +- Use of `++nested` : [see vimhelp](https://vimhelp.org/autocmd.txt.html#autocmd-nested) + +## For formatting with LSP + +We can use [efm-langserver](https://github.com/mattn/efm-langserver) for code formatting. + ++ [Example efm config : tomaskallup dotfiles](https://github.com/tomaskallup/dotfiles/blob/29177be3dc416842a3e9112520d4caa4b039728c/nvim/lua/plugins/nvim-lspconfig.lua#L138-L167) + ++ [Example efm config: martinsione dotfiles](https://github.com/martinsione/dotfiles/blob/3716969e12d663d9d7be432682f8fd5c022e44f1/src/.config/nvim/lua/modules/config/nvim-lspconfig/format.lua) + +## Nvim Treesitter [[treesitter]](https://github.com/tree-sitter/tree-sitter) [[nvim-treesitter]](https://github.com/nvim-treesitter/nvim-treesitter) + +Provides better syntax highlighting by wonderful parsing mechanism and if you are code-mad, amazing code control via `tree nodes`. + ++ [nvim-treesitter instructions for Windows](https://github.com/nvim-treesitter/nvim-treesitter/wiki/Windows-support) + +## Lua Plugins + ++ https://sbulav.github.io/vim/neovim-telescope-github/ + From 3de43119dadfeeae8af9b9c8e4c86458d86f3e72 Mon Sep 17 00:00:00 2001 From: PrashanthaTP Date: Sun, 28 Nov 2021 12:45:23 +0530 Subject: [PATCH 26/50] Chore(nvim): ignore some folders in nerdtree using vim global 'NERDTreeIgnore' --- .config/nvim/lua/plugins/nerdtree/init.lua | 1 + 1 file changed, 1 insertion(+) diff --git a/.config/nvim/lua/plugins/nerdtree/init.lua b/.config/nvim/lua/plugins/nerdtree/init.lua index e7d0688..5e4375e 100644 --- a/.config/nvim/lua/plugins/nerdtree/init.lua +++ b/.config/nvim/lua/plugins/nerdtree/init.lua @@ -1,3 +1,4 @@ +vim.g["NERDTreeIgnore"] = {'^node_modules$','\\.git$', '\\.idea$', '\\.vscode$', '\\.history$'} vim.cmd([[ nnoremap t :NERDTreeToggle nnoremap y :NERDTreeFind From d03d43bd43312e573d0c0235f2a0870cbe1bd8dd Mon Sep 17 00:00:00 2001 From: PrashanthaTP Date: Sun, 28 Nov 2021 12:51:41 +0530 Subject: [PATCH 27/50] Plug(nvim): add friendly-snippets why: vim-vsnip is a snippets engine and needs a source for snippets tags: snippets, plugin --- .config/nvim/lua/plugins/init.lua | 1 + 1 file changed, 1 insertion(+) diff --git a/.config/nvim/lua/plugins/init.lua b/.config/nvim/lua/plugins/init.lua index 6c6f463..c583f65 100644 --- a/.config/nvim/lua/plugins/init.lua +++ b/.config/nvim/lua/plugins/init.lua @@ -30,6 +30,7 @@ Plug("hrsh7th/cmp-path") Plug("hrsh7th/cmp-cmdline") Plug("hrsh7th/nvim-cmp") --Plug("onsails/lspkind-nvim")--awesome menu styling +Plug("rafamadriz/friendly-snippets") Plug("hrsh7th/vim-vsnip") Plug("hrsh7th/cmp-vsnip") --Plug 'hrsh7th/vim-vsnip-integ' From 52278e9b19de650fcbc34b06349753cb2ede6edc Mon Sep 17 00:00:00 2001 From: PrashanthaTP Date: Sun, 28 Nov 2021 12:54:56 +0530 Subject: [PATCH 28/50] Cleanup(nvim): refactor plugins/init.lua remove some autocommands --- .config/nvim/lua/plugins/init.lua | 30 ++---------------------------- 1 file changed, 2 insertions(+), 28 deletions(-) diff --git a/.config/nvim/lua/plugins/init.lua b/.config/nvim/lua/plugins/init.lua index c583f65..714e96d 100644 --- a/.config/nvim/lua/plugins/init.lua +++ b/.config/nvim/lua/plugins/init.lua @@ -7,7 +7,7 @@ end vim.call("plug#begin", PLUGINS_DIR) Plug("sainnhe/gruvbox-material") Plug("preservim/nerdtree", { on = { "NERDTreeToggle", "NERDTreeFind" } }) -Plug("sbdchd/neoformat") +--Plug("sbdchd/neoformat") --[===[ Plug ('prettier/vim-prettier', { ['do']= 'yarn install', ['for']= {'python', 'lua', @@ -40,8 +40,8 @@ Plug("nvim-lualine/lualine.nvim") vim.call("plug#end") require("plugins.nerdtree") -require("plugins.nvim-lspconfig") require("plugins.nvim-cmp") +require("plugins.nvim-lspconfig") require("plugins.vim-vsnip") require("plugins.lualine") require("plugins.nvim-treesitter") @@ -56,29 +56,3 @@ highlight! LspDiagnosticsVirtualTextError guifg=Red ctermfg=Red highlight! LspDiagnosticsDefaultWarning guifg=#FF0000 ctermfg=Red highlight! LspDiagnosticsDefaultError guifg=#FF0000 ctermfg=Red ]]) - -vim.cmd([[ -" auto-format -autocmd BufWritePre *.js lua vim.lsp.buf.formatting_sync(nil, 100) -autocmd BufWritePre *.jsx lua vim.lsp.buf.formatting_sync(nil, 100) -autocmd BufWritePre *.py lua vim.lsp.buf.formatting_sync(nil, 100) -]]) - -vim.cmd([[ -"let g:prettier#config#single_quote = 'true' -"let g:prettier#config#trailing_comma = 'all' - -let g:neoformat_python_autopep8 = { - \ 'exe': 'python -m autopep8', - \ 'args': ['-s 4', '-E'], - \ 'replace': 1 , - \ 'stdin': 1, - \ 'env': ["DEBUG=1"], - \ 'valid_exit_codes': [0, 23], - \ 'no_append': 1, - \ } - -let g:neoformat_enabled_python = ['autopep8'] - -]]) - From b91c6e01f96c4521028e13a58f9aae2bae611718 Mon Sep 17 00:00:00 2001 From: PrashanthaTP Date: Sun, 28 Nov 2021 12:56:16 +0530 Subject: [PATCH 29/50] Feat(nvim): show react, html snippets in js files --- .config/nvim/lua/plugins/vim-vsnip/init.lua | 5 +++-- 1 file changed, 3 insertions(+), 2 deletions(-) diff --git a/.config/nvim/lua/plugins/vim-vsnip/init.lua b/.config/nvim/lua/plugins/vim-vsnip/init.lua index b19835e..062f786 100644 --- a/.config/nvim/lua/plugins/vim-vsnip/init.lua +++ b/.config/nvim/lua/plugins/vim-vsnip/init.lua @@ -1,6 +1,7 @@ -vim.cmd( -[[ +vim.cmd([[ let g:vsnip_filetypes = {} +let g:vsnip_filetypes.javascript = ['html'] +let g:vsnip_filetypes.javascript = ['javascriptreact'] let g:vsnip_filetypes.javascriptreact = ['javascript'] let g:vsnip_filetypes.typescriptreact = ['typescript'] ]]) From 1a5cbde7cbc0b08551cb35c3e6d3d762de499f63 Mon Sep 17 00:00:00 2001 From: PrashanthaTP Date: Sun, 28 Nov 2021 12:57:51 +0530 Subject: [PATCH 30/50] Util(nvim): add function to get os name --- .config/nvim/lua/utils/init.lua | 19 +++++++++++++++++++ 1 file changed, 19 insertions(+) diff --git a/.config/nvim/lua/utils/init.lua b/.config/nvim/lua/utils/init.lua index 1c5f14d..0ae9a7b 100644 --- a/.config/nvim/lua/utils/init.lua +++ b/.config/nvim/lua/utils/init.lua @@ -31,4 +31,23 @@ M.replace_termcodes = function(str) return vim.api.nvim_replace_termcodes(str, true, true, true) end +M.os_windows = "win32" +M.os_unix = "unix" +M.os_mac = "mac" +M.os_unknown = "unknown" + +M.get_os_name = function() + local system_name + if vim.fn.has(M.mac) == 1 then + system_name = M.mac + elseif vim.fn.has(M.unix) == 1 then + system_name = M.unix + elseif vim.fn.has(M.windows) == 1 then + system_name = M.windows + else + system_name = M.unknown_os + return system_name + end +end + return M -- module table From 17fdf3bc0cadf2a89de3b6b4ba4286d77116f765 Mon Sep 17 00:00:00 2001 From: PrashanthaTP Date: Sun, 28 Nov 2021 13:30:02 +0530 Subject: [PATCH 31/50] Plug(nvim): add nvim-telescope - add file_ignore_patterns - custom mapping for exiting telescope window tags: plugin, telescope --- .config/nvim/lua/plugins/init.lua | 3 ++ .../nvim/lua/plugins/nvim-telescope/init.lua | 48 +++++++++++++++++++ 2 files changed, 51 insertions(+) create mode 100644 .config/nvim/lua/plugins/nvim-telescope/init.lua diff --git a/.config/nvim/lua/plugins/init.lua b/.config/nvim/lua/plugins/init.lua index 714e96d..b848028 100644 --- a/.config/nvim/lua/plugins/init.lua +++ b/.config/nvim/lua/plugins/init.lua @@ -37,6 +37,7 @@ Plug("hrsh7th/cmp-vsnip") Plug("nvim-treesitter/nvim-treesitter", { ["do"] = ":TSUpdate" }) Plug("nvim-lualine/lualine.nvim") +Plug("nvim-telescope/telescope.nvim") vim.call("plug#end") require("plugins.nerdtree") @@ -46,6 +47,8 @@ require("plugins.vim-vsnip") require("plugins.lualine") require("plugins.nvim-treesitter") +require("plugins.nvim-telescope") + vim.cmd([[colorscheme gruvbox-material]]) --require('plugins.syntax.gruvbox') diff --git a/.config/nvim/lua/plugins/nvim-telescope/init.lua b/.config/nvim/lua/plugins/nvim-telescope/init.lua new file mode 100644 index 0000000..56a87ca --- /dev/null +++ b/.config/nvim/lua/plugins/nvim-telescope/init.lua @@ -0,0 +1,48 @@ +vim.cmd([[ +nnoremap ff lua require('telescope.builtin').find_files() +nnoremap fg lua require('telescope.builtin').live_grep() +nnoremap fb lua require('telescope.builtin').buffers() +nnoremap fh lua require('telescope.builtin').help_tags() +nnoremap fn lua require('telescope.builtin').find_files({cwd="$HOME/.config"}) +]]) + +--Dont preview binaries +local previewers = require("telescope.previewers") +local actions = require("telescope.actions") +local Job = require("plenary.job") + +local new_maker = function(filepath, bufnr, opts) + filepath = vim.fn.expand(filepath) + Job + :new({ + command = "file", + args = { "--mime-type", "-b", filepath }, + on_exit = function(j) + local mime_type = vim.split(j:result()[1], "/")[1] + if mime_type == "text" then + previewers.buffer_previewer_maker(filepath, bufnr, opts) + else + -- maybe we want to write something to the buffer here + vim.schedule(function() + vim.api.nvim_buf_set_lines(bufnr, 0, -1, false, { "BINARY" }) + end) + end + end, + }) + :sync() +end + +require("telescope").setup({ + defaults = { + --buffer_previewer_maker = new_maker, + file_ignore_patterns = { "node_modules", "^vim\\view\\", "^vim\\backup\\", "^vim\\swap\\" }, + mappings = { + i = { + [""] = actions.close, + }, + n = { + ["q"] = actions.close, + }, + }, + }, +}) From 819b003909759001c18efc1e65dc72fbd9d0ce7e Mon Sep 17 00:00:00 2001 From: PrashanthaTP Date: Sun, 28 Nov 2021 13:41:40 +0530 Subject: [PATCH 32/50] Plug(nvim): add vim-devicons and nvim-web-devicons to get file icons in telescope and nerdtree --- .config/nvim/lua/plugins/init.lua | 2 ++ 1 file changed, 2 insertions(+) diff --git a/.config/nvim/lua/plugins/init.lua b/.config/nvim/lua/plugins/init.lua index b848028..682110b 100644 --- a/.config/nvim/lua/plugins/init.lua +++ b/.config/nvim/lua/plugins/init.lua @@ -38,6 +38,8 @@ Plug("nvim-treesitter/nvim-treesitter", { ["do"] = ":TSUpdate" }) Plug("nvim-lualine/lualine.nvim") Plug("nvim-telescope/telescope.nvim") +Plug("kyazdani42/nvim-web-devicons") --load at the end : for lua plugins +Plug("ryanoasis/vim-devicons") -- for vim plugins vim.call("plug#end") require("plugins.nerdtree") From 1aeef71cc9e00bd567759066d32a8409dacf6aa5 Mon Sep 17 00:00:00 2001 From: PrashanthaTP Date: Sun, 28 Nov 2021 13:43:19 +0530 Subject: [PATCH 33/50] Chore(nvim): customize LSP virtualtext & menuicons --- .../nvim/lua/plugins/nvim-lspconfig/utils.lua | 60 ++++++++++++++++++- 1 file changed, 58 insertions(+), 2 deletions(-) diff --git a/.config/nvim/lua/plugins/nvim-lspconfig/utils.lua b/.config/nvim/lua/plugins/nvim-lspconfig/utils.lua index 3b079fa..b8bfba4 100644 --- a/.config/nvim/lua/plugins/nvim-lspconfig/utils.lua +++ b/.config/nvim/lua/plugins/nvim-lspconfig/utils.lua @@ -25,7 +25,8 @@ M.set_keymappings = function(bufnr) buf_set_keymap("n", "[d", "lua vim.lsp.diagnostic.goto_prev()", opts) buf_set_keymap("n", "]d", "lua vim.lsp.diagnostic.goto_next()", opts) buf_set_keymap("n", t("q"), "lua vim.lsp.diagnostic.set_loclist()", opts) - buf_set_keymap("n", t("f"), "lua vim.lsp.buf.formatting()", opts) + buf_set_keymap("n", t("wf"), "lua vim.lsp.buf.formatting()", opts) + -- formatting end -- Use an on_attach function to only map the following keys @@ -38,6 +39,11 @@ M.on_attach = function(client, bufnr) buf_set_option("omnifunc", "v:lua.vim.lsp.omnifunc") -- Mappings. M.set_keymappings(bufnr) + + --[[ if client.name == 'tsserver' then + client.resolved_capabilities.document_formatting = false + end + --]] if client.resolved_capabilities.document_formatting then vim.api.nvim_command([[augroup FORMAT]]) vim.api.nvim_command([[autocmd! * ]]) @@ -45,9 +51,59 @@ M.on_attach = function(client, bufnr) vim.api.nvim_command([[augroup end]]) end vim.lsp.handlers["textDocument/publishDiagnostics"] = vim.lsp.with(vim.lsp.diagnostic.on_publish_diagnostics, { - virtual_text = {spacing=4,prefix='' }, signs = true, underline = true, + virtual_text = { spacing = 4, prefix = "" }, + signs = true, + underline = true, update_in_insert = true, }) + --protocol.SymbolKind = { } + vim.lsp.protocol.completionItemKind = { + "", -- Text + "", -- Method + "", -- Function + "", -- Constructor + "", -- Field + "", -- Variable + "", -- Class + "ﰮ", -- Interface + "", -- Module + "", -- Property + "", -- Unit + "", -- Value + "", -- Enum + "", -- Keyword + "﬌", -- Snippet + "", -- Color + "", -- File + "", -- Reference + "", -- Folder + "", -- EnumMember + "", -- Constant + "", -- Struct + "", -- Event + "ﬦ", -- Operator + "", -- TypeParameter + } end +--[==[== on attach add formatting functionality +-- + if client.resolved_capabilities.document_formatting then + vim.api.nvim_command([[augroup FORMAT]]) + vim.api.nvim_command([[autocmd! * ]]) + vim.api.nvim_command([[autocmd BufWritePre lua vim.lsp.buf.formatting_seq_sync()]]) + vim.api.nvim_command([[augroup end]]) + end +--]==] +local capabilities = require("cmp_nvim_lsp").update_capabilities(vim.lsp.protocol.make_client_capabilities()) +M.get_capabilities = function() + local _capabilities = nil + if capabilities == nil then + _capabilities = vim.lsp.protocol.make_client_capabilities() + _capabilities.textDocument.completion.completionItem.snippetSupport = true + else + _capabilities = capabilities + end + return _capabilities +end return M From d576ac28cd6f9f5977b6675618b532edde0ebb7e Mon Sep 17 00:00:00 2001 From: PrashanthaTP Date: Sun, 28 Nov 2021 16:20:51 +0530 Subject: [PATCH 34/50] Chore(nvim): enable capabilities for tsserver - explicity set true for certain capabilities - add fallback for root_dir in setup tags : LSP, nvim, server, tsserver --- .../nvim-lspconfig/servers/tsserver.lua | 27 +++++++++++++++++-- 1 file changed, 25 insertions(+), 2 deletions(-) diff --git a/.config/nvim/lua/plugins/nvim-lspconfig/servers/tsserver.lua b/.config/nvim/lua/plugins/nvim-lspconfig/servers/tsserver.lua index 0d3740e..7404543 100644 --- a/.config/nvim/lua/plugins/nvim-lspconfig/servers/tsserver.lua +++ b/.config/nvim/lua/plugins/nvim-lspconfig/servers/tsserver.lua @@ -1,16 +1,39 @@ local M = {} -M.setup = function (on_attach) +M.setup = function (on_attach,capabilities) +local on_attach_without_formatting = function(client,bufnr) + client.resolved_capabilities.document_formatting = false + on_attach(client,bufnr) +end + +local capabilities_for_tsserver = require('cmp_nvim_lsp').update_capabilities(vim.lsp.protocol.make_client_capabilities()) +capabilities.textDocument.completion.completionItem.snippetSupport = true +capabilities.textDocument.completion.completionItem.preselectSupport = true +capabilities.textDocument.completion.completionItem.insertReplaceSupport = true +capabilities.textDocument.completion.completionItem.labelDetailsSupport = true +capabilities.textDocument.completion.completionItem.deprecatedSupport = true +capabilities.textDocument.completion.completionItem.commitCharactersSupport = true +capabilities.textDocument.completion.completionItem.tagSupport = { valueSet = { 1 } } +capabilities.textDocument.completion.completionItem.resolveSupport = { + properties = { + 'documentation', + 'detail', + 'additionalTextEdits', + } +} require "lspconfig".tsserver.setup { + on_attach = on_attach_without_formatting, + capabilities=capabilities_for_tsserver, cmd = { "typescript-language-server.cmd", "--stdio" }, filetypes = { "javascript", "javascriptreact", "javascript.jsx", "typescript", "typescriptreact", "typescript.tsx" }, init_options = { hostInfo = "neovim" }, - root_dir = require('lspconfig').util.root_pattern("package.json", "tsconfig.json", "jsconfig.json", ".git") + root_dir = require('lspconfig').util.root_pattern("package.json", "tsconfig.json", "jsconfig.json", ".git") or vim.loop.cwd } end + return M From d710402b466491efdd7ff75f6d1634b4f3027b24 Mon Sep 17 00:00:00 2001 From: PrashanthaTP Date: Sun, 28 Nov 2021 16:21:16 +0530 Subject: [PATCH 35/50] Chore(nvim): set a fallback capabilities for cssls tags: LSP, server, cssls --- .../plugins/nvim-lspconfig/servers/cssls.lua | 58 ++++++++++--------- 1 file changed, 32 insertions(+), 26 deletions(-) diff --git a/.config/nvim/lua/plugins/nvim-lspconfig/servers/cssls.lua b/.config/nvim/lua/plugins/nvim-lspconfig/servers/cssls.lua index bb39698..728af9f 100644 --- a/.config/nvim/lua/plugins/nvim-lspconfig/servers/cssls.lua +++ b/.config/nvim/lua/plugins/nvim-lspconfig/servers/cssls.lua @@ -1,31 +1,37 @@ -local lspconfig = require('lspconfig') +local lspconfig = require("lspconfig") local M = {} -M.setup = function (on_attach) - local capabilities = vim.lsp.protocol.make_client_capabilities() - capabilities.textDocument.completion.completionItem.snippetSupport = true - lspconfig.cssls.setup{ - capabilities=capabilities, - cmd = { "vscode-css-language-server.cmd", "--stdio" }, - filetypes = { "css", "scss", "less" }, - on_attach=on_attach, - --root_dir = root_pattern("package.json", ".git") or bufdir, - --https://stackoverflow.com/questions/64868071/i-cannot-activate-nvims-built-in-lsps-for-javascript-and-html - root_dir = function() return vim.loop.cwd() end , - settings = { - css = { - validate = true - }, - less = { - validate = true - }, - scss = { - validate = true - } - }, - single_file_support = true - } - +M.setup = function(on_attach, capabilities) + local _capabilities = nil + if capabilities == nil then + _capabilities = vim.lsp.protocol.make_client_capabilities() + _capabilities.textDocument.completion.completionItem.snippetSupport = true + else + _capabilities = capabilities + end + lspconfig.cssls.setup({ + capabilities = _capabilities, + cmd = { "vscode-css-language-server.cmd", "--stdio" }, + filetypes = { "css", "scss", "less" }, + on_attach = on_attach, + --root_dir = root_pattern("package.json", ".git") or bufdir, + --https://stackoverflow.com/questions/64868071/i-cannot-activate-nvims-built-in-lsps-for-javascript-and-html + root_dir = function() + return vim.loop.cwd() + end, + settings = { + css = { + validate = true, + }, + less = { + validate = true, + }, + scss = { + validate = true, + }, + }, + single_file_support = true, + }) end return M From 819a8cb3f9a7f01e750f0b13ffee91a2185fac57 Mon Sep 17 00:00:00 2001 From: PrashanthaTP Date: Sun, 28 Nov 2021 16:23:04 +0530 Subject: [PATCH 36/50] Feat(nvim): add support more lanugages with efm - also refactor some functions - formatters : autopep8,stylua,prettier tags: LSP, server, efm --- .../plugins/nvim-lspconfig/servers/efm.lua | 63 ++++++++++++++----- 1 file changed, 47 insertions(+), 16 deletions(-) diff --git a/.config/nvim/lua/plugins/nvim-lspconfig/servers/efm.lua b/.config/nvim/lua/plugins/nvim-lspconfig/servers/efm.lua index 2bfa711..40037ae 100644 --- a/.config/nvim/lua/plugins/nvim-lspconfig/servers/efm.lua +++ b/.config/nvim/lua/plugins/nvim-lspconfig/servers/efm.lua @@ -1,4 +1,4 @@ -local lspconfig = require('lspconfig') +local lspconfig = require("lspconfig") local M = {} --[===[ @@ -18,26 +18,57 @@ local black = { formatCommand = 'black --quiet -', formatStdin = true } --]===] -- local lua_format_cmd = function() - local buf_name = vim.fn.fnameescape(vim.api.nvim_buf_get_name(0)) - return LUA_LANG_SERVER_EXE.." -i '"..buf_name.."'" + local buf_name = vim.fn.fnameescape(vim.api.nvim_buf_get_name(0)) + return FORMATTERS_DIR .. "/stylua -s '" .. buf_name .. "'" end -local python_formatter = {formatCommand = "python -m autopep8 -", formatStdin = true} - -local lua_formatter = {formatCommand = FORMATTERS_DIR.."/stylua -s -", formatStdin = true } -local languages = { python={python_formatter}, lua={lua_formatter} } - -M.setup = function (on_attach) +local prettier_format_cmd = function(lang) + local buf_name = vim.fn.fnameescape(vim.api.nvim_buf_get_name(0)) + local command = "prettier --stdin-filepath "..buf_name + if lang==nil or string.len(lang)==0 then + return command + end +end -require "lspconfig".efm.setup { - init_options = {documentFormatting = true}, - cmd ={LANGUAGE_SERVERS_DIR .."/efm-langserver"}, - settings = { - languages = languages - }, - single_file_support = true +local python_formatter = { formatCommand = "python -m autopep8 -", formatStdin = true } +local prettier_formatter = function(lang) + return { formatCommand = prettier_format_cmd(lang), formatStdin = true } +end +local lua_formatter = { formatCommand = FORMATTERS_DIR .. "/stylua -s -", formatStdin = true } +local languages = { + css = { prettier_formatter("css") }, + html = { prettier_formatter("html") }, + javascript = { prettier_formatter("") }, + javascriptreact = { prettier_formatter("") }, + json = { prettier_formatter("json") }, + lua = { lua_formatter }, + python = { python_formatter }, + typescript = { prettier_formatter("") }, + typescriptreact = { prettier_formatter("") }, + scss = { prettier_formatter("scss") }, } +M.setup = function(on_attach) + require("lspconfig").efm.setup({ + filetypes = { + "css", + "html", + "javascript", + "javascriptreact", + "json", + "lua", + "python", + "typescript", + "typescriptreact", + "scss", + }, + init_options = { documentFormatting = true }, + cmd = { LANGUAGE_SERVERS_DIR .. "/efm-langserver" }, + settings = { + languages = languages, + }, + single_file_support = true, + }) end return M From d7d1d63047574175a88a15af4a443a3564126d84 Mon Sep 17 00:00:00 2001 From: PrashanthaTP Date: Sun, 28 Nov 2021 16:28:36 +0530 Subject: [PATCH 37/50] Chore(nvim): add fallback capabilities for sumneko inside setup function for sumneko_lua server tags: LSP, server, sumneko_lua --- .../nvim-lspconfig/servers/sumneko_lua.lua | 15 +++++++++++---- 1 file changed, 11 insertions(+), 4 deletions(-) diff --git a/.config/nvim/lua/plugins/nvim-lspconfig/servers/sumneko_lua.lua b/.config/nvim/lua/plugins/nvim-lspconfig/servers/sumneko_lua.lua index 0d1ed17..bb2d922 100644 --- a/.config/nvim/lua/plugins/nvim-lspconfig/servers/sumneko_lua.lua +++ b/.config/nvim/lua/plugins/nvim-lspconfig/servers/sumneko_lua.lua @@ -1,15 +1,22 @@ -local capabilities = require('cmp_nvim_lsp').update_capabilities(vim.lsp.protocol.make_client_capabilities()) local luaconfig = require('lspconfig') local M = {} -M.setup = function(on_attach) +M.setup = function(on_attach,capabilities) -- Make runtime files discoverable to the server local runtime_path = vim.split(package.path, ';')--package path is nvim installation dir/bin/lua + local _capabilities = nil + if capabilities == nil then + _capabilities = vim.lsp.protocol.make_client_capabilities() + _capabilities.textDocument.completion.completionItem.snippetSupport = true + else + _capabilities = capabilities + end + luaconfig.sumneko_lua.setup { - capabilities=capabilities, - cmd = {LUA_LANG_SERVER_EXE, "-E", LUA_LANG_SERVER_MAIN_LUA}, on_attach=on_attach, + capabilities=_capabilities, + cmd = {LUA_LANG_SERVER_EXE, "-E", LUA_LANG_SERVER_MAIN_LUA}, init_options = { provideFormatter = true }, From 9bd843b2b462baee349d0152a125540500ea3029 Mon Sep 17 00:00:00 2001 From: PrashanthaTP Date: Sun, 28 Nov 2021 16:32:17 +0530 Subject: [PATCH 38/50] Feat(nvim): add diagnostic language server generic language server similar to efm lanugage server others delete servers/init.vim tags LSP, server, diagnosticls --- .../nvim/lua/plugins/nvim-lspconfig/init.lua | 13 ++- .../nvim-lspconfig/servers/diagnosticls.lua | 91 +++++++++++++++++++ .../plugins/nvim-lspconfig/servers/init.vim | 0 3 files changed, 99 insertions(+), 5 deletions(-) create mode 100644 .config/nvim/lua/plugins/nvim-lspconfig/servers/diagnosticls.lua delete mode 100644 .config/nvim/lua/plugins/nvim-lspconfig/servers/init.vim diff --git a/.config/nvim/lua/plugins/nvim-lspconfig/init.lua b/.config/nvim/lua/plugins/nvim-lspconfig/init.lua index dfb7210..69da355 100644 --- a/.config/nvim/lua/plugins/nvim-lspconfig/init.lua +++ b/.config/nvim/lua/plugins/nvim-lspconfig/init.lua @@ -8,6 +8,7 @@ local servers = { "pyright", "clangd", "cmake", "tsserver", "cssls", "sumneko_lu local capabilities = require("cmp_nvim_lsp").update_capabilities(vim.lsp.protocol.make_client_capabilities()) +--[[ for _, lsp in ipairs(servers) do nvim_lsp[lsp].setup({ capabilities = capabilities, @@ -17,8 +18,10 @@ for _, lsp in ipairs(servers) do }, }) end - -require("plugins.nvim-lspconfig.servers.cssls").setup(on_attach) -require("plugins.nvim-lspconfig.servers.sumneko_lua").setup(on_attach) -require("plugins.nvim-lspconfig.servers.efm").setup(on_attach) -require("plugins.nvim-lspconfig.servers.tsserver").setup(on_attach) +--]] +vim.lsp.set_log_level("debug") +require("plugins.nvim-lspconfig.servers.cssls").setup(on_attach,capabilities) +require("plugins.nvim-lspconfig.servers.sumneko_lua").setup(on_attach,capabilities) +--require("plugins.nvim-lspconfig.servers.efm").setup(on_attach,capabilities) +require("plugins.nvim-lspconfig.servers.diagnosticls").setup(on_attach,capabilities) +require("plugins.nvim-lspconfig.servers.tsserver").setup(on_attach,capabilities) diff --git a/.config/nvim/lua/plugins/nvim-lspconfig/servers/diagnosticls.lua b/.config/nvim/lua/plugins/nvim-lspconfig/servers/diagnosticls.lua new file mode 100644 index 0000000..07e71a7 --- /dev/null +++ b/.config/nvim/lua/plugins/nvim-lspconfig/servers/diagnosticls.lua @@ -0,0 +1,91 @@ +local nvim_lsp = require("lspconfig") +local M = {} + +M.setup = function(on_attach, capabilities) + nvim_lsp.diagnosticls.setup({ + on_attach = on_attach, + capabilities = capabilities, + cmd = { "diagnostic-languageserver.cmd", "--stdio" }, + filetypes = { + "lua", + "javascript", + "javascriptreact", + "json", + "typescript", + "typescriptreact", + "css", + "less", + "scss", + "markdown", + "pandoc", + }, + single_file_support = true, + init_options = { + linters = { + eslint = { + command = "eslint_d", + rootPatterns = { ".git", "jsconfig.json", "tsconfig.json", "package.json" }, + debounce = 100, + args = { "--stdin", "--stdin-filename", "%filepath", "--format", "json" }, + sourceName = "eslint_d", + parseJson = { + errorsRoot = "[0].messages", + line = "line", + column = "column", + endLine = "endLine", + endColumn = "endColumn", + message = "[eslint] ${message} [${ruleId}]", + security = "severity", + }, + securities = { + [2] = "error", + [1] = "warning", + }, + }, + }, + filetypes = { + javascript = "eslint", + javascriptreact = "eslint", + typescript = "eslint", + typescriptreact = "eslint", + }, + formatters = { + eslint_d = { + command = "eslint_d", + args = { "--stdin", "--fix-to-stdout", "--stdin-filename", "%filename" }, + rootPatterns = { ".git", "jsconfig.json", "tsconfig.json", "package.json" }, + }, + prettier = { + command = "prettier", + args = { "--stdin", "--stdin-filepath", "%filename" }, + }, + prettier_lua = { + command = FORMATTERS_DIR .. "/stylua", + args = { "-s", "-" }, + }, + prettierd = { + command = "prettierd", + args = { "%filename" }, + }, + prettier_python = { + command = "python -m autopep8", + args = { "-" }, + }, + }, + formatFiletypes = { + css = "prettier", + javascript = "prettierd", + javascriptreact = "prettierd", + json = "prettier", + lua = "prettier_lua", + scss = "prettier", + less = "prettier", + typescript = "prettierd", + typescriptreact = "prettierd", + markdown = "prettier", + }, + }, + }) +end + +return M diff --git a/.config/nvim/lua/plugins/nvim-lspconfig/servers/init.vim b/.config/nvim/lua/plugins/nvim-lspconfig/servers/init.vim deleted file mode 100644 index e69de29..0000000 From 4e9d003026b61c87677fcfcd2ee5e92c29e75cc5 Mon Sep 17 00:00:00 2001 From: PrashanthaTP Date: Sun, 28 Nov 2021 16:37:08 +0530 Subject: [PATCH 39/50] Chore(vim): edit some colorsettings and git aucmd - did refactoring related to highlight groups - customized highlight groups in git autocmd - set TERM variable in color settings tags: vim, color, git --- .config/vim/general/colorscheme_settings.vim | 7 ++--- .config/vim/general/git.vim | 10 ++++--- .config/vim/vimrc | 28 +++++--------------- 3 files changed, 16 insertions(+), 29 deletions(-) diff --git a/.config/vim/general/colorscheme_settings.vim b/.config/vim/general/colorscheme_settings.vim index 7f45291..c790aea 100644 --- a/.config/vim/general/colorscheme_settings.vim +++ b/.config/vim/general/colorscheme_settings.vim @@ -1,3 +1,4 @@ +let $TERM="xterm-256color" let g:colorscheme='default' " gruvbox ----- {{{ if (has("termguicolors")) @@ -10,11 +11,11 @@ set t_Co=256 "https://github.com/sainnhe/gruvbox-material/blob/master/doc/gruvbox-material.txt "soft,medium,hard "let g:gruvbox_material_background = 'medium' -let g:gruvbox_material_transparent_background = 1 +"let g:gruvbox_material_transparent_background = 1 let g:gruvbox_material_enable_bold = 1 let g:gruvbox_material_enable_italic = 1 "let g:gruvbox_material_statusline_style = 'original' -let g:gruvbox_material_diagnostic_virtual_text = 'colored' +"let g:gruvbox_material_diagnostic_virtual_text = 'colored' let g:gruvbox_material_better_performance = 1 "configuration must be dont before applying colorscheme " @@ -23,7 +24,7 @@ let g:gruvbox_contrast_dark="hard" let g:gruvbox_bold=1 let g:gruvbox_italic=1 -colorscheme gruvbox +colorscheme gruvbox-material "endif " }}} diff --git a/.config/vim/general/git.vim b/.config/vim/general/git.vim index 21933b4..4764443 100644 --- a/.config/vim/general/git.vim +++ b/.config/vim/general/git.vim @@ -1,7 +1,9 @@ function Set_git_settings() - "colorscheme gruvbox - "below line is important : gruvbox-material doesn't work - let g:lightline.colorscheme='gruvbox' + + let g:gruvbox_contrast_dark="mixed" + highlight! CursorLine ctermbg=236 term=NONE cterm=NONE gui=NONE guibg=NONE + highlight! CursorLineNr ctermbg=236 term=NONE cterm=NONE gui=NONE guibg=NONE + "let g:lightline.colorscheme='gruvbox-material' endfunction if &diff @@ -17,7 +19,7 @@ if &diff highlight! link DiffText MatchParen "no transperant bg : set to default colors from gruvbox" "found out using :hi Normal - highlight! Normal ctermfg=223 ctermbg=235 guifg=#ebdbb2 guibg=#282828 + "highlight! Normal ctermfg=223 ctermbg=235 guifg=#ebdbb2 guibg=#282828 :call Set_git_settings() endif diff --git a/.config/vim/vimrc b/.config/vim/vimrc index 13fa5ec..147350b 100644 --- a/.config/vim/vimrc +++ b/.config/vim/vimrc @@ -6,7 +6,6 @@ " changing vimrc folder : " [stackexchange]: https://vi.stackexchange.com/questions/11879/how-can-put-vimrc-and-viminfo-into-vim-directory " -" let g:BASE_DIR="$HOME/.config/vim" let rtp=&runtimepath exec "set runtimepath=".g:BASE_DIR @@ -16,6 +15,8 @@ let &runtimepath.="," set viminfo+=n.g:BASE_DIR.'/viminfo' +exec "set packpath+=".g:BASE_DIR + exec "set directory=" \.g:BASE_DIR."/swap//" \.".," @@ -38,28 +39,11 @@ exec "source ".g:BASE_DIR."/general/general.vim" exec "source ".g:BASE_DIR."/general/cursor.vim" exec "source ".g:BASE_DIR."/general/keybindings.vim" exec "source ".g:BASE_DIR."/general/leader.vim" +exec "source ".g:BASE_DIR."/general/colorscheme_settings.vim" +exec "source ".g:BASE_DIR."/general/git.vim" -highlight Comment cterm=italic gui=italic - -highlight ColorColumn ctermbg=235 guibg=lightgrey cterm=NONE gui=NONE -highlight CursorLine ctermbg=236 guibg=lightgrey cterm=NONE gui=NONE -highlight CursorLineNr ctermbg=236 guibg=lightgrey cterm=NONE gui=NONE - -highlight TabLineSel ctermbg=77 ctermfg=0 cterm=BOLD -highlight TabLineFill ctermbg=0 ctermfg=235 cterm=BOLD -highlight TabLineSel ctermbg=77 ctermfg=0 -highlight TabLine ctermbg=0 ctermfg=77 - -highlight visual ctermbg=238 guibg=#000000 gui=NONE - - -hi MatchParen ctermbg=0 guibg=lightblue -"hi! ColorColumn ctermbg=236 guibg=grey cterm=NONE -"hi! CursorLine ctermbg=236 guibg=grey cterm=NONE -"hi! CursorLineNr ctermbg=237 guibg=grey cterm=NONE -hi! LineNr ctermbg=232 guibg=grey cterm=NONE -"hi! NonText guifg=bg ctermfg=NONE -"hi! Visual ctermbg=237 guibg=#dddddd cterm=NONE +"exec "source ".g:BASE_DIR."/plugins.vim" " let g:netrw_cursor=0 " to use userdefined CursorLine and ColorColumn let g:netrw_winsize=30 + From a565ecb1f21e3faf0edbbe99cc6ae2623432d112 Mon Sep 17 00:00:00 2001 From: PrashanthaTP Date: Sun, 28 Nov 2021 16:41:19 +0530 Subject: [PATCH 40/50] Feat(powershell): add open_wiki and lsg functions - open_wiki : open wiki files with nvim using `find`,`fzf` and `bat` as previewer for `fzf`. - lsg : alias for ls.exe from Git/usr/bin tags: powershell, commandline, fzf, wiki, ls, git-bin --- .../Microsoft.PowerShell_profile.ps1 | 12 +++++++++--- 1 file changed, 9 insertions(+), 3 deletions(-) diff --git a/Documents/WindowsPowerShell/Microsoft.PowerShell_profile.ps1 b/Documents/WindowsPowerShell/Microsoft.PowerShell_profile.ps1 index 03abc38..eeed8fb 100644 --- a/Documents/WindowsPowerShell/Microsoft.PowerShell_profile.ps1 +++ b/Documents/WindowsPowerShell/Microsoft.PowerShell_profile.ps1 @@ -61,9 +61,15 @@ function cd_proj_dir{ cd $env:PROJ_DIR } set-alias -name cdp -value cd_proj_dir - $env:FZF_DEFAULT_COMMAND = 'rg --files --hidden --follow --no-ignore-vcs' -$env:FZF_DEFAULT_OPTS='--height 40% --layout=reverse --border' +$env:FZF_DEFAULT_OPTS='--height 40% --layout=reverse --ansi --border --preview "bat --color=always {1}"' + +function open_wiki{ + $local:cmd="C:/Program Files/Git/usr/bin/find.exe" + $local:dir="D:/dotfiles/wiki" + + nvim $(& $cmd $dir -type f -name '\*.md' -not -path '\*/.git/\*'| fzf) + } ########################################################### # FZY #set-alias -name fzy -value $env:ProgramFiles/Git/usr/bin/fzy.exe @@ -86,7 +92,7 @@ function vim{ run_git_utility "vim" $Args } -function ls{ +function lsg{ run_git_utility "ls" $args } From 96aa495985be9edee660246567a1cf880daa642a Mon Sep 17 00:00:00 2001 From: PrashanthaTP Date: Thu, 2 Dec 2021 22:22:04 +0530 Subject: [PATCH 41/50] Fix(nvim): address #13, configfure efm lang server supported languages = { css = { prettier_formatter }, html = { prettier_formatter }, javascript = { prettier_formatter }, javascriptreact = { prettier_formatter }, json = { prettier_formatter }, lua = { lua_formatter }, python = { python_formatter }, typescript = { prettier_formatter }, typescriptreact = { prettier_formatter, eslint_formatter }, scss = { prettier_formatter }, } - prettier formatter is prettierd - python formatter is `python -m autopep8` - lua formatter is `stylua` tags: formatting, efm, server, lanugages --- .../plugins/nvim-lspconfig/servers/efm.lua | 129 ++++++++++++------ 1 file changed, 89 insertions(+), 40 deletions(-) diff --git a/.config/nvim/lua/plugins/nvim-lspconfig/servers/efm.lua b/.config/nvim/lua/plugins/nvim-lspconfig/servers/efm.lua index 40037ae..922c305 100644 --- a/.config/nvim/lua/plugins/nvim-lspconfig/servers/efm.lua +++ b/.config/nvim/lua/plugins/nvim-lspconfig/servers/efm.lua @@ -17,58 +17,107 @@ local stylua = { formatCommand = 'stylua -s -', formatStdin = true } local black = { formatCommand = 'black --quiet -', formatStdin = true } --]===] -- +-- local lua_format_cmd = function() - local buf_name = vim.fn.fnameescape(vim.api.nvim_buf_get_name(0)) - return FORMATTERS_DIR .. "/stylua -s '" .. buf_name .. "'" + local buf_name = vim.fn.fnameescape(vim.api.nvim_buf_get_name(0)) + return FORMATTERS_DIR .. "/stylua -s '" .. buf_name .. "'" end local prettier_format_cmd = function(lang) - local buf_name = vim.fn.fnameescape(vim.api.nvim_buf_get_name(0)) - local command = "prettier --stdin-filepath "..buf_name - if lang==nil or string.len(lang)==0 then - return command - end + local buf_name = vim.fn.fnameescape(vim.api.nvim_buf_get_name(0)) + local command = "prettier --stdin-filepath " .. buf_name + if lang == nil or string.len(lang) == 0 then + return command + end +end + +local python_formatter = { formatCommand = "python -m autopep8 --indent-size=4 -", formatStdin = true } +--[===[ +--local prettier_formatter = function(lang) + return { formatCommand = prettier_format_cmd(lang), formatStdin = true } end +--]===] +-- +local function eslint_config_exists() + local eslintrc = vim.fn.glob(".eslintrc*", 0, 1) + + if not vim.tbl_isempty(eslintrc) then + return true + end + + if vim.fn.filereadable("package.json") then + if vim.fn.json_decode(vim.fn.readfile("package.json"))["eslintConfig"] then + return true + end + end -local python_formatter = { formatCommand = "python -m autopep8 -", formatStdin = true } -local prettier_formatter = function(lang) - return { formatCommand = prettier_format_cmd(lang), formatStdin = true } + return false end + +local eslint_formatter = { + lintCommand = "eslint_d -f unix --stdin --stdin-filename ${INPUT}", + lintStdin = true, + lintFormats = { "%f:%l:%c: %m" }, + lintIgnoreExitCode = true, + formatCommand = "eslint_d --fix-to-stdout --stdin --stdin-filename=${INPUT}", + formatStdin = true, +} +local prettier_formatter = { + formatCommand = "prettierd ${INPUT}", + formatStdin = true, + --rootPatterns = { ".git", "jsconfig.json", "tsconfig.json", "package.json" }, +} local lua_formatter = { formatCommand = FORMATTERS_DIR .. "/stylua -s -", formatStdin = true } + local languages = { - css = { prettier_formatter("css") }, - html = { prettier_formatter("html") }, - javascript = { prettier_formatter("") }, - javascriptreact = { prettier_formatter("") }, - json = { prettier_formatter("json") }, - lua = { lua_formatter }, - python = { python_formatter }, - typescript = { prettier_formatter("") }, - typescriptreact = { prettier_formatter("") }, - scss = { prettier_formatter("scss") }, + css = { prettier_formatter }, + html = { prettier_formatter }, + javascript = { prettier_formatter }, + javascriptreact = { prettier_formatter }, + json = { prettier_formatter }, + lua = { lua_formatter }, + python = { python_formatter }, + typescript = { prettier_formatter }, + typescriptreact = { prettier_formatter, eslint_formatter }, + scss = { prettier_formatter }, } M.setup = function(on_attach) - require("lspconfig").efm.setup({ - filetypes = { - "css", - "html", - "javascript", - "javascriptreact", - "json", - "lua", - "python", - "typescript", - "typescriptreact", - "scss", - }, - init_options = { documentFormatting = true }, - cmd = { LANGUAGE_SERVERS_DIR .. "/efm-langserver" }, - settings = { - languages = languages, - }, - single_file_support = true, - }) + require("lspconfig").efm.setup({ + on_attach = function(client, bufnr) + client.resolved_capabilities.document_formatting = true + client.resolved_capabilities.goto_definition = false + on_attach(client, bufnr) + end, + filetypes = { + "css", + "html", + "javascript", + "javascriptreact", + "json", + "lua", + "python", + "typescript", + "typescriptreact", + "scss", + }, + init_options = { documentFormatting = true }, + cmd = { LANGUAGE_SERVERS_DIR .. "/efm-langserver" }, + settings = { + languages = languages, + }, + --[===[ + root_dir = function() + if not eslint_config_exists() then + return nil + end + return vim.fn.getcwd() + end, + --]===] + root_dir = lspconfig.util.root_pattern(".git", "package.json", ".stylua.toml", ".pep8") or vim.loop.cwd(), + --root_dir = vim.loop.cwd, + single_file_support = true, + }) end return M From 7efa3e854b897046eb9ab6c5c2268e09de3e191b Mon Sep 17 00:00:00 2001 From: PrashanthaTP Date: Thu, 2 Dec 2021 22:30:01 +0530 Subject: [PATCH 42/50] Refactor(nvim): format some server files cssls,diagnosticls,sumneko_lua,tsserver --- .../plugins/nvim-lspconfig/servers/cssls.lua | 58 +++++++------- .../nvim-lspconfig/servers/diagnosticls.lua | 13 ++-- .../nvim-lspconfig/servers/sumneko_lua.lua | 2 + .../nvim-lspconfig/servers/tsserver.lua | 75 +++++++++++-------- 4 files changed, 81 insertions(+), 67 deletions(-) diff --git a/.config/nvim/lua/plugins/nvim-lspconfig/servers/cssls.lua b/.config/nvim/lua/plugins/nvim-lspconfig/servers/cssls.lua index 728af9f..66a07fa 100644 --- a/.config/nvim/lua/plugins/nvim-lspconfig/servers/cssls.lua +++ b/.config/nvim/lua/plugins/nvim-lspconfig/servers/cssls.lua @@ -2,36 +2,34 @@ local lspconfig = require("lspconfig") local M = {} M.setup = function(on_attach, capabilities) - local _capabilities = nil - if capabilities == nil then - _capabilities = vim.lsp.protocol.make_client_capabilities() - _capabilities.textDocument.completion.completionItem.snippetSupport = true - else - _capabilities = capabilities - end - lspconfig.cssls.setup({ - capabilities = _capabilities, - cmd = { "vscode-css-language-server.cmd", "--stdio" }, - filetypes = { "css", "scss", "less" }, - on_attach = on_attach, - --root_dir = root_pattern("package.json", ".git") or bufdir, - --https://stackoverflow.com/questions/64868071/i-cannot-activate-nvims-built-in-lsps-for-javascript-and-html - root_dir = function() - return vim.loop.cwd() - end, - settings = { - css = { - validate = true, - }, - less = { - validate = true, - }, - scss = { - validate = true, - }, - }, - single_file_support = true, - }) + local _capabilities = nil + if capabilities == nil then + _capabilities = vim.lsp.protocol.make_client_capabilities() + _capabilities.textDocument.completion.completionItem.snippetSupport = true + else + _capabilities = capabilities + end + lspconfig.cssls.setup({ + capabilities = _capabilities, + cmd = { "vscode-css-language-server.cmd", "--stdio" }, + filetypes = { "css", "scss", "less" }, + on_attach = on_attach, + --root_dir = root_pattern("package.json", ".git") or bufdir, + --https://stackoverflow.com/questions/64868071/i-cannot-activate-nvims-built-in-lsps-for-javascript-and-html + root_dir = lspconfig.util.root_pattern(".git", "package.json") or vim.loop.cwd, + settings = { + css = { + validate = true, + }, + less = { + validate = true, + }, + scss = { + validate = true, + }, + }, + single_file_support = true, + }) end return M diff --git a/.config/nvim/lua/plugins/nvim-lspconfig/servers/diagnosticls.lua b/.config/nvim/lua/plugins/nvim-lspconfig/servers/diagnosticls.lua index 07e71a7..4f2819d 100644 --- a/.config/nvim/lua/plugins/nvim-lspconfig/servers/diagnosticls.lua +++ b/.config/nvim/lua/plugins/nvim-lspconfig/servers/diagnosticls.lua @@ -1,3 +1,6 @@ +-- EFM Language Server +--https://phelipetls.github.io/posts/configuring-eslint-to-work-with-neovim-lsp/ + local nvim_lsp = require("lspconfig") local M = {} @@ -7,7 +10,6 @@ M.setup = function(on_attach, capabilities) capabilities = capabilities, cmd = { "diagnostic-languageserver.cmd", "--stdio" }, filetypes = { - "lua", "javascript", "javascriptreact", "json", @@ -17,6 +19,7 @@ M.setup = function(on_attach, capabilities) "less", "scss", "markdown", + "python", "pandoc", }, single_file_support = true, @@ -69,7 +72,7 @@ M.setup = function(on_attach, capabilities) }, prettier_python = { command = "python -m autopep8", - args = { "-" }, + args = { "%filename" }, }, }, formatFiletypes = { @@ -77,12 +80,12 @@ M.setup = function(on_attach, capabilities) javascript = "prettierd", javascriptreact = "prettierd", json = "prettier", - lua = "prettier_lua", - scss = "prettier", less = "prettier", + markdown = "prettier", + python = "prettier_python", + scss = "prettier", typescript = "prettierd", typescriptreact = "prettierd", - markdown = "prettier", }, }, }) diff --git a/.config/nvim/lua/plugins/nvim-lspconfig/servers/sumneko_lua.lua b/.config/nvim/lua/plugins/nvim-lspconfig/servers/sumneko_lua.lua index bb2d922..8905709 100644 --- a/.config/nvim/lua/plugins/nvim-lspconfig/servers/sumneko_lua.lua +++ b/.config/nvim/lua/plugins/nvim-lspconfig/servers/sumneko_lua.lua @@ -1,3 +1,5 @@ +--Sumneko Language Server +--formatting not supported local luaconfig = require('lspconfig') local M = {} diff --git a/.config/nvim/lua/plugins/nvim-lspconfig/servers/tsserver.lua b/.config/nvim/lua/plugins/nvim-lspconfig/servers/tsserver.lua index 7404543..1002b28 100644 --- a/.config/nvim/lua/plugins/nvim-lspconfig/servers/tsserver.lua +++ b/.config/nvim/lua/plugins/nvim-lspconfig/servers/tsserver.lua @@ -1,39 +1,50 @@ local M = {} -M.setup = function (on_attach,capabilities) -local on_attach_without_formatting = function(client,bufnr) - client.resolved_capabilities.document_formatting = false - on_attach(client,bufnr) -end - -local capabilities_for_tsserver = require('cmp_nvim_lsp').update_capabilities(vim.lsp.protocol.make_client_capabilities()) -capabilities.textDocument.completion.completionItem.snippetSupport = true -capabilities.textDocument.completion.completionItem.preselectSupport = true -capabilities.textDocument.completion.completionItem.insertReplaceSupport = true -capabilities.textDocument.completion.completionItem.labelDetailsSupport = true -capabilities.textDocument.completion.completionItem.deprecatedSupport = true -capabilities.textDocument.completion.completionItem.commitCharactersSupport = true -capabilities.textDocument.completion.completionItem.tagSupport = { valueSet = { 1 } } -capabilities.textDocument.completion.completionItem.resolveSupport = { - properties = { - 'documentation', - 'detail', - 'additionalTextEdits', - } -} - -require "lspconfig".tsserver.setup { - on_attach = on_attach_without_formatting, - capabilities=capabilities_for_tsserver, - cmd = { "typescript-language-server.cmd", "--stdio" }, - filetypes = { "javascript", "javascriptreact", "javascript.jsx", "typescript", "typescriptreact", "typescript.tsx" }, - init_options = { - hostInfo = "neovim" - }, - root_dir = require('lspconfig').util.root_pattern("package.json", "tsconfig.json", "jsconfig.json", ".git") or vim.loop.cwd +M.setup = function(on_attach, capabilities) + local on_attach_without_formatting = function(client, bufnr) + client.resolved_capabilities.document_formatting = false + if client.config.flags then + client.config.flags.allow_incremental_sync = true + end + on_attach(client, bufnr) + end -} + local capabilities_for_tsserver = require("cmp_nvim_lsp").update_capabilities( + vim.lsp.protocol.make_client_capabilities() + ) + capabilities.textDocument.completion.completionItem.snippetSupport = true + capabilities.textDocument.completion.completionItem.preselectSupport = true + capabilities.textDocument.completion.completionItem.insertReplaceSupport = true + capabilities.textDocument.completion.completionItem.labelDetailsSupport = true + capabilities.textDocument.completion.completionItem.deprecatedSupport = true + capabilities.textDocument.completion.completionItem.commitCharactersSupport = true + capabilities.textDocument.completion.completionItem.tagSupport = { valueSet = { 1 } } + capabilities.textDocument.completion.completionItem.resolveSupport = { + properties = { + "documentation", + "detail", + "additionalTextEdits", + }, + } + require("lspconfig").tsserver.setup({ + on_attach = on_attach_without_formatting, + capabilities = capabilities_for_tsserver, + cmd = { "typescript-language-server.cmd", "--stdio" }, + filetypes = { + "javascript", + "javascriptreact", + "javascript.jsx", + "typescript", + "typescriptreact", + "typescript.tsx", + }, + init_options = { + hostInfo = "neovim", + }, + root_dir = require("lspconfig").util.root_pattern("package.json", "tsconfig.json", "jsconfig.json", ".git") + or vim.loop.cwd, + }) end return M From e0e994bc46ff8d63244a89860af11d2f3a950924 Mon Sep 17 00:00:00 2001 From: PrashanthaTP Date: Thu, 2 Dec 2021 22:31:29 +0530 Subject: [PATCH 43/50] Feat(nvim): configure language servers more langs - pyright - clangd - cmake tags: LSP, servers, pyright, clangd, cmake, languages --- .../nvim/lua/plugins/nvim-lspconfig/init.lua | 13 ++++++++----- .../plugins/nvim-lspconfig/servers/clangd.lua | 15 +++++++++++++++ .../plugins/nvim-lspconfig/servers/cmake.lua | 18 ++++++++++++++++++ .../plugins/nvim-lspconfig/servers/pyright.lua | 15 +++++++++++++++ 4 files changed, 56 insertions(+), 5 deletions(-) create mode 100644 .config/nvim/lua/plugins/nvim-lspconfig/servers/pyright.lua diff --git a/.config/nvim/lua/plugins/nvim-lspconfig/init.lua b/.config/nvim/lua/plugins/nvim-lspconfig/init.lua index 69da355..064b624 100644 --- a/.config/nvim/lua/plugins/nvim-lspconfig/init.lua +++ b/.config/nvim/lua/plugins/nvim-lspconfig/init.lua @@ -20,8 +20,11 @@ for _, lsp in ipairs(servers) do end --]] vim.lsp.set_log_level("debug") -require("plugins.nvim-lspconfig.servers.cssls").setup(on_attach,capabilities) -require("plugins.nvim-lspconfig.servers.sumneko_lua").setup(on_attach,capabilities) ---require("plugins.nvim-lspconfig.servers.efm").setup(on_attach,capabilities) -require("plugins.nvim-lspconfig.servers.diagnosticls").setup(on_attach,capabilities) -require("plugins.nvim-lspconfig.servers.tsserver").setup(on_attach,capabilities) +require("plugins.nvim-lspconfig.servers.pyright").setup(on_attach, capabilities) +require("plugins.nvim-lspconfig.servers.clangd").setup(on_attach, capabilities) +require("plugins.nvim-lspconfig.servers.cmake").setup(on_attach, capabilities) +require("plugins.nvim-lspconfig.servers.cssls").setup(on_attach, capabilities) +require("plugins.nvim-lspconfig.servers.sumneko_lua").setup(on_attach, capabilities) +require("plugins.nvim-lspconfig.servers.tsserver").setup(on_attach, capabilities) +require("plugins.nvim-lspconfig.servers.efm").setup(on_attach, capabilities) +--require("plugins.nvim-lspconfig.servers.diagnosticls").setup(on_attach,capabilities) diff --git a/.config/nvim/lua/plugins/nvim-lspconfig/servers/clangd.lua b/.config/nvim/lua/plugins/nvim-lspconfig/servers/clangd.lua index e69de29..040a518 100644 --- a/.config/nvim/lua/plugins/nvim-lspconfig/servers/clangd.lua +++ b/.config/nvim/lua/plugins/nvim-lspconfig/servers/clangd.lua @@ -0,0 +1,15 @@ +local lspconfig = require("lspconfig") + +local M = {} + +M.setup = function(on_attach, capabilities) + lspconfig.clangd.setup({ + on_attach = on_attach, + capabilities = capabilities, + filetypes = { "c", "cpp", "objc", "objcpp" }, + root_dir = lspconfig.util.root_pattern(".git", "compile_commands.json", "compile_flags.txt", ".git", ".clangd") + or vim.loop.cwd, + single_file_support = true, + }) +end +return M diff --git a/.config/nvim/lua/plugins/nvim-lspconfig/servers/cmake.lua b/.config/nvim/lua/plugins/nvim-lspconfig/servers/cmake.lua index e69de29..1adf4d1 100644 --- a/.config/nvim/lua/plugins/nvim-lspconfig/servers/cmake.lua +++ b/.config/nvim/lua/plugins/nvim-lspconfig/servers/cmake.lua @@ -0,0 +1,18 @@ +local lspconfig = require("lspconfig") + +local M = {} + +M.setup = function(on_attach, capabilities) + lspconfig.clangd.setup({ + on_attach = on_attach, + capabilities = capabilities, + filetypes = { "cmake" }, + init_options = { + buildDirectory = "build", + }, + root_dir = lspconfig.util.root_pattern(".git", "compile_commands.json", "build/") or vim.loop.cwd, + single_file_support = true, + }) +end + +return M diff --git a/.config/nvim/lua/plugins/nvim-lspconfig/servers/pyright.lua b/.config/nvim/lua/plugins/nvim-lspconfig/servers/pyright.lua new file mode 100644 index 0000000..868ded6 --- /dev/null +++ b/.config/nvim/lua/plugins/nvim-lspconfig/servers/pyright.lua @@ -0,0 +1,15 @@ +local lspconfig = require("lspconfig") + +local M = {} + +M.setup = function(on_attach, capabilities) + lspconfig.pyright.setup({ + on_attach = on_attach, + capabilities = capabilities, + root_dir = lspconfig.util.root_pattern(".git", "setup.py", "setup.cfg", "pyproject.toml", "requirements.txt") + or vim.loop.cwd, + single_file_support = true, + }) +end + +return M From 4997c23f2c99f6b2beb5c08a875b5fb9ffa97a2a Mon Sep 17 00:00:00 2001 From: PrashanthaTP Date: Thu, 2 Dec 2021 22:35:11 +0530 Subject: [PATCH 44/50] Fix(nvim): reposition heturn statement for get_os_name tags : utils, lua --- .config/nvim/lua/utils/init.lua | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/.config/nvim/lua/utils/init.lua b/.config/nvim/lua/utils/init.lua index 0ae9a7b..bb1be11 100644 --- a/.config/nvim/lua/utils/init.lua +++ b/.config/nvim/lua/utils/init.lua @@ -46,8 +46,8 @@ M.get_os_name = function() system_name = M.windows else system_name = M.unknown_os - return system_name end + return system_name end return M -- module table From 8dceca7b9fe37b9d67315795906973783a37c15b Mon Sep 17 00:00:00 2001 From: PrashanthaTP Date: Thu, 2 Dec 2021 22:35:41 +0530 Subject: [PATCH 45/50] Chore(nvim): customize lualine --- .config/nvim/lua/plugins/lualine/init.lua | 47 +++++++++++++++++------ 1 file changed, 35 insertions(+), 12 deletions(-) diff --git a/.config/nvim/lua/plugins/lualine/init.lua b/.config/nvim/lua/plugins/lualine/init.lua index 4c60644..6d8b48c 100644 --- a/.config/nvim/lua/plugins/lualine/init.lua +++ b/.config/nvim/lua/plugins/lualine/init.lua @@ -1,6 +1,7 @@ -- Eviline config for lualine -- Author: shadmansaleh -- Credit: glepnir +-- modified-by: PrashanthaTP local lualine = require("lualine") -- Color table for highlights @@ -37,8 +38,12 @@ local conditions = { local config = { options = { -- Disable sections and component separators - component_separators = "", + -- + component_separators = "|", section_separators = "", + -- section_separators = { left = "", right = "" }, + -- component_separators = { left = "", right = "" }, + --theme = "wombat", theme = { -- We are going to use lualine_c an lualine_x as left and -- right section. Both are highlighted by c theme . So we @@ -49,7 +54,7 @@ local config = { }, sections = { -- these are to remove the defaults - lualine_a = {}, + lualine_a = { "mode" }, lualine_b = {}, lualine_y = {}, lualine_z = {}, @@ -78,6 +83,7 @@ local function ins_right(component) table.insert(config.sections.lualine_x, component) end +--[===[ ins_left({ function() return "▊" @@ -85,7 +91,8 @@ ins_left({ color = { fg = colors.blue }, -- Sets highlighting of component padding = { left = 0, right = 1 }, -- We don't need space before this }) - +--]===] +--[===[ ins_left({ -- mode component function() @@ -118,11 +125,13 @@ ins_left({ color = "LualineMode", padding = { right = 1 }, }) - +--]===] +-- ins_left({ "filename", cond = conditions.buffer_not_empty, - color = { fg = colors.magenta, gui = "bold" }, + --color = { fg = colors.magenta, gui = "bold" }, + color = { fg = colors.green, gui = "bold" }, }) ins_left({ @@ -133,13 +142,24 @@ ins_left({ ins_left({ "diagnostics", + -- table of diagnostic sources, available sources: + -- 'nvim_lsp', 'nvim', 'coc', 'ale', 'vim_lsp' + -- Or a function that returns a table like + -- {error=error_cnt, warn=warn_cnt, info=info_cnt, hint=hint_cnt} sources = { "nvim_lsp" }, - symbols = { error = " ", warn = " ", info = " " }, + -- displays diagnostics from defined severity + sections = { "error", "warn", "info", "hint" }, diagnostics_color = { - color_error = { fg = colors.red }, - color_warn = { fg = colors.yellow }, - color_info = { fg = colors.cyan }, + -- Same values like general color option can be used here. + error = { fg = colors.red }, -- changes diagnostic's error color + warn = { fg = colors.orange }, -- changes diagnostic's warn color + info = { fg = colors.blue }, -- Changes diagnostic's info color + hint = { fg = colors.yellow }, -- Changes diagnostic's hint color }, + symbols = { error = "E", warn = "W", info = "I", hint = "H" }, + colored = true, -- displays diagnostics status in color if set to true + update_in_insert = false, -- Update diagnostics in insert mode + always_visible = false, -- Show diagnostics even if count is 0, boolean or function returning boolean }) -- Insert mid section. You can make any number of sections in neovim :) @@ -168,7 +188,8 @@ ins_right({ return msg end, icon = " LSP:", - color = { fg = "#ffffff", gui = "bold" }, + --color = { fg = "#ffffff", gui = "bold" }, + color = { fg = colors.green, gui = "bold" }, }) ins_right({ "location" }) @@ -192,7 +213,8 @@ ins_right({ ins_right({ "diff", -- Is it me or the symbol for modified us really weird - symbols = { added = " ", modified = "柳 ", removed = " " }, + --symbols = { added = " ", modified = " 柳 ", removed = " " }, + symbols = { added = " ", modified = "ﮐ ", removed = " " }, diff_color = { added = { fg = colors.green }, modified = { fg = colors.orange }, @@ -206,6 +228,7 @@ ins_right({ "filesize", cond = conditions.buffer_not_empty, }) +--[===[ ins_right({ function() return "▊" @@ -213,6 +236,6 @@ ins_right({ color = { fg = colors.blue }, padding = { left = 1 }, }) - +--]===] -- Now don't forget to initialize lualine lualine.setup(config) From d5e1bb1cc466a81e5cd17f3d089feac5514ed8d6 Mon Sep 17 00:00:00 2001 From: PrashanthaTP Date: Thu, 2 Dec 2021 22:36:50 +0530 Subject: [PATCH 46/50] Feat(nvim): use ripgrep for telescope findfiles tags: telescope, rg, findfiles --- .../nvim/lua/plugins/nvim-telescope/init.lua | 62 +++++++++---------- 1 file changed, 31 insertions(+), 31 deletions(-) diff --git a/.config/nvim/lua/plugins/nvim-telescope/init.lua b/.config/nvim/lua/plugins/nvim-telescope/init.lua index 56a87ca..e999bb5 100644 --- a/.config/nvim/lua/plugins/nvim-telescope/init.lua +++ b/.config/nvim/lua/plugins/nvim-telescope/init.lua @@ -1,5 +1,5 @@ vim.cmd([[ -nnoremap ff lua require('telescope.builtin').find_files() +nnoremap ff lua require('telescope.builtin').find_files(find_command = { "rg", "--files", "--hidden", "--follow"}) nnoremap fg lua require('telescope.builtin').live_grep() nnoremap fb lua require('telescope.builtin').buffers() nnoremap fh lua require('telescope.builtin').help_tags() @@ -12,37 +12,37 @@ local actions = require("telescope.actions") local Job = require("plenary.job") local new_maker = function(filepath, bufnr, opts) - filepath = vim.fn.expand(filepath) - Job - :new({ - command = "file", - args = { "--mime-type", "-b", filepath }, - on_exit = function(j) - local mime_type = vim.split(j:result()[1], "/")[1] - if mime_type == "text" then - previewers.buffer_previewer_maker(filepath, bufnr, opts) - else - -- maybe we want to write something to the buffer here - vim.schedule(function() - vim.api.nvim_buf_set_lines(bufnr, 0, -1, false, { "BINARY" }) - end) - end - end, - }) - :sync() + filepath = vim.fn.expand(filepath) + Job + :new({ + command = "file", + args = { "--mime-type", "-b", filepath }, + on_exit = function(j) + local mime_type = vim.split(j:result()[1], "/")[1] + if mime_type == "text" then + previewers.buffer_previewer_maker(filepath, bufnr, opts) + else + -- maybe we want to write something to the buffer here + vim.schedule(function() + vim.api.nvim_buf_set_lines(bufnr, 0, -1, false, { "BINARY" }) + end) + end + end, + }) + :sync() end require("telescope").setup({ - defaults = { - --buffer_previewer_maker = new_maker, - file_ignore_patterns = { "node_modules", "^vim\\view\\", "^vim\\backup\\", "^vim\\swap\\" }, - mappings = { - i = { - [""] = actions.close, - }, - n = { - ["q"] = actions.close, - }, - }, - }, + defaults = { + --buffer_previewer_maker = new_maker, + file_ignore_patterns = { "node_modules", "^vim\\view\\", "^vim\\backup\\", "^vim\\swap\\" }, + mappings = { + i = { + [""] = actions.close, + }, + n = { + ["q"] = actions.close, + }, + }, + }, }) From cccda1f088484b12f17911cb4f236f2671acad41 Mon Sep 17 00:00:00 2001 From: PrashanthaTP Date: Fri, 3 Dec 2021 22:18:30 +0530 Subject: [PATCH 47/50] Fix(nvim): rectify fallback option for root_dir change vim.loop.cwd to vim.loop.cwd() tags: LSP, root_dir, servers --- .../plugins/nvim-lspconfig/servers/clangd.lua | 2 +- .../plugins/nvim-lspconfig/servers/cmake.lua | 2 +- .../plugins/nvim-lspconfig/servers/cssls.lua | 2 +- .../nvim-lspconfig/servers/pyright.lua | 2 +- .../nvim-lspconfig/servers/tsserver.lua | 85 ++++++++++--------- 5 files changed, 47 insertions(+), 46 deletions(-) diff --git a/.config/nvim/lua/plugins/nvim-lspconfig/servers/clangd.lua b/.config/nvim/lua/plugins/nvim-lspconfig/servers/clangd.lua index 040a518..7ef8b08 100644 --- a/.config/nvim/lua/plugins/nvim-lspconfig/servers/clangd.lua +++ b/.config/nvim/lua/plugins/nvim-lspconfig/servers/clangd.lua @@ -8,7 +8,7 @@ M.setup = function(on_attach, capabilities) capabilities = capabilities, filetypes = { "c", "cpp", "objc", "objcpp" }, root_dir = lspconfig.util.root_pattern(".git", "compile_commands.json", "compile_flags.txt", ".git", ".clangd") - or vim.loop.cwd, + or vim.loop.cwd(), single_file_support = true, }) end diff --git a/.config/nvim/lua/plugins/nvim-lspconfig/servers/cmake.lua b/.config/nvim/lua/plugins/nvim-lspconfig/servers/cmake.lua index 1adf4d1..8fbe929 100644 --- a/.config/nvim/lua/plugins/nvim-lspconfig/servers/cmake.lua +++ b/.config/nvim/lua/plugins/nvim-lspconfig/servers/cmake.lua @@ -10,7 +10,7 @@ M.setup = function(on_attach, capabilities) init_options = { buildDirectory = "build", }, - root_dir = lspconfig.util.root_pattern(".git", "compile_commands.json", "build/") or vim.loop.cwd, + root_dir = lspconfig.util.root_pattern(".git", "compile_commands.json", "build/") or vim.loop.cwd(), single_file_support = true, }) end diff --git a/.config/nvim/lua/plugins/nvim-lspconfig/servers/cssls.lua b/.config/nvim/lua/plugins/nvim-lspconfig/servers/cssls.lua index 66a07fa..7c20af7 100644 --- a/.config/nvim/lua/plugins/nvim-lspconfig/servers/cssls.lua +++ b/.config/nvim/lua/plugins/nvim-lspconfig/servers/cssls.lua @@ -16,7 +16,7 @@ M.setup = function(on_attach, capabilities) on_attach = on_attach, --root_dir = root_pattern("package.json", ".git") or bufdir, --https://stackoverflow.com/questions/64868071/i-cannot-activate-nvims-built-in-lsps-for-javascript-and-html - root_dir = lspconfig.util.root_pattern(".git", "package.json") or vim.loop.cwd, + root_dir = lspconfig.util.root_pattern(".git", "package.json") or vim.loop.cwd(), settings = { css = { validate = true, diff --git a/.config/nvim/lua/plugins/nvim-lspconfig/servers/pyright.lua b/.config/nvim/lua/plugins/nvim-lspconfig/servers/pyright.lua index 868ded6..3cf44cf 100644 --- a/.config/nvim/lua/plugins/nvim-lspconfig/servers/pyright.lua +++ b/.config/nvim/lua/plugins/nvim-lspconfig/servers/pyright.lua @@ -7,7 +7,7 @@ M.setup = function(on_attach, capabilities) on_attach = on_attach, capabilities = capabilities, root_dir = lspconfig.util.root_pattern(".git", "setup.py", "setup.cfg", "pyproject.toml", "requirements.txt") - or vim.loop.cwd, + or vim.loop.cwd(), single_file_support = true, }) end diff --git a/.config/nvim/lua/plugins/nvim-lspconfig/servers/tsserver.lua b/.config/nvim/lua/plugins/nvim-lspconfig/servers/tsserver.lua index 1002b28..c1acb0f 100644 --- a/.config/nvim/lua/plugins/nvim-lspconfig/servers/tsserver.lua +++ b/.config/nvim/lua/plugins/nvim-lspconfig/servers/tsserver.lua @@ -1,50 +1,51 @@ local M = {} M.setup = function(on_attach, capabilities) - local on_attach_without_formatting = function(client, bufnr) - client.resolved_capabilities.document_formatting = false - if client.config.flags then - client.config.flags.allow_incremental_sync = true - end - on_attach(client, bufnr) - end + local on_attach_without_formatting = function(client, bufnr) + client.resolved_capabilities.document_formatting = false + if client.config.flags then + client.config.flags.allow_incremental_sync = true + end + on_attach(client, bufnr) + end - local capabilities_for_tsserver = require("cmp_nvim_lsp").update_capabilities( - vim.lsp.protocol.make_client_capabilities() - ) - capabilities.textDocument.completion.completionItem.snippetSupport = true - capabilities.textDocument.completion.completionItem.preselectSupport = true - capabilities.textDocument.completion.completionItem.insertReplaceSupport = true - capabilities.textDocument.completion.completionItem.labelDetailsSupport = true - capabilities.textDocument.completion.completionItem.deprecatedSupport = true - capabilities.textDocument.completion.completionItem.commitCharactersSupport = true - capabilities.textDocument.completion.completionItem.tagSupport = { valueSet = { 1 } } - capabilities.textDocument.completion.completionItem.resolveSupport = { - properties = { - "documentation", - "detail", - "additionalTextEdits", - }, - } + local capabilities_for_tsserver = require("cmp_nvim_lsp").update_capabilities( + vim.lsp.protocol.make_client_capabilities() + ) + capabilities.textDocument.completion.completionItem.snippetSupport = true + capabilities.textDocument.completion.completionItem.preselectSupport = true + capabilities.textDocument.completion.completionItem.insertReplaceSupport = true + capabilities.textDocument.completion.completionItem.labelDetailsSupport = true + capabilities.textDocument.completion.completionItem.deprecatedSupport = true + capabilities.textDocument.completion.completionItem.commitCharactersSupport = true + capabilities.textDocument.completion.completionItem.tagSupport = { valueSet = { 1 } } + capabilities.textDocument.completion.completionItem.resolveSupport = { + properties = { + "documentation", + "detail", + "additionalTextEdits", + }, + } - require("lspconfig").tsserver.setup({ - on_attach = on_attach_without_formatting, - capabilities = capabilities_for_tsserver, - cmd = { "typescript-language-server.cmd", "--stdio" }, - filetypes = { - "javascript", - "javascriptreact", - "javascript.jsx", - "typescript", - "typescriptreact", - "typescript.tsx", - }, - init_options = { - hostInfo = "neovim", - }, - root_dir = require("lspconfig").util.root_pattern("package.json", "tsconfig.json", "jsconfig.json", ".git") - or vim.loop.cwd, - }) + require("lspconfig").tsserver.setup({ + on_attach = on_attach_without_formatting, + capabilities = capabilities_for_tsserver, + cmd = { "typescript-language-server.cmd", "--stdio" }, + filetypes = { + "javascript", + "javascriptreact", + "javascript.jsx", + "typescript", + "typescriptreact", + "typescript.tsx", + }, + init_options = { + hostInfo = "neovim", + }, + root_dir = require("lspconfig").util.root_pattern("package.json", "tsconfig.json", "jsconfig.json", ".git") + or vim.loop.cwd(), + single_file_support = true, + }) end return M From 391cae0989efb21385585c2cb750f833f5af7eab Mon Sep 17 00:00:00 2001 From: PrashanthaTP Date: Fri, 3 Dec 2021 22:23:42 +0530 Subject: [PATCH 48/50] Dev(nvim): add .stylua.toml config file for stylua formatter --- .config/nvim/.stylua.toml | 3 +++ 1 file changed, 3 insertions(+) create mode 100644 .config/nvim/.stylua.toml diff --git a/.config/nvim/.stylua.toml b/.config/nvim/.stylua.toml new file mode 100644 index 0000000..6894fa6 --- /dev/null +++ b/.config/nvim/.stylua.toml @@ -0,0 +1,3 @@ +column_width = 120 +indent_type = "Spaces" +indent_width = 2 From c5ad0edfefd58ed99b6e4d9327d64c433135a2e2 Mon Sep 17 00:00:00 2001 From: PrashanthaTP Date: Sat, 4 Dec 2021 12:31:44 +0530 Subject: [PATCH 49/50] Chore(nvim): reformat lsp util file document formatted using Stylua language server --- .../nvim/lua/plugins/nvim-lspconfig/utils.lua | 161 +++++++++--------- 1 file changed, 82 insertions(+), 79 deletions(-) diff --git a/.config/nvim/lua/plugins/nvim-lspconfig/utils.lua b/.config/nvim/lua/plugins/nvim-lspconfig/utils.lua index b8bfba4..57bd7fc 100644 --- a/.config/nvim/lua/plugins/nvim-lspconfig/utils.lua +++ b/.config/nvim/lua/plugins/nvim-lspconfig/utils.lua @@ -1,89 +1,90 @@ +local lspconfig = require("lspconfig") local t = require("utils").replace_termcodes local M = {} M.set_keymappings = function(bufnr) - local buf_set_keymap = function(...) - vim.api.nvim_buf_set_keymap(bufnr, ...) - end + local buf_set_keymap = function(...) + vim.api.nvim_buf_set_keymap(bufnr, ...) + end - local opts = { noremap = true, silent = true } + local opts = { noremap = true, silent = true } - -- See `:help vim.lsp.*` for documentation on any of the below functions - buf_set_keymap("n", "gD", "lua vim.lsp.buf.declaration()", opts) - buf_set_keymap("n", "gd", "lua vim.lsp.buf.definition()", opts) - buf_set_keymap("n", "K", "lua vim.lsp.buf.hover()", opts) - buf_set_keymap("n", "gi", "lua vim.lsp.buf.implementation()", opts) - buf_set_keymap("n", t(""), "lua vim.lsp.buf.signature_help()", opts) - buf_set_keymap("n", t("wa"), "lua vim.lsp.buf.add_workspace_folder()", opts) - buf_set_keymap("n", t("wr"), "lua vim.lsp.buf.remove_workspace_folder()", opts) - buf_set_keymap("n", t("wl"), "lua print(vim.inspect(vim.lsp.buf.list_workspace_folders()))", opts) - buf_set_keymap("n", t("D"), "lua vim.lsp.buf.type_definition()", opts) - buf_set_keymap("n", t("rn"), "lua vim.lsp.buf.rename()", opts) - buf_set_keymap("n", t("ca"), "lua vim.lsp.buf.code_action()", opts) - buf_set_keymap("n", "gr", "lua vim.lsp.buf.references()", opts) - buf_set_keymap("n", t("e"), "lua vim.lsp.diagnostic.show_line_diagnostics()", opts) - buf_set_keymap("n", "[d", "lua vim.lsp.diagnostic.goto_prev()", opts) - buf_set_keymap("n", "]d", "lua vim.lsp.diagnostic.goto_next()", opts) - buf_set_keymap("n", t("q"), "lua vim.lsp.diagnostic.set_loclist()", opts) - buf_set_keymap("n", t("wf"), "lua vim.lsp.buf.formatting()", opts) - -- formatting + -- See `:help vim.lsp.*` for documentation on any of the below functions + buf_set_keymap("n", "gD", "lua vim.lsp.buf.declaration()", opts) + buf_set_keymap("n", "gd", "lua vim.lsp.buf.definition()", opts) + buf_set_keymap("n", "K", "lua vim.lsp.buf.hover()", opts) + buf_set_keymap("n", "gi", "lua vim.lsp.buf.implementation()", opts) + buf_set_keymap("n", t(""), "lua vim.lsp.buf.signature_help()", opts) + buf_set_keymap("n", t("wa"), "lua vim.lsp.buf.add_workspace_folder()", opts) + buf_set_keymap("n", t("wr"), "lua vim.lsp.buf.remove_workspace_folder()", opts) + buf_set_keymap("n", t("wl"), "lua print(vim.inspect(vim.lsp.buf.list_workspace_folders()))", opts) + buf_set_keymap("n", t("D"), "lua vim.lsp.buf.type_definition()", opts) + buf_set_keymap("n", t("rn"), "lua vim.lsp.buf.rename()", opts) + buf_set_keymap("n", t("ca"), "lua vim.lsp.buf.code_action()", opts) + buf_set_keymap("n", "gr", "lua vim.lsp.buf.references()", opts) + buf_set_keymap("n", t("e"), "lua vim.lsp.diagnostic.show_line_diagnostics()", opts) + buf_set_keymap("n", "[d", "lua vim.lsp.diagnostic.goto_prev()", opts) + buf_set_keymap("n", "]d", "lua vim.lsp.diagnostic.goto_next()", opts) + buf_set_keymap("n", t("q"), "lua vim.lsp.diagnostic.set_loclist()", opts) + buf_set_keymap("n", t("wf"), "lua vim.lsp.buf.formatting()", opts) + -- formatting end -- Use an on_attach function to only map the following keys -- after the language server attaches to the current buffer M.on_attach = function(client, bufnr) - local buf_set_option = function(...) - vim.api.nvim_buf_set_option(bufnr, ...) - end - -- Enable completion triggered by - buf_set_option("omnifunc", "v:lua.vim.lsp.omnifunc") - -- Mappings. - M.set_keymappings(bufnr) + local buf_set_option = function(...) + vim.api.nvim_buf_set_option(bufnr, ...) + end + -- Enable completion triggered by + buf_set_option("omnifunc", "v:lua.vim.lsp.omnifunc") + -- Mappings. + M.set_keymappings(bufnr) - --[[ if client.name == 'tsserver' then + --[[ if client.name == 'tsserver' then client.resolved_capabilities.document_formatting = false end --]] - if client.resolved_capabilities.document_formatting then - vim.api.nvim_command([[augroup FORMAT]]) - vim.api.nvim_command([[autocmd! * ]]) - vim.api.nvim_command([[autocmd BufWritePre lua vim.lsp.buf.formatting_seq_sync()]]) - vim.api.nvim_command([[augroup end]]) - end - vim.lsp.handlers["textDocument/publishDiagnostics"] = vim.lsp.with(vim.lsp.diagnostic.on_publish_diagnostics, { - virtual_text = { spacing = 4, prefix = "" }, - signs = true, - underline = true, - update_in_insert = true, - }) - --protocol.SymbolKind = { } - vim.lsp.protocol.completionItemKind = { - "", -- Text - "", -- Method - "", -- Function - "", -- Constructor - "", -- Field - "", -- Variable - "", -- Class - "ﰮ", -- Interface - "", -- Module - "", -- Property - "", -- Unit - "", -- Value - "", -- Enum - "", -- Keyword - "﬌", -- Snippet - "", -- Color - "", -- File - "", -- Reference - "", -- Folder - "", -- EnumMember - "", -- Constant - "", -- Struct - "", -- Event - "ﬦ", -- Operator - "", -- TypeParameter - } + if client.resolved_capabilities.document_formatting then + vim.api.nvim_command([[augroup FORMAT]]) + vim.api.nvim_command([[autocmd! * ]]) + vim.api.nvim_command([[autocmd BufWritePre lua vim.lsp.buf.formatting_seq_sync()]]) + vim.api.nvim_command([[augroup end]]) + end + vim.lsp.handlers["textDocument/publishDiagnostics"] = vim.lsp.with(vim.lsp.diagnostic.on_publish_diagnostics, { + virtual_text = { spacing = 4, prefix = "" }, + signs = true, + underline = true, + update_in_insert = true, + }) + --protocol.SymbolKind = { } + vim.lsp.protocol.completionItemKind = { + "", -- Text + "", -- Method + "", -- Function + "", -- Constructor + "", -- Field + "", -- Variable + "", -- Class + "ﰮ", -- Interface + "", -- Module + "", -- Property + "", -- Unit + "", -- Value + "", -- Enum + "", -- Keyword + "﬌", -- Snippet + "", -- Color + "", -- File + "", -- Reference + "", -- Folder + "", -- EnumMember + "", -- Constant + "", -- Struct + "", -- Event + "ﬦ", -- Operator + "", -- TypeParameter + } end --[==[== on attach add formatting functionality @@ -96,14 +97,16 @@ end end --]==] local capabilities = require("cmp_nvim_lsp").update_capabilities(vim.lsp.protocol.make_client_capabilities()) + M.get_capabilities = function() - local _capabilities = nil - if capabilities == nil then - _capabilities = vim.lsp.protocol.make_client_capabilities() - _capabilities.textDocument.completion.completionItem.snippetSupport = true - else - _capabilities = capabilities - end - return _capabilities + local _capabilities = nil + if capabilities == nil then + _capabilities = vim.lsp.protocol.make_client_capabilities() + _capabilities.textDocument.completion.completionItem.snippetSupport = true + else + _capabilities = capabilities + end + return _capabilities end + return M From 78823a038e1ecb1739532f913cf3c5a03a335eb5 Mon Sep 17 00:00:00 2001 From: PrashanthaTP Date: Sat, 4 Dec 2021 12:39:25 +0530 Subject: [PATCH 50/50] Feat(powershell): add head,nvp utils;update FZFcmd tags: fzf, bat, truecolors, git-utils, head --- .../Microsoft.PowerShell_profile.ps1 | 18 +++++++++++++++++- 1 file changed, 17 insertions(+), 1 deletion(-) diff --git a/Documents/WindowsPowerShell/Microsoft.PowerShell_profile.ps1 b/Documents/WindowsPowerShell/Microsoft.PowerShell_profile.ps1 index eeed8fb..ac6d2eb 100644 --- a/Documents/WindowsPowerShell/Microsoft.PowerShell_profile.ps1 +++ b/Documents/WindowsPowerShell/Microsoft.PowerShell_profile.ps1 @@ -61,7 +61,16 @@ function cd_proj_dir{ cd $env:PROJ_DIR } set-alias -name cdp -value cd_proj_dir -$env:FZF_DEFAULT_COMMAND = 'rg --files --hidden --follow --no-ignore-vcs' + +<# +# TRUE colors with COLORTERM option for bat +# Discussions related to True colors +# - https://github.com/junegunn/fzf.vim/issues/1179 +# - https://github.com/macvim-dev/macvim/issues/1177 +# - https://github.com/sharkdp/bat/issues/634 +##> +$env:FZF_DEFAULT_COMMAND = 'COLORTERM=truecolor rg --files --hidden --follow --ignore-vcs' + $env:FZF_DEFAULT_OPTS='--height 40% --layout=reverse --ansi --border --preview "bat --color=always {1}"' function open_wiki{ @@ -70,6 +79,9 @@ function open_wiki{ nvim $(& $cmd $dir -type f -name '\*.md' -not -path '\*/.git/\*'| fzf) } +function nvp{ + nvim $PROFILE +} ########################################################### # FZY #set-alias -name fzy -value $env:ProgramFiles/Git/usr/bin/fzy.exe @@ -96,6 +108,10 @@ function lsg{ run_git_utility "ls" $args } +function head{ + run_git_utility "head" $args +} + function grep{ run_git_utility "grep" $args }