Skip to content

Commit

Permalink
feat!: use coc-list session, remove mksession.vim
Browse files Browse the repository at this point in the history
  • Loading branch information
jiangyinzuo committed Jan 11, 2024
1 parent 73ded48 commit 39116d9
Show file tree
Hide file tree
Showing 11 changed files with 109 additions and 111 deletions.
50 changes: 0 additions & 50 deletions root/.vim/autoload/mksession.vim

This file was deleted.

3 changes: 2 additions & 1 deletion root/.vim/coc-settings.json
Original file line number Diff line number Diff line change
Expand Up @@ -79,5 +79,6 @@
],
"explorer.git.enable": false,
"explorer.file.showHiddenFiles": true,
"explorer.icon.enableNerdfont": true
"explorer.icon.enableNerdfont": true,
"session.saveOnVimLeave": true
}
83 changes: 60 additions & 23 deletions root/.vim/doc/git-help.cnx
Original file line number Diff line number Diff line change
Expand Up @@ -146,26 +146,81 @@ git rebase --edit-timestamp *git-rebase-edit-timestamp*

*git-difftool* git difftool HEAD mydoc.txt or git difftool -- mydoc.txt HEAD

|vimdiff|
vimdf 脚本

*git-mergetool*

git列举所有unmerged文件 git diff --name-only --diff-filter=U --relative
git撤销某个提交的merged文件 git restore -m foo.txt
tutorial: https://gist.github.com/karenyyng/f19ff75c60f18b4b8149
插件: https://github.com/samoshkin/vim-mergetool

批量merge多个文件的流程
批量merge多个文件的流程 ~

方案1: 直接git mergetool开启merge
方案2:
1) `:Git mergetool` , 在quickfix list加载所有unmerged file
通用vim命令 `:Git mergetool` , 在quickfix list加载所有unmerged file
可以用:SaveList 和 :LoadList 保存/加载quickfix list(在quickfix buffer下命令生效)
2) 打开需要merge的文件后, >

方案0: 直接修改unmerged文件 ~

例子来源于上面的tutorial
>
root@DESKTOP-TI1H94P:~/galaxyZoo# git merge astrophy_objects
Auto-merging astrophy_obj.txt
CONFLICT (content): Merge conflict in astrophy_obj.txt
Auto-merging foo.txt
CONFLICT (add/add): Merge conflict in foo.txt
Automatic merge failed; fix conflicts and then commit the result.
root@DESKTOP-TI1H94P:~/galaxyZoo# git status
On branch master
You have unmerged paths.
(fix conflicts and run "git commit")
(use "git merge --abort" to abort the merge)
Unmerged paths:
(use "git add <file>..." to mark resolution)
both modified: astrophy_obj.txt
both added: foo.txt
no changes added to commit (use "git add" and/or "git commit -a")
root@DESKTOP-TI1H94P:~/galaxyZoo# cat foo.txt
<<<<<<< HEAD
abc
||||||| dbbf6d7
=======
def
>>>>>>> astrophy_objects
<

方案1: 直接git mergetool开启merge ~

方案2: 基于vim-mergetool~

需要在.gitconfig中添加 >
[merge]
conflictStyle = diff3
[merge]
# tool = vimdiff
tool = vim_mergetool
conflictstyle = diff3
[mergetool]
keepBackup = false
[mergetool "vim_mergetool"]
cmd = vim -f -c "MergetoolStart" "$MERGED" "$BASE" "$LOCAL" "$REMOTE"
# When trustExitCode = true, checks exit code of merge tool process.
# When trustExitCode = false, checks if MERGED file was modified.
trustExitCode = true
prompt = false
<

1) 利用上面的`:Git mergetool`或其它方式,打开需要merge的文件后, >
:MergetoolStart/:MergetoolToggle 开始merge
:MergetoolStop/:MergetoolToggle 结束merge(保存或撤销)
<

用:qa!退出vim会直接判断为merge成功

其它命令
:MergetoolDiffExchangeLeft 把右边的buffer应用到左边的MERGED文件
:GitUnmergedRaw FZF打开unmerged文件,直接编辑
:GitUnmerged FZF打开unmerged文件,然后:MergetoolStart
Expand Down Expand Up @@ -217,23 +272,5 @@ git gc, git 减小.git目录大小 *git-gc*
git gc --prune=now --aggressive
<

-------------------------------------------------------------------------------
vim mergetool *vim-mergetool*

当你使用 Vim 作为 Git 的 mergetool 时,你可以使用一些 Vim 插件来美化三路合并的高亮
文本页面。

比如,你可以使用 'vim-mergetool' 插件,它提供了一个集成的三路合并界面,以及一些高
亮和配色方案来提升可读性。

你可以在 Vim 中使用以下命令来安装 'vim-mergetool' 插件:
:Plug 'samoshkin/vim-mergetool'

然后,你需要在你的 '.gitconfig' 文件中设置 Vim 作为默认的 mergetool:
[merge]
tool = vimdiff

然后,当你运行 'git mergetool' 命令时,Git 会使用 Vim 来解决合并冲突。

==============================================================================

8 changes: 5 additions & 3 deletions root/.vim/doc/mydoc.cnx
Original file line number Diff line number Diff line change
Expand Up @@ -16,8 +16,11 @@ ISSUE: helpfile开启ft=help后,在快速插入---------------------时存在
在当前文件夹下新建文件 %
删除文件/文件夹 D
-------------------------------------------------------------------------------
*保存会话session* :mks foo.vim
*加载会话session* vim -S foo.vim

自v0.15.0后,coc-list替代了mksession.vim

*基于coc-list保存会话session* :Mksession
*基于coc-list加载会话session* :Loadsession
-------------------------------------------------------------------------------

*往下/上翻1页* CTRL-F CTRL-B
Expand Down Expand Up @@ -183,7 +186,6 @@ CTRL-SHIFT-V paste

*vimt* tex
*vimhelp* help
*vimdf* diff, see vimdf -h

-------------------------------------------------------------------------------

Expand Down
2 changes: 1 addition & 1 deletion root/.vim/vimrc
Original file line number Diff line number Diff line change
Expand Up @@ -88,7 +88,7 @@ set nowritebackup "only in case you don't want a backup file while editing
set noswapfile "no swap files

" 会话不保存options, 防止重新set background=dark后,覆盖一些highlight设置
set sessionoptions-=options
set sessionoptions=curdir,globals,localoptions,resize,tabpages,terminal,winpos,winsize

" 选中想格式化的段落后,可以用gq格式化
" 设置textwidth,可以让文本格式化时自动换行
Expand Down
5 changes: 5 additions & 0 deletions root/.vim/vimrc.d/coc.vim
Original file line number Diff line number Diff line change
Expand Up @@ -140,6 +140,11 @@ command! -nargs=? Fold :call CocAction('fold', <f-args>)
" Add `:OR` command for organize imports of the current buffer
command! -nargs=0 OrganizeImports :call CocActionAsync('runCommand', 'editor.action.organizeImport')

" Use coc-lists instead of custom mksession.vim
" https://github.com/neoclide/coc-lists
command! -nargs=0 Mksession :CocCommand session.save
command! -nargs=0 Loadsession :CocCommand session.load

" https://github.com/neoclide/coc.nvim/wiki/Multiple-cursors-support
" vim-visual-multi is too complex!!!
" SpecialKey在coc多光标模式下不会高亮,如有需要,可以在执行多光标前执行
Expand Down
9 changes: 0 additions & 9 deletions root/.vim/vimrc.d/project.vim
Original file line number Diff line number Diff line change
Expand Up @@ -94,12 +94,3 @@ augroup load_my_project
" 当打开新的缓冲区时,调用LoadProjectConfigEachTab函数加载对应的.project_vimrc文件
autocmd TabNew * call TabNewLoadProjectConfig()
augroup END

"""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""
" MkSession
"""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""
if exists("*json_encode")
" [[palette]]创建session文件 :MkSession
command MkSession call mksession#MkSession(asyncrun#current_root() . '/session.vim')
endif

2 changes: 1 addition & 1 deletion root/bashrc
Original file line number Diff line number Diff line change
Expand Up @@ -7,8 +7,8 @@ export BASH_ENV=$HOME/vimrc/root/bashrc_noi
source $HOME/vimrc/root/bashrc_noi

alias vimt='vim --servername TEX'
alias vims='vim -S session.vim'
alias vimhelp='vim -c ":Lines!" ~/.vim/doc/mydoc.txt'
alias vims='vim -c ":CocCommand session.load"'

source "$VIMRC_ROOT"/fzf/fzf.bash

Expand Down
34 changes: 34 additions & 0 deletions root/scripts/forget
Original file line number Diff line number Diff line change
@@ -0,0 +1,34 @@
#!/bin/bash

echo_green() {
echo -e "\033[32m$1\033[0m"
}

echo_blue() {
echo -e "\033[34m$1\033[0m"
}

forget_daily() {
echo_blue 'NOTE: type "wslhelp" to see more help'
echo_green '$ forget'
echo
echo_green '$ daily'
$VIMRC_ROOT/scripts/wsl/daily
echo
echo_green '$ sr'
$VIMRC_ROOT/scripts/wsl/sr
}

if [ $# -eq 0 ]; then
echo_blue "forget alias? run:"
echo "alias"
echo_blue "forget functions? run:"
# do not output function start with "_"
echo "declare -F | grep -oP '(?<=declare -f )[a-zA-Z]+\w+'"
echo_blue "other commands:"
# output all functions in this file begin with "forget_"
declare -F | grep -oP '(?<=declare -f )forget_\w+' | sed 's/forget_/forget /'
exit 0
else
forget_$1
fi
22 changes: 0 additions & 22 deletions root/scripts/wsl/forget

This file was deleted.

2 changes: 1 addition & 1 deletion root/wsl-init.bash
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@ echo -e "forget?? run \033[32mforget\033[0m"
# 检查是否是今天第一次启动shell
if [ ! -f /tmp/reminder_done ]; then
# 执行脚本
$VIMRC_ROOT/scripts/wsl/forget
$VIMRC_ROOT/scripts/forget
# 创建一个标记文件,表示今天已经提醒过了
touch /tmp/reminder_done
# 设置该文件在次日0点自动删除
Expand Down

0 comments on commit 39116d9

Please sign in to comment.