1
0
mirror of https://github.com/SpaceVim/SpaceVim.git synced 2025-01-23 07:10:06 +08:00

feat(core): Add SPC f a key binding to save as new file

Problem: There is no key binding to save current buffer as new file.
Solution: Add `SPC f a` key binding

close https://github.com/SpaceVim/SpaceVim/issues/4310
This commit is contained in:
Shidong Wang 2021-09-21 22:04:26 +08:00
parent 1bbc24ea4d
commit bdc0101b9a
No known key found for this signature in database
GPG Key ID: 41BB7053E835C848
3 changed files with 33 additions and 0 deletions

View File

@ -149,6 +149,9 @@ function! SpaceVim#layers#core#config() abort
call SpaceVim#mapping#space#def('nnoremap', ['f', 's'], 'call call('
\ . string(s:_function('s:save_current_file')) . ', [])',
\ 'save-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)
call SpaceVim#mapping#space#def('nnoremap', ['f', 'S'], 'wall', 'save-all-files', 1)
" help mappings
call SpaceVim#mapping#space#def('nnoremap', ['h', 'I'], 'call SpaceVim#issue#report()', 'report-issue-or-bug', 1)
@ -936,6 +939,34 @@ function! s:save_current_file() abort
endif
endfunction
function! s:save_as_new_file() abort
let current_fname = bufname()
if !empty(current_fname)
let dir = fnamemodify(current_fname, ':h') . s:FILE.separator
else
let dir = getcwd() . s:FILE.separator
endif
let input = input('save as: ', dir, 'file')
" clear cmdline
noautocmd normal! :
if !empty(input)
exe 'silent! write ' . input
exe 'e ' . input
if v:errmsg !=# ''
echohl ErrorMsg
echo v:errmsg
echohl None
else
echohl Delimiter
echo fnamemodify(bufname(), ':.:gs?[\\/]?/?') . ' written'
echohl None
endif
else
echo 'canceled!'
endif
endfunction
let g:_spacevim_autoclose_filetree = 1
function! s:explore_current_dir(cur) abort
if g:spacevim_filemanager ==# 'vimfiler'

View File

@ -1334,6 +1334,7 @@ SpaceVim 选项 `window_leader` 的值来设为其它按键:
| `SPC f o` | 代开文件树,并定位到当前文件 |
| `SPC f R` | rename the current file(TODO) |
| `SPC f s` / `Ctrl-s` | 保存文件 (:w) |
| `SPC f a` | 另存为新的文件 |
| `SPC f W` | 使用管理员模式保存 |
| `SPC f S` | 保存所有文件 |
| `SPC f r` | 打开文件历史 |

View File

@ -1424,6 +1424,7 @@ Files manipulation commands (start with `f`):
| `SPC f o` | Find current file in file tree |
| `SPC f R` | rename the current file(TODO) |
| `SPC f s` | save a file |
| `SPC f a` | save as new file name |
| `SPC f S` | save all files |
| `SPC f r` | open a recent file |
| `SPC f t` | toggle file tree side bar |