เปลี่ยนชื่อไฟล์ใน VIM
13 ตุลาคม 2563
นี่คือฟังก์ชันสุดสะดวกที่ใช้เปลี่ยนชื่อไฟล์ใน VIM (ใช้งานได้ทั้งใน MacVIM และ Neovim ด้วย)
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
nnoremap <leader>n :call RenameFile()<cr>
หมายเหตุ: ในที่นี้ใช้ <leader> ซึ่งใน config ของผู้เขียน map ไว้กับปุ่ม comma แต่คุณจะใช้ key combination ไหนก็ได้ตามที่ชอบ