Renaming open files in sublime text 2
--------------------------------------------------
Rise to the top 3% as a developer or hire one of them at Toptal: https://topt.al/25cXVn
--------------------------------------------------
Music by Eric Matyas
https://www.soundimage.org
Track title: Digital Sunset Looping
--
Chapters
00:00 Renaming Open Files In Sublime Text 2
00:45 Accepted Answer Score 7
01:19 Answer 2 Score 8
01:41 Answer 3 Score 3
01:49 Thank you
--
Full question
https://superuser.com/questions/683766/r...
--
Content licensed under CC BY-SA
https://meta.stackexchange.com/help/lice...
--
Tags
#keyboardshortcuts #sublimetext2 #rename
#avk47
Rise to the top 3% as a developer or hire one of them at Toptal: https://topt.al/25cXVn
--------------------------------------------------
Music by Eric Matyas
https://www.soundimage.org
Track title: Digital Sunset Looping
--
Chapters
00:00 Renaming Open Files In Sublime Text 2
00:45 Accepted Answer Score 7
01:19 Answer 2 Score 8
01:41 Answer 3 Score 3
01:49 Thank you
--
Full question
https://superuser.com/questions/683766/r...
--
Content licensed under CC BY-SA
https://meta.stackexchange.com/help/lice...
--
Tags
#keyboardshortcuts #sublimetext2 #rename
#avk47
ANSWER 1
Score 8
Reference: http://www.sublimetext.com/forum/viewtopic.php?f=2&t=9534
Another simple way to set up a keyboard shortcut for renaming files:
Install SideBar Enhancements, and set up the shortcut in Key Bindings - User
:
{ "keys": ["your shortcut combination"], "command": "side_bar_move" }
ACCEPTED ANSWER
Score 7
Copy to your User keymap
{ "keys": ["shift+f2"], "command": "rename_file", "args": { "paths": ["$file"] } }
Create directory/file in your Packages folder: "...Packages/RenameFile/rename_file.py"
import sublime
import sublime_plugin
import os
import functools
class RenameFileCommand(sublime_plugin.WindowCommand):
def run(self, paths):
if paths[0] == "$file":
paths[0] = self.window.active_view().file_name()
branch, leaf = os.path.split(paths[0])
v = self.window.show_input_panel("New Name:", leaf, functools.partial(self.on_done, paths[0], branch), None, None)
name, ext = os.path.splitext(leaf)
v.sel().clear()
v.sel().add(sublime.Region(0, len(name)))
def on_done(self, old, branch, leaf):
new = os.path.join(branch, leaf)
try:
os.rename(old, new)
v = self.window.find_open_file(old)
if v:
v.retarget(new)
except:
sublime.status_message("Unable to rename")
def is_visible(self, paths):
return len(paths) == 1
ANSWER 3
Score 3
Here is a package for Sublime Text 3: