Using F2 to Rename Open Files

Posted Trace Spaces

tags:

篇首语:本文由小常识网(cha138.com)小编为大家整理,主要介绍了Using F2 to Rename Open Files相关的知识,希望对你有一定的参考价值。

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
 

以上是关于Using F2 to Rename Open Files的主要内容,如果未能解决你的问题,请参考以下文章

oracle rename数据文件的两种方法

对文件内容去重后写入另一文件

dbm.error: need 'c' or 'n' flag to open new db

shell function/for in/for (())/string concat/has dir/rename using regex/if(())/exit/execute command

3D Computer Grapihcs Using OpenGL - 07 Passing Data from Vertex to Fragment Shader

Unable to lock the administration directory (/var/lib/dpkg/),is another process using it?