Skip to content

Commit

Permalink
Add tags, asynctasks. Remove clang_format_config.vim
Browse files Browse the repository at this point in the history
  • Loading branch information
jiangyinzuo committed Feb 6, 2023
1 parent 70af014 commit afcdbaa
Show file tree
Hide file tree
Showing 19 changed files with 1,136 additions and 59 deletions.
8 changes: 6 additions & 2 deletions README.md
Original file line number Diff line number Diff line change
@@ -1,5 +1,8 @@
# Vimrc

vim编译选项
Ubuntu22.04下安装`sudo apt install vim-gtk3`

Vim编译选项
./configure --with-features=huge --enable-fontset=yes --enable-cscope=yes --enable-multibyte --enable-python3interp=yes

`:CocInstall`后,连同nodejs打包给docker容器用
Expand All @@ -17,13 +20,14 @@ ln -s vimrc/root/.vim .vim
source vimrc/root/bashrc
```

## 命令行工具
## 其它命令行工具

查找: find -> fd(还没用过)
模糊查找: fzf
内容搜索: grep -> ripgrep
下载: wget -> axel
git终端: lazygit
Linux文本处理: awk, sed, cut

### LSP
c++: clangd
Expand Down
2 changes: 2 additions & 0 deletions root/.gitconfig
Original file line number Diff line number Diff line change
@@ -1,5 +1,7 @@
#[url "https://github.moeyy.xyz/https://github.com/"]
# insteadOf = https://github.com/
[core]
editor = vim
[diff]
tool = vimdiff
[difftool]
Expand Down
2 changes: 2 additions & 0 deletions root/.globalrc
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
default:\
:skip=tags,TAGS,gtags.files,cscope.files,cscope.out,cscope.po.out,cscope.in.out,*.o,*.a,*.so,*.lo,*.zip,*.gz,*.bz2,*.xz,*.tgz,build/,third_party/:
8 changes: 4 additions & 4 deletions root/vimrc.d/timer.vim → root/.vim/autoload/timer.vim
Original file line number Diff line number Diff line change
@@ -1,19 +1,19 @@
let g:timers = {}

function s:timerAutoSave(timer)
function s:autoSave(timer)
if &readonly == 0 && &modified == 1
silent write
" echo 'auto saved at ' . strftime('%X')
endif
endfunction

function TimerStartAutoSave()
function timer#startAutoSave()
if !has_key(g:timers, 'auto_save')
let g:timers.auto_save = timer_start(30000, 's:timerAutoSave', {'repeat': -1})
let g:timers.auto_save = timer_start(30000, 's:autoSave', {'repeat': -1})
endif
endfunction

function TimerStopAutoSave()
function timer#stopAutoSave()
if has_key(g:timers, 'auto_save')
let timer = g:timers['auto_save']
call timer_stop(timer)
Expand Down
92 changes: 83 additions & 9 deletions root/.vim/doc/mydoc.txt
Original file line number Diff line number Diff line change
Expand Up @@ -5,25 +5,94 @@
MyDoc *mydoc*

1. Basic |my-basic|
2. Markdown |my-markdown|
2. Git |my-git|
2.1 Diff |my-git-diff|
2.2 Merge |my-git-merge|
3. Tags |my-tags|
4. Format |my-format|
5. Lint |my-lint|
6. Markdown |my-markdown|
7. LSP(coc.nvim) |my-lsp|

===============================================================================
1. Basic *my-basic*

welcome: `:intro` `:smile`
Welcome: `:intro` `:smile`

cheetsheets: https://devhints.io/vim-help
Cheetsheets: https://devhints.io/vim-help

close all the other windows: `:only` (similar `:tabonly`)
Close all the other windows: `:only` (similar `:tabonly`)

paste in (search-)command-mode: `<C-R>"`
Paste in (search-)command-mode: `<C-R>"`

split with height 10 and open buffer 1: `:10sp #1`
Execute selected(yanked) text: `:@"`, see `:h :@`

create terminal in new tab: `:tab ter`
Split with height 10 and open buffer 1: `:10sp #1`

