From 27d7b85ed4bcb2902474dd248fe0e2c7ab233179 Mon Sep 17 00:00:00 2001 From: srdusr Date: Wed, 20 Sep 2023 23:51:56 +0200 Subject: Rename file --- autoload/utils.vim | 26 ++++++++++++++++++++------ 1 file changed, 20 insertions(+), 6 deletions(-) (limited to 'autoload') diff --git a/autoload/utils.vim b/autoload/utils.vim index 1eeba25..69ef640 100644 --- a/autoload/utils.vim +++ b/autoload/utils.vim @@ -212,12 +212,26 @@ endfunction "------------------------------------------------- " On The Fly Table mode - function! s:isAtStartOfLine(mapping) - let text_before_cursor = getline('.')[0 : col('.')-1] - let mapping_pattern = '\V' . escape(a:mapping, '\') - let comment_pattern = '\V' . escape(substitute(&l:commentstring, '%s.*$', '', ''), '\') - return (text_before_cursor =~? '^' . ('\v(' . comment_pattern . '\v)?') . '\s*\v' . mapping_pattern . '\v$') - endfunction +function! s:isAtStartOfLine(mapping) + let text_before_cursor = getline('.')[0 : col('.')-1] + let mapping_pattern = '\V' . escape(a:mapping, '\') + let comment_pattern = '\V' . escape(substitute(&l:commentstring, '%s.*$', '', ''), '\') + return (text_before_cursor =~? '^' . ('\v(' . comment_pattern . '\v)?') . '\s*\v' . mapping_pattern . '\v$') +endfunction + + +"------------------------------------------------- + +" :Rename {newname} +function! RenameFile() + let old_name = expand('%') + let new_name = input('New file name: ', expand('%'), 'file') + if new_name != '' && new_name != old_name + exec ':saveas ' . new_name + exec ':silent !rm ' . old_name + redraw! + endif +endfunction "------------------------------------------------- -- cgit v1.2.3