Skip to content

Commit

Permalink
feat!: remove .vimrc vimdf, add fzf-gitdiff.vim
Browse files Browse the repository at this point in the history
  • Loading branch information
jiangyinzuo committed Feb 7, 2024
1 parent a2aed3b commit bb94e09
Show file tree
Hide file tree
Showing 8 changed files with 75 additions and 680 deletions.
8 changes: 4 additions & 4 deletions .github/workflows/load_vimrc.yml
Original file line number Diff line number Diff line change
Expand Up @@ -17,13 +17,13 @@ jobs:
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v3
- name: single vimrc with vim.tiny
run: vim.tiny -E -s -u .vimrc -c "qa!"
# - name: single vimrc with vim.tiny
# run: vim.tiny -E -s -u .vimrc -c "qa!"
- name: install vim
# CentOS 7.1 uses Vim 7.4.629
run: sudo ./install/build_vim_from_source.sh 7.4.629
- name: single vimrc
run: vim -E -s -u .vimrc -c "qa!"
# - name: single vimrc
# run: vim -E -s -u .vimrc -c "qa!"
- name: full vimrc
run: ln -s `pwd`/root/.vim ~/.vim && vim -E -s -c "qa!"
- name: full vimrc with vim.tiny
Expand Down
533 changes: 0 additions & 533 deletions .vimrc

This file was deleted.

31 changes: 0 additions & 31 deletions root/.vim/autoload/cppfoldexpr.vim

This file was deleted.

62 changes: 62 additions & 0 deletions root/.vim/autoload/mycpp.vim
Original file line number Diff line number Diff line change
@@ -0,0 +1,62 @@
function! mycpp#FoldExpr(lnum)
let line = getline(a:lnum)
if !exists('b:cpp_fold_level')
let b:cpp_fold_level = 0
let b:last_primitive = ''
endif

let open_braces = len(split(line, '{', 1)) - 1
let close_braces = len(split(line, '}', 1)) - 1

if b:last_primitive == 'if'
let b:cpp_fold_level += 1
elseif b:last_primitive == 'end'
let b:cpp_fold_level -= 1
endif
let b:last_primitive = ''

if line =~ '^\s*#\s*\(ifdef\|ifndef\|if\)' || open_braces > close_braces
let b:cpp_fold_level += 1
let b:last_primitive = 'if'
return b:cpp_fold_level
elseif line =~ '^\s*#\s*\(else\|elif\)' || (open_braces == close_braces && open_braces > 0)
return b:cpp_fold_level - 1
elseif line =~ '^\s*#\s*endif' || close_braces > open_braces
let b:last_primitive = 'end'
let b:cpp_fold_level -= 1
return b:cpp_fold_level
endif

return b:cpp_fold_level
endfunction
function! mycpp#CompleteFunc(findstart, base)
if a:findstart
" 确定补全开始的位置
let line = getline('.')
let start = col('.') - 1
while start > 0 && line[start - 1] =~ '\S'
let start -= 1
endwhile
if line[start] != '<' && line[start] != '"'
return -3
endif
return start + 1
endif