===============================================================================
2. Markdown *my-markdown*
Create terminal in new tab: `:tab ter`

Increment Number: `<C-A>`

Global Replace:
Put grep results into quickfixlist, then replace by `:cdo` >
:cdo %s/<search term>/<replace term>/cg
<

Add ` galaxy` to the end of line: `:%s/$/ galaxy/g`
Add `hello ` to the begin of line: `:%s/^/hello /g`

-------------------------------------------------------------------------------
2. Git *my-git*
2.1 Diff *my-git-diff*

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

-------------------------------------------------------------------------------
2.2 Merge *my-git-merge*

Tutorial: https://gist.github.com/karenyyng/f19ff75c60f18b4b8149
`git mergetool`

Clean LOCAL, BASE, REMOTE files: >
git clean -i
<

-------------------------------------------------------------------------------
3. Tags *my-tags*

See root/vimrc.d/tags.vim

Comparison with ctags, gtags and cscope:
https://github.com/oracle/opengrok/wiki/Comparison-with-Similar-Tools

gtags(global) > cscope > ctags

Universal Ctags: a maintained implementation of ctags
Exuberant Ctags: unmaintained

Install on Ubuntu: >
sudo apt install global
sudo apt install cscpoe
sudo apt install universal-ctags
# sudo apt insatll exuberant-ctags
<

-------------------------------------------------------------------------------
4. Format *my-format*

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

-------------------------------------------------------------------------------
5. Lint *my-lint*

*clang-tidy*
output to quickfix list: >
:CExprsys clang-tidy hello.cpp
<

-------------------------------------------------------------------------------
6. Markdown *my-markdown*

*marp* Markdown Presentation Ecosystem

Expand All @@ -36,3 +105,8 @@ watch mode >
md -> html >
:AsyncRun npx @marp-team/marp-cli@latest note.md
<

-------------------------------------------------------------------------------
7. LSP(coc.nvim) *my-lsp*

TODO: LSP formatter, LSP linter
15 changes: 11 additions & 4 deletions root/.vim/doc/unused.txt
Original file line number Diff line number Diff line change
@@ -1,22 +1,29 @@
*unused.txt*
*awesome.txt*

Unused Plugins/Scripts~
Awesome Plugins/Scripts~
=======================================================================================

*mhinz/vim-startify* beautify dashboard, see >
git show v0.2.1:root/vimrc.d/startify.vim
<
*vim-airline/vim-airline* beautify status line

*skywind3000/vim-quickui*: top menu
*skywind3000/vim-quickui* top menu

*preservim/nerdtree* file system explorer, see >
git show v0.2.1:root/vimrc.d/nerdtree.vim
<
*tpope/vim-fugitive* a git wrapper

*skywind3000/asyncrun.vim* *skywind3000/asynctask.vim*
enhanced workflow, async task system
Async run command. Async task system, replaces `:RunCode` script. >
" RunCode
autocmd FileType c :command! -nargs=0 RunCode :!cc % -o %:r && ./%:r
autocmd FileType cpp :command! -nargs=0 RunCode :!c++ % -o %:r && ./%:r
autocmd FileType python :command! -nargs=0 RunCode :!python3 %

nnoremap <Leader>rc :RunCode<CR>
<

Terminal Manager: https://zhuanlan.zhihu.com/p/469396812

Expand Down
10 changes: 10 additions & 0 deletions root/.vim/ftplugin/html.vim
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
" https://www.zhihu.com/question/547708456/answer/2645630850
function HtmlPrettify()
if &filetype != 'html'
echo 'not a html file'
return
endif
silent! exec "s/<[^.]*>/\r&\r/g"
silent! exec "g/^$/d"
exec "normal ggVG="
endfunction
42 changes: 42 additions & 0 deletions root/.vim/tasks.ini
Original file line number Diff line number Diff line change
@@ -0,0 +1,42 @@
[file-build]
command:c=gcc -O2 -Wall "$(VIM_FILEPATH)" -o "$(VIM_PATHNOEXT)" -lstdc++ -lm -msse3
command:cpp=g++ -O2 -Wall "$(VIM_FILEPATH)" -o "$(VIM_PATHNOEXT)" -lstdc++ -lm -msse3
command:go=go build -o "$(VIM_PATHNOEXT)" "$(VIM_FILEPATH)"
command:make=make -f "$(VIM_FILEPATH)"
output=quickfix
cwd=$(VIM_FILEDIR)
save=2

