diff --git a/autoload/notecrate.vim b/autoload/notecrate.vim index ed9dca8..6ad8ee7 100644 --- a/autoload/notecrate.vim +++ b/autoload/notecrate.vim @@ -361,6 +361,21 @@ function! notecrate#delete_note() " {{{ endif 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 . "\" + 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" 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 + " }}} " }}} diff --git a/ftplugin/notecrate.vim b/ftplugin/notecrate.vim index 61ca630..34eec70 100644 --- a/ftplugin/notecrate.vim +++ b/ftplugin/notecrate.vim @@ -4,6 +4,8 @@ setlocal comments+=b:* setlocal foldlevel=3 setlocal formatoptions=cro +command -nargs=1 Rename call notecrate#rename_note() + nnoremap c :call notecrate#convert() nnoremap o :call notecrate#search_open() nnoremap i :call notecrate#search_insert_link()