Skip to content

Commit

Permalink
feat: enable backup
Browse files Browse the repository at this point in the history
  • Loading branch information
jiangyinzuo committed Jun 29, 2024
1 parent ec02b62 commit 0c399ec
Show file tree
Hide file tree
Showing 14 changed files with 229 additions and 309 deletions.
1 change: 1 addition & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@ root/.vim/.netrwhist
root/.vim/plugged
root/.vim/doc/tags
root/.vim/doc/tags-cn
root/.vim/backup
root/.vim/coc
root/.vim/gadgets
root/.vim/.viminfo
Expand Down
47 changes: 44 additions & 3 deletions .vimrc
Original file line number Diff line number Diff line change
Expand Up @@ -73,9 +73,33 @@ if has('autocmd') " vim-tiny does not have autocmd
set magic "模式匹配时 ^ $ . * ~ [] 具有特殊含义
set lazyredraw " 不要在宏的中间重绘屏幕。使它们更快完成。
set dictionary+=/usr/share/dict/american-english
set nobackup "no backup files
set nowritebackup "only in case you don't want a backup file while editing
set noswapfile "no swap files
" NOTE: persistent_undo在文件丢失后无法恢复历史,所以开启backup
set nobackup
set nowritebackup
if has('nvim')
let s:backup_dir = "~/.vim/backup/nvim"
else
let s:backup_dir = "~/.vim/backup/vim"
endif
function BackupFile()
" 获取当前文件的大小(单位:字节)
let l:filesize = getfsize(expand('%:p'))
" 设置大小阈值为5MB
let l:maxsize = 5 * 1024 * 1024
if l:filesize > l:maxsize
return
endif
if !exists("b:backup_dir")
let b:backup_dir = expand(s:backup_dir) . expand("%:p:h")
if !isdirectory(b:backup_dir)
call mkdir(b:backup_dir, "p", 0700)
endif
endif
call system('cp ' . expand('%:p') . ' ' . b:backup_dir . '/' . expand('%:t') . strftime("~~%Y-%m%d-%X") .. '.bak')
endfunction
autocmd BufWritePost * call BackupFile()
set swapfile
set updatecount=100
" 会话不保存options, 防止重新set background=dark后,覆盖一些highlight设置
if v:version >= 802 || has('nvim')
set sessionoptions=curdir,globals,localoptions,resize,tabpages,terminal,winpos,winsize
Expand Down Expand Up @@ -154,6 +178,23 @@ if has('autocmd') " vim-tiny does not have autocmd
" https://vi.stackexchange.com/questions/13091/autocmd-event-for-autoread
autocmd FileChangedShellPost * echohl WarningMsg | echo "File changed on disk. Buffer reloaded." | echohl Noneau FocusGained,BufEnter * checktime
endif

" Enable persistent undo so that undo history persists across vim sessions
" NOTE: persistent_undo在文件丢失后无法恢复历史,需要开启backup
if has("persistent_undo")
if has('nvim')
let target_path = expand('~/.vim/undodir/nvim')
else
let target_path = expand('~/.vim/undodir/vim')
endif
" create the directory and any parent directories
" if the location does not exist.
if !isdirectory(target_path)
call mkdir(target_path, "p", 0700)
endif
let &undodir=target_path
set undofile
endif
"""""""""""""""""""""""""""""""
if has("patch-8.1.0360")
set diffopt=vertical,filler,context:3,indent-heuristic,algorithm:patience,internal
Expand Down
5 changes: 4 additions & 1 deletion root/.vim/autoload/plug.vim
Original file line number Diff line number Diff line change
Expand Up @@ -2281,7 +2281,10 @@ endfunction

function! s:with_cd(cmd, dir, ...)
let script = a:0 > 0 ? a:1 : 1
return printf('cd%s %s && %s', s:is_win ? ' /d' : '', plug#shellescape(a:dir, {'script': script}), a:cmd)
let pwsh = s:is_powershell(&shell)
let cd = s:is_win && !pwsh ? 'cd /d' : 'cd'
let sep = pwsh ? ';' : '&&'
return printf('%s %s %s %s', cd, plug#shellescape(a:dir, {'script': script, 'shell': &shell}), sep, a:cmd)
endfunction

function! s:system(cmd, ...)
Expand Down
2 changes: 2 additions & 0 deletions root/.vim/coc-settings.json
Original file line number Diff line number Diff line change
Expand Up @@ -59,10 +59,12 @@
"Lua.format.enable": false,
"ltex.enabled": false,
"python.pythonPath": "/bin/python3",
"python.formatting.provider": "black",
"python.linting.mypyEnabled": false,
"python.linting.pylintEnabled": true,
"pyright.enable": true,
"pyright.testing.provider": "unittest",
"basedpyright.enable": false,
"rust-analyzer.enable": true,
"rust-analyzer.cargo.autoreload": true,
"rust-analyzer.procMacro.enable": true,
Expand Down
49 changes: 38 additions & 11 deletions root/.vim/doc/c-cpp-cuda.txt
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@ vim:ft=help
LLVM Toolchains

--------------------------------------------------------------------------------------
Clangd
Clangd ~

*clangd*

Expand All @@ -24,22 +24,24 @@ See: https://www.reddit.com/r/neovim/comments/vj0e16/how_to_specify_location_of_
<
同时clangd启动命令添加`--compile-commands-dir=build/release`

NOTE
Clangd 配置 ~

clangd无法解析OpenMP pragma https://github.com/clangd/clangd/issues/1640
暂时的解决方案:在`.clangd`文件中添加
>
CompileFlags:
Remove: [-fopenmp]
>yaml
CompileFlags:
Remove: [-fopenmp]
<
clangd还没实现outgoing calls in call hierarchy https://github.com/llvm/llvm-project/pull/77556

clangd omp.h not found ~

locate /omp.h 找到omp.h文件位置,然后在`.clangd`文件中添加

CompileFlags:
Add:
- -isystem/usr/lib/gcc/x86_64-linux-gnu/13/include/
>yaml
CompileFlags:
Add:
- -isystem/usr/lib/gcc/x86_64-linux-gnu/13/include/
<

clangd / |ccls| 找不到c++系统头文件解决方法 ~

Expand All @@ -56,13 +58,27 @@ https://stackoverflow.com/questions/74785927/clangd-doesnt-recognize-standard-he
>
ls /usr/include/c++
<
clang: In included file: use of undeclared identifier '__builtin_ia32_prefetch' 解决方法 ~

由于编译器未启用特定的处理器架构或指令集支持所致。这个内建函数是用于 x86
平台的特定指令。如果没有正确设置目标架构,编译器可能无法识别这些内建函数。

方法一:添加编译选项
>yaml
CompileFlags:
Add: [-march=x86-64]
<

方法二:添加头文件
>cpp
#include <xmmintrin.h>
<
--------------------------------------------------------------------------------------

*clang-format* `:%!clang-format` or `:'<,'>!clang-format`.
No need of `Plug 'rhysd/vim-clang-format'`

*clang-tidy*
*clang-tidy*
output to quickfix list: >
:CExprsys clang-tidy hello.cpp
<
Expand Down Expand Up @@ -125,6 +141,10 @@ Ninja:
cmake --trace --trace-expand ..
<

CMake导出compile_commands.json ~
>bash
cmake -DCMAKE_EXPORT_COMPILE_COMMANDS=ON ..
<
--------------------------------------------------------------------------------------

*CPM.cmake* https://github.com/cpm-cmake/CPM.cmake
Expand Down Expand Up @@ -189,7 +209,7 @@ https://apt.llvm.org/
wget -O - https://apt.llvm.org/llvm-snapshot.gpg.key | sudo apt-key add -
<

------------------------------------------------------------------------------------
====================================================================================
*cuda*

CUDA 安装: https://developer.nvidia.com/cuda-toolkit-archive
Expand All @@ -211,6 +231,13 @@ gpustat: `pip install gpustat`
【工具篇】如何优雅地监控显卡(GPU)使用情况? - 聚丙烯酰胺的文章 - 知乎 https://zhuanlan.zhihu.com/p/577533593

------------------------------------------------------------------------------------
Failed to initialize NVML: Driver/library version mismatch NVML library version: 535.183

原因:kernel mod 的 Nvidia driver 的版本没有更新
解决方法:重启服务器

https://comzyh.com/blog/archives/967/
====================================================================================
*glibc*

查看glibc版本
Expand Down
1 change: 1 addition & 0 deletions root/.vim/doc/command-line-tool.txt
Original file line number Diff line number Diff line change
Expand Up @@ -47,6 +47,7 @@ Ubuntu22.04下均可通过apt安装

命令行补全目录: .local/share/bash-completion/completions

*rename-command*
批量重命名: rename。rename有两个版本,
一种版本支持's/foo/bar/g'替换模式 (Ubuntu 23.10),
另一种版本不支持。
Expand Down
Loading

0 comments on commit 0c399ec

Please sign in to comment.