Skip to content

Commit

Permalink
add cf shortcut in codenote.vim
Browse files Browse the repository at this point in the history
  • Loading branch information
jiangyinzuo committed Aug 30, 2023
1 parent 330a991 commit 572f6c8
Show file tree
Hide file tree
Showing 3 changed files with 28 additions and 4 deletions.
2 changes: 1 addition & 1 deletion root/.vim/vimrc
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@ let g:coc_global_extensions = get(g:, 'coc_global_extensions', [])

" gtags-cscope | cscope
let g:tag_system = get(g:, 'tag_system', 'gtags-cscope')
let g:mapleader = get(g:, 'mapleader', '\')
let g:mapleader = get(g:, 'mapleader', ' ')
"""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""

set noexrc " 不读取当前文件夹的.vimrc
Expand Down
3 changes: 3 additions & 0 deletions root/.vim/vimrc.d/coc.vim
Original file line number Diff line number Diff line change
Expand Up @@ -84,6 +84,9 @@ xmap <leader>fmt <Plug>(coc-format-selected)
" Map function and class text objects
" NOTE: Requires 'textDocument.documentSymbol' support from the language server
" xmap 是用于Visual模式(不包括Select模式)的映射。
" omap 用于Operator-pending模式的映射。这种映射在你输入一个操作符(如 d 删除,y 复制,c 改变等)后,但在你完成整个操作(比如指定一个移动命令或文本对象)之前,生效。
" daf 删除当前函数文本对象
xmap if <Plug>(coc-funcobj-i)
omap if <Plug>(coc-funcobj-i)
xmap af <Plug>(coc-funcobj-a)
Expand Down
27 changes: 24 additions & 3 deletions root/.vim/vimrc.d/codenote.vim
Original file line number Diff line number Diff line change
Expand Up @@ -212,25 +212,46 @@ endfunction
" See also: root/vimrc.d/asynctasks.vim
function YankCodeLink(need_beginline, need_endline, append, goto_buf)
if exists("t:repo_type") && t:repo_type == "code"
if s:only_has_one_repo()
call s:open_note_repo(g:noterepo_dir)
endif
let l:file = expand("%:p")[len(g:coderepo_dir) + 1:]
let l:line = line(".")
let l:content = getline(".")
call s:yank_registers(l:file, l:line, l:content, a:need_beginline, a:need_endline, a:append)
if a:goto_buf
if s:only_has_one_repo()
call s:open_note_repo(g:noterepo_dir)
endif
call s:goto_note_buffer()
endif
endif
endfunction

" need_beginline, need_endline, append, goto_buf
nnoremap <silent> cr :call YankCodeLink(0, 0, 0, 1)<CR>
nnoremap <silent> cy :call YankCodeLink(1, 1, 0, 1)<CR>
nnoremap <silent> cb :call YankCodeLink(1, 0, 0, 0)<CR>
nnoremap <silent> ca :call YankCodeLink(0, 0, 1, 0)<CR>
nnoremap <silent> ce :call YankCodeLink(0, 1, 1, 1)<CR>
function YankCodeWithFunctionHeader()
if exists("t:repo_type") && t:repo_type == "code"
let l:file = expand("%:p")[len(g:coderepo_dir) + 1:]
let l:body_line = line(".")
let l:body_content = getline(".")
normal [f
let l:header_line = line(".")
let l:header_content = getline(".")

call s:yank_registers(l:file, l:header_line, l:header_content, 1, 0, 0)
call s:yank_registers(l:file, l:body_line, l:body_content, 0, 1, 1)

if s:only_has_one_repo()
call s:open_note_repo(g:noterepo_dir)
endif
call s:goto_note_buffer()
endif
endfunction
nnoremap <silent> cf :call YankCodeWithFunctionHeader()<CR>
function YankCodeLinkVisual(need_beginline, need_endline, append, goto_buf) range
if exists("t:repo_type") && t:repo_type == "code"
if s:only_has_one_repo()
Expand Down

0 comments on commit 572f6c8

Please sign in to comment.