From fce46ed7e852dfc60466c50f348c0c2c7caba7fc Mon Sep 17 00:00:00 2001 From: Urbain Vaes Date: Tue, 10 Aug 2021 10:32:16 +0200 Subject: Minor change --- vim/.config/nvim/plugin | 1 + vim/.vim/after/plugin/status.vim | 46 ++++++++ vim/.vim/plugin/search.vim | 52 +++++++++ vim/.vimrc | 238 +++++++++++---------------------------- zsh/.zshrc | 7 +- 5 files changed, 168 insertions(+), 176 deletions(-) create mode 120000 vim/.config/nvim/plugin create mode 100644 vim/.vim/after/plugin/status.vim create mode 100644 vim/.vim/plugin/search.vim diff --git a/vim/.config/nvim/plugin b/vim/.config/nvim/plugin new file mode 120000 index 0000000..971c377 --- /dev/null +++ b/vim/.config/nvim/plugin @@ -0,0 +1 @@ +../../../../.vim/plugin \ No newline at end of file diff --git a/vim/.vim/after/plugin/status.vim b/vim/.vim/after/plugin/status.vim new file mode 100644 index 0000000..54c5bb7 --- /dev/null +++ b/vim/.vim/after/plugin/status.vim @@ -0,0 +1,46 @@ +" Depends on vim-flagship +set showtabline=2 +let g:tabprefix = "" +let g:tablabel = "%N%{flagship#tabmodified()} %{TabCwd(v:lnum) != '' ? pathshorten(TabCwd(v:lnum)) : ''}" +let g:flagship_skip = 'FugitiveStatusline' + +function! Mixed_indent() + let l:spaces=search('\v(^ +)','n') + let l:tabs=search('\v(^\t+)','n') + return (l:spaces * l:tabs > 0) +endfunction + +function! GlobalCwd() + return getcwd(-1, -1) +endfunction + +function! TabCwd(number) + if haslocaldir(-1, a:number) + return getcwd(-1, a:number) + endif + return "" +endfunction + +function! WinCwd() + if haslocaldir(0) + return getcwd() + endif + return "" +endfunction + +augroup myflags + let status_line_bg = synIDattr(hlID("StatusLine"), "fg") + let status_line_fg = synIDattr(hlID("StatusLine"), "bg") + exe "highlight MyGlobals ctermfg=255 ctermbg=".status_line_bg + highlight MyGlobals ctermfg=255 ctermbg=240 + + autocmd! + autocmd CmdwinEnter,BufEnter,BufRead,BufWritePost * let b:trailing=search('\s\+$','n') + autocmd CmdwinEnter,BufEnter,BufRead,BufWritePost * let b:mixed=Mixed_indent() + autocmd User Flags call Hoist("buffer", "%{FugitiveHead('') != '' ? '['.FugitiveHead('').']' : ''}") + autocmd User Flags call Hoist("buffer", "%{b:trailing?'[tw]':''}") + autocmd User Flags call Hoist("buffer", "%{b:mixed?'[mixed]':''}") + autocmd User Flags call Hoist("buffer", "%{&paste?'[paste]':''}") + autocmd User Flags call Hoist("window", "%{WinCwd() != '' ? '['.WinCwd().']' : ''}") + autocmd User Flags call Hoist("global", {"hl": "MyGlobals"}, "[%{pathshorten(GlobalCwd())}, %{g:my_searchprgs[g:my_searchprg]}, %{g:my_findprgs[g:my_findprg]}]") +augroup END diff --git a/vim/.vim/plugin/search.vim b/vim/.vim/plugin/search.vim new file mode 100644 index 0000000..b4e1054 --- /dev/null +++ b/vim/.vim/plugin/search.vim @@ -0,0 +1,52 @@ +" http://vim.wikia.com/wiki/Searching_for_files +function! MySearch(...) + let l:prevgrepprg=&grepprg + let l:prevgrepformat=&grepformat + if a:1 == "Rg" + set grepprg=rg\ -uu\ --vimgrep + set grepformat=%f:%l:%c:%m + elseif a:1 == "Gnufind" + set grepprg=find\ .\ -name + set grepformat=%f + elseif a:1 == "Gitfind" + set grepprg=git\ ls-files\ -i\ -x + set grepformat=%f + endif + execute 'silent grep!' a:2 | cwindow | redraw! + let &grepprg=l:prevgrepprg + let &grepformat=l:prevgrepformat +endfun + +command! -nargs=+ -complete=file_in_path Rg call MySearch("Rg", ) +command! -nargs=+ -complete=file_in_path Gnufind call MySearch("Gnufind", ) +command! -nargs=+ -complete=file_in_path Gitfind call MySearch("Gitfind", ) +command! -nargs=+ -complete=file_in_path GitGrep execute 'silent Ggrep!' | cw | redraw! +command! -nargs=+ -complete=file_in_path VimGrep execute 'silent vimgrep!' | cw | redraw! + +" Default search and find programs +function! FillSearch(...) + if a:0 == 0 + let l:filltext = "" + else + let l:is_visual=(a:1 == "v") + let l:line=getline(l:is_visual ? "'<" : "'[") + let [line1,col1] = getpos(l:is_visual ? "'<" : "'[")[1:2] + let [line2,col2] = getpos(l:is_visual ? "'>" : "']")[1:2] + let l:filltext =l:line[col1 - 1: col2 - 1] + endif + call feedkeys(':' . g:my_fillprg . ' "' . l:filltext . '"'."\") +endfunction + +let g:my_searchprgs = ['Rg', 'GitGrep', 'VimGrep'] +let g:my_findprgs = ['Gnufind', 'Gitfind'] +let g:my_searchprg = 0 +let g:my_findprg = 0 + +nnoremap g/ :let g:my_fillprg=g:my_searchprgs[g:my_searchprg]:set opfunc=FillSearchg@ +nnoremap ,g :let g:my_fillprg=g:my_searchprgs[g:my_searchprg]:call FillSearch() +xnoremap ,g :let g:my_fillprg=g:my_searchprgs[g:my_searchprg]:call FillSearch(visualmode()) +nnoremap ,f :let g:my_fillprg=g:my_findprgs[g:my_findprg]:call FillSearch() + +" Cycle search / find prgs +nnoremap cog :let g:my_searchprg=(g:my_searchprg+1)%len(g:my_searchprgs):let &ro = &ro +nnoremap cof :let g:my_findprg=(g:my_findprg+1)%len(g:my_findprgs):let &ro = &ro diff --git a/vim/.vimrc b/vim/.vimrc index 7d5f9ff..5b0be7f 100644 --- a/vim/.vimrc +++ b/vim/.vimrc @@ -15,12 +15,10 @@ Plug 'PotatoesMaster/i3-vim-syntax' Plug 'SirVer/ultisnips' Plug 'airblade/vim-gitgutter' Plug 'AndrewRadev/splitjoin.vim' -Plug 'easymotion/vim-easymotion' Plug 'honza/vim-snippets' Plug 'jamessan/vim-gnupg', { 'branch': 'main' } Plug 'junegunn/fzf', { 'dir': '~/.fzf', 'do': './install --all' } Plug 'junegunn/fzf.vim' -Plug 'junegunn/goyo.vim' Plug 'junegunn/gv.vim' Plug 'junegunn/heytmux' Plug 'junegunn/vim-easy-align' @@ -31,7 +29,6 @@ Plug 'justinmk/vim-sneak' Plug 'kshenoy/vim-signature' Plug 'lervag/vimtex' Plug 'machakann/vim-highlightedyank' -Plug 'majutsushi/tagbar' Plug 'mg979/vim-visual-multi' Plug 'neomake/neomake' Plug 'sjl/Gundo.vim', { 'on' : 'GundoToggle' } @@ -53,34 +50,28 @@ Plug 'tpope/vim-sensible' Plug 'tpope/vim-surround' Plug 'tpope/vim-unimpaired' Plug 'troydm/zoomwintab.vim' -let g:zoomwintab_hidetabbar=0 Plug 'vim-scripts/ReplaceWithRegister' Plug 'vim-scripts/gmsh.vim' Plug 'wellle/targets.vim' - if isdirectory($HOME."/dotfiles/plugins") - " Plug '~/dotfiles/plugins/vim-remembrall' + Plug '~/dotfiles/plugins/vim-remembrall' Plug '~/dotfiles/plugins/vim-tmux-pilot' Plug '~/dotfiles/plugins/vim-ripple' Plug '~/dotfiles/plugins/vim-darjeeling' Plug '~/dotfiles/plugins/vim-macaw' endif -if has("nvim") - Plug '~/dotfiles/plugins/nvim-i3scratchpad' -endif - if has("nvim") && hostname() != "peuplier" - Plug 'neovim/nvim-lsp' + Plug '~/dotfiles/plugins/nvim-i3scratchpad' Plug 'neovim/nvim-lspconfig' + Plug 'nvim-treesitter/nvim-treesitter', {'do': ':TSUpdate'} + Plug 'nvim-treesitter/playground' endif " Colors Plug 'altercation/vim-colors-solarized' -Plug 'KKPMW/sacredforest-vim' Plug 'junegunn/seoul256.vim' Plug 'romainl/Apprentice' -Plug 'arcticicestudio/nord-vim' Plug 'JuliaEditorSupport/julia-vim' " Plug 'axvr/zepl.vim' call plug#end() @@ -89,22 +80,16 @@ call plug#end() " Toggles nnoremap cpg :GitGutterToggle -nnoremap cpn :NERDTreeToggle -nnoremap cpt :TagbarToggle nnoremap cpu :GundoToggle -nnoremap cp Remembrall('cp') " Fuzzy finder -nnoremap a :Ag nnoremap b :Buffers -nnoremap C :Colors nnoremap f :Files nnoremap g :GitFiles nnoremap r :History nnoremap : :History: nnoremap / :History/ nnoremap l :BLines - nnoremap :Buffers nnoremap :Files nnoremap :GitFiles @@ -124,7 +109,6 @@ let g:VM_maps["Select Cursor Up"] = "" function! Call_heytmux(vm) call feedkeys(":'[,']Heytmux! ") endfunction - nnoremap gh :set opfunc=Call_heytmuxg@ xnoremap gh :Heytmux! @@ -141,8 +125,8 @@ nnoremap ,pc :PlugClean " Remembrall if &runtimepath =~ 'remembrall' - let g:remembrall_auto_accept = 0 - nnoremap ,p Remembrall(',p') + let g:remembrall_auto_accept = 1 + nnoremap ,p Remembrall(',p') nnoremap ,, Remembrall('') augroup remembrall autocmd FileType tex nnoremap ,l Remembrall(',l') @@ -187,9 +171,6 @@ let g:UltiSnipsExpandTrigger="" let g:UltiSnipsJumpBackwardTrigger="" let g:UltiSnipsJumpForwardTrigger="" let g:UltiSnipsListSnippets="" -" let g:UltiSnipsSnippetDirectories=['UltiSnips'] -" let g:UltiSnipsSnippetsDir="~/.vim/mySnippets" -" let g:UltiSnipsUsePythonVersion=3 " Vimtex let g:vimtex_fold_enabled=1 " Makes %s slow! @@ -225,15 +206,20 @@ let g:pilot_mode='wintab' "" Vim variables {{{1 let g:netrw_bufsettings='relativenumber' + +" Latex configuration let g:tex_conceal= '' let g:tex_flavor='latex' +augroup latex + autocmd FileType tex let b:surround_124 = "\\lvert \r \\rvert" +augroup END + "" Vim options {{{1 set backup set undofile set backupdir^=~/.vim/backup// set directory^=~/.vim/swap// -set undodir^=~/.vim/undo// " ^= : prepends to list " // : store absolute path @@ -287,42 +273,48 @@ nnoremap N Nzz nnoremap AddWhiteSpaceAfter a h:silent call repeat#set("\AddWhiteSpaceAfter") nnoremap AddWhiteSpaceBefore i l:silent call repeat#set("\AddWhiteSpaceBefore") - nmap ]w AddWhiteSpaceAfter nmap [w AddWhiteSpaceBefore nnoremap w :update nnoremap q :q nnoremap d :bd! -nnoremap :q +nnoremap :q nnoremap ,bd :ls:bd -nnoremap ,te :tabedit nnoremap gl :+tabmove nnoremap gh :-tabmove -nnoremap ,t0 :tabmove 0 -nnoremap ,t$ :tabmove +" Delete cache nnoremap c :call delete($HOME."/.vim/swap/".substitute(expand('%:p'), '/', '%', 'g').".swp") + +" Dispatch nnoremap r :Start %:p nnoremap R :Start! %:p +" Quickfix nnoremap cqo :copen nnoremap cqh :colder nnoremap cqc :cclose +" Terminal and file manager nnoremap got :call system('urxvt -cd '.shellescape(getcwd()).' &') nnoremap goT :call system('urxvt -cd '.shellescape(expand("%:p:h")).' &') nnoremap gof :call system('urxvt -e vifm '.shellescape(getcwd()).' '.shellescape(getcwd()).' &') nnoremap goF :call system('urxvt -e vifm '.shellescape(expand("%:p:h")).' '.shellescape(expand("%:p:h")).' &') +" Header files nnoremap \h :e %:p:s,.hpp$,.X123X,:s,.cpp$,.hpp,:s,.X123X$,.cpp, + +" Make Y behave like C, D nnoremap Y y$ +" Formatting nnoremap fw :%s/\s\+$// nnoremap ft :%s/^ \+//g +" Swap / and / cnoremap cnoremap cnoremap @@ -330,10 +322,12 @@ cnoremap " Alternate file nnoremap  + +" Buffers nnoremap + :Buffers " Align -nnoremap vip:EasyAlign * :w +nnoremap yA vip:EasyAlign * :w " Source current file nnoremap ,s :source % @@ -354,13 +348,11 @@ nmap co yo "" Autocommands {{{1 augroup vimrc autocmd! - " autocmd ColorScheme * highlight String ctermfg=192 guifg=#d7ff87 - " autocmd ColorScheme * highlight Folded ctermbg=23 ctermfg=185 guibg=#005f5f guifg=#d7d75f autocmd BufWritePost *vimrc,*exrc :call feedkeys(":source %\") autocmd BufNewFile,Bufread /tmp/mutt-* setlocal tw=72 autocmd BufWritePre * \ if !isdirectory(expand(':p:h')) | - \ call mkdir(expand(':p:h'), 'p') | + \ call mkdir(expand(':p:h'), 'p') | \ endif " Detect filetypes (! 'setf freefem' does not override...) @@ -392,105 +384,6 @@ nnoremap ,cs :colorscheme seoul256 set notermguicolors colo darjeeling -"" My search {{{1 - -" http://vim.wikia.com/wiki/Searching_for_files -function! MySearch(...) - let l:prevgrepprg=&grepprg - let l:prevgrepformat=&grepformat - if a:1 == "Rg" - set grepprg=rg\ -uu\ --vimgrep - set grepformat=%f:%l:%c:%m - elseif a:1 == "Gnufind" - set grepprg=find\ .\ -name - set grepformat=%f - elseif a:1 == "Gitfind" - set grepprg=git\ ls-files\ -i\ -x - set grepformat=%f - endif - execute 'silent grep!' a:2 | cwindow | redraw! - let &grepprg=l:prevgrepprg - let &grepformat=l:prevgrepformat -endfun - -command! -nargs=+ -complete=file_in_path Rg call MySearch("Rg", ) -command! -nargs=+ -complete=file_in_path Gnufind call MySearch("Gnufind", ) -command! -nargs=+ -complete=file_in_path Gitfind call MySearch("Gitfind", ) -command! -nargs=+ -complete=file_in_path GitGrep execute 'silent Ggrep!' | cw | redraw! -command! -nargs=+ -complete=file_in_path VimGrep execute 'silent vimgrep!' | cw | redraw! - -" Default search and find programs -function! FillSearch(...) - if a:0 == 0 - let l:filltext = "" - else - let l:is_visual=(a:1 == "v") - let l:line=getline(l:is_visual ? "'<" : "'[") - let [line1,col1] = getpos(l:is_visual ? "'<" : "'[")[1:2] - let [line2,col2] = getpos(l:is_visual ? "'>" : "']")[1:2] - let l:filltext =l:line[col1 - 1: col2 - 1] - endif - call feedkeys(':' . g:my_fillprg . ' "' . l:filltext . '"'."\") -endfunction - -let g:my_searchprgs = ['Rg', 'GitGrep', 'VimGrep'] -let g:my_findprgs = ['Gnufind', 'Gitfind'] -let g:my_searchprg = 0 -let g:my_findprg = 0 - -nnoremap g/ :let g:my_fillprg=g:my_searchprgs[g:my_searchprg]:set opfunc=FillSearchg@ -nnoremap ,g :let g:my_fillprg=g:my_searchprgs[g:my_searchprg]:call FillSearch() -xnoremap ,g :let g:my_fillprg=g:my_searchprgs[g:my_searchprg]:call FillSearch(visualmode()) -nnoremap ,f :let g:my_fillprg=g:my_findprgs[g:my_findprg]:call FillSearch() - -" Cycle search / find prgs -nnoremap cog :let g:my_searchprg=(g:my_searchprg+1)%len(g:my_searchprgs):let &ro = &ro -nnoremap cof :let g:my_findprg=(g:my_findprg+1)%len(g:my_findprgs):let &ro = &ro - -"" Status line {{{1 -function! Mixed_indent() - let l:spaces=search('\v(^ +)','n') - let l:tabs=search('\v(^\t+)','n') - return (l:spaces * l:tabs > 0) -endfunction - -function! GlobalCwd() - return getcwd(-1, -1) -endfunction - -function! TabCwd(number) - if haslocaldir(-1, a:number) - return getcwd(-1, a:number) - endif - return "" -endfunction - -function! WinCwd() - if haslocaldir(0) - return getcwd() - endif - return "" -endfunction - -set showtabline=2 -let g:tabprefix = "" -let g:tablabel = "%N%{flagship#tabmodified()} %{TabCwd(v:lnum) != '' ? pathshorten(TabCwd(v:lnum)) : ''}" -let g:flagship_skip = 'FugitiveStatusline' - -augroup myflags - autocmd! - autocmd CmdwinEnter,BufEnter,BufRead,BufWritePost * let b:trailing=search('\s\+$','n') - autocmd CmdwinEnter,BufEnter,BufRead,BufWritePost * let b:mixed=Mixed_indent() - autocmd User Flags call Hoist("buffer", "%{FugitiveHead('') != '' ? '['.FugitiveHead('').']' : ''}") - autocmd User Flags call Hoist("buffer", "%{b:trailing?'[tw]':''}") - autocmd User Flags call Hoist("buffer", "%{b:mixed?'[mixed]':''}") - autocmd User Flags call Hoist("buffer", "%{&paste?'[paste]':''}") - autocmd User Flags call Hoist("window", "%{WinCwd() != '' ? '['.WinCwd().']' : ''}") - - highlight MyGlobals ctermfg=255 ctermbg=240 - autocmd User Flags call Hoist("global", {"hl": "MyGlobals"}, "[%{pathshorten(GlobalCwd())}, %{g:my_searchprgs[g:my_searchprg]}, %{g:my_findprgs[g:my_findprg]}]") -augroup END - "" Neovim {{{1 if has("nvim") nnoremap goh :let @a=getcwd() \| lcd %:h \| terminal:execute 'lcd '.@aA @@ -500,45 +393,44 @@ if has("nvim") nnoremap t :b term \| norm A endif +if has("nvim") +lua < Remembrall('') -" nnoremap h lua vim.lsp.buf.hover() -" nnoremap a lua vim.lsp.buf.declaration() -" nnoremap d lua vim.lsp.buf.definition() -" nnoremap i lua vim.lsp.buf.implementation() -" nnoremap s lua vim.lsp.buf.signature_help() -" nnoremap t lua vim.lsp.buf.type_definition() -" nnoremap lua vim.lsp.stop_client(vim.lsp.get_active_clients()) -" endif - -function! s:remove_leading_whitespaces(code) - " Check if the first line is indented - let leading_spaces = matchstr(a:code, '^\s\+') - - if leading_spaces == "" - return a:code - endif - - " Calculate indentation - let indentation = strlen(leading_spaces) - - " Remove further indentations - return substitute(a:code, '\(^\|\r\zs\)\s\{'.indentation.'}', "", "g") -endfunction +if has("nvim") && hostname() != "peuplier" +try + " lua require('lspconfig').pyls.setup{} + " lua require('lspconfig').julials.setup{} + " autocmd Filetype python setlocal omnifunc=v:lua.vim.lsp.omnifunc + autocmd Filetype julia setlocal omnifunc=v:lua.vim.lsp.omnifunc + nnoremap Remembrall('') + nnoremap h lua vim.lsp.buf.hover() + nnoremap a lua vim.lsp.buf.declaration() + nnoremap d lua vim.lsp.buf.definition() + nnoremap i lua vim.lsp.buf.implementation() + nnoremap s lua vim.lsp.buf.signature_help() + nnoremap t lua vim.lsp.buf.type_definition() + nnoremap lua vim.lsp.stop_client(vim.lsp.get_active_clients()) +catch + echom "Error with LPS configuration" +endtry +endif +" Tests {{{1 let g:ripple_repls = { - \ "python": ["ipython", "\[200~", "\[201~", 1, function('s:remove_leading_whitespaces')], - \ "r": "radian" - \ } - -" let g:ripple_repls = { -" \ "python": ["ipython", "", "", 1] -" \ } - - -" let g:ripple_repls = { "python": ["ipython", "\", "\\", 1] } - -autocmd FileType tex let b:surround_124 = "\\lvert \r \\rvert" + \ "python": { + \ "command": "ipython", + \ "pre": "\[200~", + \ "post": "\[201~", + \ "addcr": 1, + \ "filter": function('ripple#remove_leading_whitespaces'), + \ }, + \ "r": "radian" + \ } diff --git a/zsh/.zshrc b/zsh/.zshrc index 0fbebe2..830964c 100644 --- a/zsh/.zshrc +++ b/zsh/.zshrc @@ -1,6 +1,7 @@ -## startx automatically {{{1 -[[ -z $DISPLAY && -z $SSH_CONNECTION && $XDG_VTNR -eq 1 ]] && exec startx -## Bindings {{{1 +# startx automatically {{{1 + [[ -z $DISPLAY && -z $SSH_CONNECTION && $XDG_VTNR -eq 1 ]] && exec startx + +# Bindings {{{1 # Load fzf bindings here because we will override ^r [ -f ~/.fzf.zsh ] && source ~/.fzf.zsh -- cgit v1.2.3