if getline('.') =~# &include
let filetype = &filetype
if filetype == 'cpp' || filetype == 'cuda'
" r! ls -1 /usr/include/c++/13 | awk '{print " \x27"$0"\x27"}' | paste -sd,
let completions = ['algorithm', 'any', 'array', 'atomic', 'backward', 'barrier', 'bit', 'bits', 'bitset', 'cassert', 'ccomplex', 'cctype', 'cerrno', 'cfenv', 'cfloat', 'charconv', 'chrono', 'cinttypes', 'ciso646', 'climits', 'clocale', 'cmath', 'codecvt', 'compare', 'complex', 'complex.h', 'concepts', 'condition_variable', 'coroutine', 'csetjmp', 'csignal', 'cstdalign', 'cstdarg', 'cstdbool', 'cstddef', 'cstdint', 'cstdio', 'cstdlib', 'cstring', 'ctgmath', 'ctime', 'cuchar', 'cwchar', 'cwctype', 'cxxabi.h', 'debug', 'decimal', 'deque', 'exception', 'execution', 'expected', 'experimental', 'ext', 'fenv.h', 'filesystem', 'format', 'forward_list', 'fstream', 'functional', 'future', 'initializer_list', 'iomanip', 'ios', 'iosfwd', 'iostream', 'istream', 'iterator', 'latch', 'limits', 'list', 'locale', 'map', 'math.h', 'memory', 'memory_resource', 'mutex', 'new', 'numbers', 'numeric', 'optional', 'ostream', 'parallel', 'pstl', 'queue', 'random', 'ranges', 'ratio', 'regex', 'scoped_allocator', 'semaphore', 'set', 'shared_mutex', 'source_location', 'span', 'spanstream', 'sstream', 'stack', 'stacktrace', 'stdatomic.h', 'stdexcept', 'stdfloat', 'stdlib.h', 'stop_token', 'streambuf', 'string', 'string_view', 'syncstream', 'system_error', 'tgmath.h', 'thread', 'tr1', 'tr2', 'tuple', 'typeindex', 'typeinfo', 'type_traits', 'unordered_map', 'unordered_set', 'utility', 'valarray', 'variant', 'vector', 'version']
call filter(completions, 'v:val =~ "^" . a:base')
else
let completions = []
endif
" 使用getcompletion()获取文件类型的补全列表
echom a:base
let completions += getcompletion(a:base . '*.h*', 'file_in_path', 1)
let completions += getcompletion(a:base . '*/$', 'file_in_path', 1)
return completions
endif
return []
endfunction
7 changes: 3 additions & 4 deletions root/.vim/vimrc
Original file line number Diff line number Diff line change
Expand Up @@ -327,17 +327,16 @@ if has('autocmd') " vim-tiny does not have autocmd
nnoremap zpr :setlocal foldexpr=(getline(v:lnum)=~@/)?0:(getline(v:lnum-1)=~@/)\\|\\|(getline(v:lnum+1)=~@/)?1:2 foldmethod=expr foldlevel=0 foldcolumn=2<CR>:set foldmethod=syntax<CR><CR>
" 打开所有折叠: zR

if s:has_vimrcd
autocmd FileType c,cpp setlocal foldmethod=expr foldexpr=cppfoldexpr#CppFoldExpr(v:lnum)
endif
autocmd FileType c,cpp,cuda setlocal foldmethod=expr foldexpr=mycpp#FoldExpr(v:lnum)
autocmd FileType c,cpp,cuda setlocal completefunc=mycpp#CompleteFunc
autocmd FileType python,vim,lua,go,markdown,sh,tex setlocal foldmethod=indent

endif

" command -nargs=0 GitBlame !git blame -L line(".") + 1, line(".") + 1 -- %
" [[palette]]git-blame :GitBlame
command -range -nargs=0 GitBlame :!git blame -n -L <line1>,<line2> -- %

" save
inoremap <c-S> <esc>:w<CR>i
Expand Down
1 change: 1 addition & 0 deletions root/.vim/vimrc.d/fzf.vim
Original file line number Diff line number Diff line change
Expand Up @@ -53,6 +53,7 @@ command! -nargs=0 GitUnstaged call fzf#run(fzf#wrap({'source': 'git ls-files -o
" On :LS!, <bang> evaluates to '!', and '!0' becomes 1
" The query history for this command will be stored as 'ls' inside g:fzf_history_dir.
" The name is ignored if g:fzf_history_dir is not defined.
let g:fzf_history_dir = '~/.local/share/fzf-history'
" [[palette]]fzf ls :LS
command! -bang -complete=dir -nargs=? LS
\ call fzf#run(fzf#wrap({'source': 'ls', 'dir': <q-args>}, <bang>0))
Expand Down
5 changes: 5 additions & 0 deletions root/.vim/vimrc.d/plugin.vim
Original file line number Diff line number Diff line change
Expand Up @@ -197,6 +197,8 @@ if !exists('g:vscode')
if v:version >= 900
" Alternative: https://github.com/gelguy/wilder.nvim
Plug 'girishji/autosuggest.vim'
" External cmd is slow.
autocmd VimEnter * call g:AutoSuggestSetup({ 'cmd': { 'exclude': ['!'] }})
endif
if v:version >= 802
if g:vimrc_use_coc
Expand Down Expand Up @@ -252,6 +254,9 @@ if !exists('g:vscode')
let g:GIT_LENS_ENABLED = 0
endif

Plug 'jiangyinzuo/fzf-gitdiff.vim'
command! -nargs=* GitDiff call fzf_gitdiff#FillFZF(<f-args>)

" Plug 'MattesGroeger/vim-bookmarks'
if has('nvim') || v:version >= 802
Plug 'pechorin/any-jump.vim'
Expand Down
108 changes: 0 additions & 108 deletions root/scripts/vimdf

This file was deleted.

0 comments on commit bb94e09

Please sign in to comment.