[file-run]
command="$(VIM_FILEPATH)"
command:c,cpp="$(VIM_PATHNOEXT)"
command:go="$(VIM_PATHNOEXT)"
command:python=python3 "$(VIM_FILENAME)"
command:javascript=node "$(VIM_FILENAME)"
command:sh=sh "$(VIM_FILENAME)"
command:lua=lua "$(VIM_FILENAME)"
command:perl=perl "$(VIM_FILENAME)"
command:ruby=ruby "$(VIM_FILENAME)"
output=terminal
cwd=$(VIM_FILEDIR)
save=2

[project-build]
command:c,cpp=make
# set the working directory to the project root.
cwd:c,cpp=$(VIM_ROOT)

[project-run]
command:c,cpp=make run
# <root> is an alias to `$(VIM_ROOT)`, a little easier to type.
cwd:c,cpp=<root>
output:c,cpp=terminal

[ctags]
command:c,cpp=ctags -R --exclude=build --exclude=third_party --exclude=doc *

[cscope]
command:cpp=find . -name '*.cc' -or -name '*.h' > cscope.files && cscope -Rbq

[gtags]
command=gtags
45 changes: 25 additions & 20 deletions root/.vimrc
Original file line number Diff line number Diff line change
@@ -1,6 +1,5 @@
set nocp
" Sets how many lines of history VIM has to remember
set history=500
set nocp "no Vi-compatible
set history=500 " Sets how many lines of history VIM has to remember

" Enable filetype plugins
filetype indent on
Expand All @@ -15,6 +14,8 @@ set backspace=indent,eol,start "indent: BS可以删除缩进; eol: BS可以删
set hidden " 未保存文本就可以隐藏buffer
set cmdheight=1 " cmd行高1
set updatetime=700 " GitGutter更新和自动保存.swp的延迟时间
set timeoutlen=3000 " key map 超时时间

if has("nvim-0.5.0") || has("patch-8.1.1564")
set signcolumn=number " 合并git状态与行号
else
Expand Down Expand Up @@ -63,16 +64,10 @@ hi debugPC term=reverse ctermbg=4 guibg=darkblue
autocmd Filetype c,cpp packadd termdebug
let g:termdebug_wide = 1

" Netrw Plugin
" let g:loaded_netrw = 1
" let g:loaded_netrwPlugin = 1

" RunCode
autocmd FileType c :command! -nargs=0 RunCode :!cc % -o %:r && ./%:r
autocmd FileType cpp :command! -nargs=0 RunCode :!c++ % -o %:r && ./%:r
autocmd FileType python :command! -nargs=0 RunCode :!python3 %

nnoremap <Leader>rc :RunCode<CR>
" Commenting blocks of code.
augroup commenting_blocks_of_code
autocmd!
Expand All @@ -83,8 +78,9 @@ augroup commenting_blocks_of_code
autocmd FileType vim let b:comment_leader = '" '
augroup end

" a sed (s/what/towhat/where) command changing ^ (start of line) to the correctly set comment character based on the type of file you have opened
" as for the silent thingies they just suppress output from commands.
" https://stackoverflow.com/questions/1676632/whats-a-quick-way-to-comment-uncomment-lines-in-vim
" A sed (s/what/towhat/where) command changing ^ (start of line) to the correctly set comment character based on the type of file you have opened
" As for the silent thingies they just suppress output from commands.
" :nohlsearch stops it from highlighting the sed search
noremap <silent> <leader>cc :<C-B>silent <C-E>s/^/<C-R>=escape(b:comment_leader,'\/')<CR>/<CR>:nohlsearch<CR>
noremap <silent> <leader>cu :<C-B>silent <C-E>s/^\V<C-R>=escape(b:comment_leader,'\/')<CR>//e<CR>:nohlsearch<CR>
Expand Down Expand Up @@ -176,19 +172,22 @@ nnoremap <silent> <leader>fd :call VimGrepFindDefinition(expand("<cword>"))<CR>
vnoremap <silent> <leader>fd :call VimGrepFindDefinition(GetVisualSelection())<CR>
command! -nargs=1 Vimfd call VimGrepFindDefinition(<q-args>)

