Browse Source

lazygit 2022-03-28 18:06

master
Gregory Leeman 3 years ago
parent
commit
c8a56c36e6
  1. 20
      autoload/notecrate.vim
  2. 2
      ftplugin/notecrate.vim

20
autoload/notecrate.vim

@ -361,6 +361,21 @@ function! notecrate#delete_note() " {{{
endif endif
endfunction endfunction
" }}}
function! notecrate#rename_note(new) " {{{
let l:old = substitute(expand('%:t'), ".md", "", "g")
let l:new = a:new
let l:oldpath = b:notecrate_dir."/".l:old.".md"
let l:newpath = b:notecrate_dir."/".l:new.".md"
let choice = confirm('', "Rename " . l:old . ".md " . l:new . ".md? &Yes\n&No\n")
if choice == 1
silent execute "normal! :!mv " . l:oldpath . " " . l:newpath . "\<CR>"
call notecrate#open_note(a:new . ".md")
call notecrate#update_links(l:old, l:new)
call notecrate#update_backlinks()
endif
endfunction
" }}} " }}}
" }}} " }}}
@ -389,6 +404,11 @@ function! notecrate#delete_links(filename) " {{{
execute "!" . g:gsed_command . " -i 's/\\[\\([^]]*\\)\\](" . a:filename . ")/\\1/g' " . b:notecrate_dir . "/*md" execute "!" . g:gsed_command . " -i 's/\\[\\([^]]*\\)\\](" . a:filename . ")/\\1/g' " . b:notecrate_dir . "/*md"
endfunction endfunction
" }}}
function! notecrate#update_links(old, new) " {{{
execute "!" . g:gsed_command . " -i 's/" . a:old . ".md/" . a:new . ".md/g' " . b:notecrate_dir . "/*md"
endfunction
" }}} " }}}
" }}} " }}}

2
ftplugin/notecrate.vim

@ -4,6 +4,8 @@ setlocal comments+=b:*
setlocal foldlevel=3 setlocal foldlevel=3
setlocal formatoptions=cro setlocal formatoptions=cro
command -nargs=1 Rename call notecrate#rename_note(<f-args>)
nnoremap <buffer> <leader>c :call notecrate#convert()<CR> nnoremap <buffer> <leader>c :call notecrate#convert()<CR>
nnoremap <buffer> <leader>o :call notecrate#search_open()<CR> nnoremap <buffer> <leader>o :call notecrate#search_open()<CR>
nnoremap <buffer> <leader>i :call notecrate#search_insert_link()<CR> nnoremap <buffer> <leader>i :call notecrate#search_insert_link()<CR>