mirror of
https://github.com/jbranchaud/til
synced 2026-01-03 23:28:02 +00:00
Add Rename Current File to vim til.
This commit is contained in:
@@ -32,6 +32,7 @@ smart people at [Hashrocket](http://hashrocket.com/).
|
|||||||
- [Preview Buffer](vim/previous-buffer.md)
|
- [Preview Buffer](vim/previous-buffer.md)
|
||||||
- [Quick File Info](vim/quick-file-info.md)
|
- [Quick File Info](vim/quick-file-info.md)
|
||||||
- [Quick Man Pages](vim/quick-man-pages.md)
|
- [Quick Man Pages](vim/quick-man-pages.md)
|
||||||
|
- [Rename Current File](vim/rename-current-file.md)
|
||||||
- [Split Different](vim/split-different.md)
|
- [Split Different](vim/split-different.md)
|
||||||
|
|
||||||
## About
|
## About
|
||||||
|
|||||||
18
vim/rename-current-file.md
Normal file
18
vim/rename-current-file.md
Normal file
@@ -0,0 +1,18 @@
|
|||||||
|
# Rename Current File
|
||||||
|
|
||||||
|
Vim doesn't come with an easy way to rename the existing, current file. The
|
||||||
|
closest you will get with a one-off command is `:saveas {new file name}`
|
||||||
|
which renames the current buffer, but also leaves you with your old file.
|
||||||
|
|
||||||
|
Another approach that you can take is to chain two commands together. You
|
||||||
|
can start be *deleting* the current file (don't worry, you've still got the
|
||||||
|
file contents in your buffer) and then *saving* the buffer with the new
|
||||||
|
name. Like so:
|
||||||
|
|
||||||
|
```
|
||||||
|
:call delete(expand('%')) | saveas new-file-name.txt
|
||||||
|
```
|
||||||
|
|
||||||
|
While this seems to do the job well enough, your mileage may vary.
|
||||||
|
Consider using a more robust plugin, such as
|
||||||
|
[rename.vim](https://github.com/danro/rename.vim/blob/master/plugin/rename.vim).
|
||||||
Reference in New Issue
Block a user