OOZOU
Get in Touch
Back to TIL
vim

Rename files in VIM

October 13, 2020

Here's a handy function that I use to rename files in VIM (works in MacVIM and Neovim too)

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>

NOTE: I've used <leader> which is mapped to comma in my config. but you can use whatever key combiniation you like.

More on vim

vimOctober 13, 2020

How to quit Vim

1. Install latest version of Vim 2. Open a file in Vim 3. ⌘-Q and close the terminal 4. Reopen terminal

vimOctober 13, 2020

How to really!! quit vim

In terminal

vimOctober 13, 2020

How to save a file with sudo in VIM

How to save a file with sudo in VIM

Have a project in mind?

We'd love to hear what you're building.

Start a Conversationhello@oozou.com
OOZOU Logo

Bangkok · Singapore · Hong Kong

X
Facebook
Instagram
LinkedIn

Services

  • Web Development
  • AI & Generative AI Solutions
  • Mobile App Development
  • Data Analytics & Engineering
  • UI/UX Design & Product Design
  • Digital Transformation

Company

  • About Us
  • Careers
  • Blog
  • Whitepapers
  • Case Studies
  • Today I Learned
  • Contact

More

  • Industries
  • Get an Estimate
  • Partner Network
© 2026 OOZOU. All rights reserved.
Privacy PolicyCode of ConductABAC Policy