summaryrefslogtreecommitdiff
path: root/vim/.vim
diff options
context:
space:
mode:
authorUrbain Vaes <urbain@vaes.uk>2021-08-10 10:32:16 +0200
committerUrbain Vaes <urbain@vaes.uk>2021-08-10 10:51:55 +0200
commitfce46ed7e852dfc60466c50f348c0c2c7caba7fc (patch)
treea3b2dce0f107676829f0eea49fcc0d8e9601c4dc /vim/.vim
parentd140b98cba4b37805e4f2b112e93c87ae6adbe73 (diff)
Minor change
Diffstat (limited to 'vim/.vim')
-rw-r--r--vim/.vim/after/plugin/status.vim46
-rw-r--r--vim/.vim/plugin/search.vim52
2 files changed, 98 insertions, 0 deletions
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", <q-args>)
+command! -nargs=+ -complete=file_in_path Gnufind call MySearch("Gnufind", <q-args>)
+command! -nargs=+ -complete=file_in_path Gitfind call MySearch("Gitfind", <q-args>)
+command! -nargs=+ -complete=file_in_path GitGrep execute 'silent Ggrep!' <q-args> | cw | redraw!
+command! -nargs=+ -complete=file_in_path VimGrep execute 'silent vimgrep!' <q-args> | 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 . '"'."\<Left>")
+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 <silent> g/ :let g:my_fillprg=g:my_searchprgs[g:my_searchprg]<cr>:set opfunc=FillSearch<cr>g@
+nnoremap <silent> ,g :let g:my_fillprg=g:my_searchprgs[g:my_searchprg]<cr>:call FillSearch()<cr>
+xnoremap <silent> ,g :<c-u>let g:my_fillprg=g:my_searchprgs[g:my_searchprg]<cr>:call FillSearch(visualmode())<cr>
+nnoremap <silent> ,f :let g:my_fillprg=g:my_findprgs[g:my_findprg]<cr>:call FillSearch()<cr>
+
+" Cycle search / find prgs
+nnoremap <silent> cog :let g:my_searchprg=(g:my_searchprg+1)%len(g:my_searchprgs)<cr>:let &ro = &ro<cr>
+nnoremap <silent> cof :let g:my_findprg=(g:my_findprg+1)%len(g:my_findprgs)<cr>:let &ro = &ro<cr>