1
0
mirror of https://github.com/SpaceVim/SpaceVim.git synced 2025-04-14 15:19:12 +08:00

feat(mapping): add SPC f R to rename current file

This commit is contained in:
wsdjeg 2022-04-04 14:35:55 +08:00
parent bc5e24c693
commit 2506fec3a0
3 changed files with 33 additions and 2 deletions

View File

@ -153,6 +153,9 @@ function! SpaceVim#layers#core#config() abort
\ ]
\ ]
\ , 1)
call SpaceVim#mapping#space#def('nnoremap', ['f', 'R'], 'call call('
\ . string(s:_function('s:rename_current_file')) . ', [])',
\ 'rename_current_file', 1)
call SpaceVim#mapping#space#def('nnoremap', ['f', 'a'], 'call call('
\ . string(s:_function('s:save_as_new_file')) . ', [])',
\ 'save-as-new-file', 1)
@ -975,6 +978,34 @@ augroup FileExplorer
augroup END
function! s:rename_current_file() abort
let current_fname = bufname()
if empty(current_fname)
echo 'can not rename empty filename!'
return
endif
let input = input('Rename to: ', fnamemodify(current_fname, ':p'), 'file')
noautocmd normal! :
if !empty(input)
exe 'silent! file ' . input
exe 'silent! w '
call delete(current_fname)
if v:errmsg !=# ''
echohl ErrorMsg
echo v:errmsg
echohl None
else
echohl Delimiter
echo fnamemodify(bufname(), ':.:gs?[\\/]?/?') . ' Renamed'
echohl None
endif
else
echo 'canceled!'
endif
endfunction
function! s:save_as_new_file() abort
let current_fname = bufname()
if !empty(current_fname)

View File

@ -1365,7 +1365,7 @@ SpaceVim 选项 `window_leader` 的值来设为其它按键:
| `SPC f f` | 在当前文件所在文件夹搜索文件 |
| `SPC f F` | 在当前文件所在的文件夹搜索光标下的文件 |
| `SPC f o` | 代开文件树,并定位到当前文件 |
| `SPC f R` | rename the current file(TODO) |
| `SPC f R` | 重命名当前文件 |
| `SPC f s` / `Ctrl-s` | 保存文件 (:w) |
| `SPC f a` | 另存为新的文件 |
| `SPC f W` | 使用管理员模式保存 |

View File

@ -1437,7 +1437,7 @@ Files manipulation commands (start with `f`):
| `SPC f f` | fuzzy find files in buffer directory |
| `SPC f F` | fuzzy find cursor file in buffer directory |
| `SPC f o` | Find current file in file tree |
| `SPC f R` | rename the current file(TODO) |
| `SPC f R` | rename the current file |
| `SPC f s` | save a file |
| `SPC f a` | save as new file name |
| `SPC f S` | save all files |