" vim.fandom.com/wiki/Searching_for_files
" Reference vim.fandom.com/wiki/Searching_for_files
" find files and populate the quickfix list
function FindFiles(filename)
let error_file = tempname()
silent exe '!find . -name "*'.a:filename.'*" | xargs file | sed "s/:/:1:/" > '.error_file
cexpr system('find . -name "*'.a:filename.'*" | xargs file | sed "s/:/:1:/"')
set errorformat=%f:%l:%m
exe "cfile ". error_file
call ShowQuickfixListIfNotEmpty()
call delete(error_file)
endfunction
command! -nargs=1 Fd call FindFiles(<q-args>)

" quickfix window
function Ripgrep(args)
cexpr system('rg --vimgrep ' . a:args)
call ShowQuickfixListIfNotEmpty()
endfunction
command! -nargs=1 Rg call Ripgrep(<q-args>)

"""""""""""""""""""""""""""""""""""""" quickfix window
nnoremap <silent> co :copen<CR>
nnoremap <silent> cn :cn<CR>
nnoremap <silent> cp :cp<CR>
Expand All @@ -198,7 +197,13 @@ vnoremap <silent> <leader>t :term ++open ++rows=9<CR>
nnoremap <silent> <leader>t :term ++rows=9<CR>
tnoremap <silent> <leader>t <C-W>:hide<CR>
function CExprSystem(args)
cexpr system(a:args)
call ShowQuickfixListIfNotEmpty()
endfunction
command! -nargs=1 CExprsys call CExprSystem(<q-args>)
""""""""""""""""""""""""""""""""""""""""""""""""""""""

helptags ~/.vim/doc
source ~/vimrc.d/timer.vim
source ~/vimrc.d/markdown.vim
source ~/vimrc.d/tags.vim
source ~/vimrc.d/plugin.vim
7 changes: 7 additions & 0 deletions root/vimrc.d/asynctasks.vim
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
Plug 'skywind3000/asynctasks.vim'
Plug 'skywind3000/asyncrun.vim'

let g:asyncrun_open = 6 " open quickfix window automatically at 6 lines height after command starts
let g:asyncrun_rootmarks = ['.git', '.root']
let g:asynctasks_term_pos = 'tab'
let g:asynctasks_term_reuse = 1
8 changes: 0 additions & 8 deletions root/vimrc.d/clang_format_config.vim

This file was deleted.

3 changes: 1 addition & 2 deletions root/vimrc.d/cpp.vim
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
Plug 'bfrg/vim-cpp-modern'
Plug 'bfrg/vim-cpp-modern', {'for': 'cpp'}
" Enable function highlighting (affects both C and C++ files)
let g:cpp_function_highlight = 1

Expand All @@ -12,4 +12,3 @@ let g:cpp_member_highlight = 1
" (affects both C and C++ files)
let g:cpp_simple_highlight = 1

source ~/vimrc.d/clang_format_config.vim
2 changes: 1 addition & 1 deletion root/vimrc.d/go.vim
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
Plug 'fatih/vim-go', { 'do': ':GoUpdateBinaries' }
Plug 'fatih/vim-go', { 'do': ':GoUpdateBinaries', 'for': 'go' }
" 禁用vim-go的lsp功能,使用coc.nvim的lsp
let g:go_gopls_enabled = 0
let g:go_code_completion_enabled = 0
Expand Down
Loading

0 comments on commit afcdbaa

Please sign in to comment.