Skip to content

Instantly share code, notes, and snippets.

Embed
What would you like to do?
A plugin of SublimeText 3 : Let the FOLDER of a new untitled file be as same as the folder of current activated file.
# NewFileAtCurrentFolder
import sublime_plugin
import os.path
class NewFileListener(sublime_plugin.EventListener):
def on_new_async(self, view):
if not view.window().active_view():
print("NF: no view")
return
newView = view.window().active_view()
index = view.window().views().index(newView)
lastView = view.window().views()[index - 1]
if not lastView:
print("NF: no lastView")
return
fileName = lastView.file_name()
if not fileName:
print("NF: no fileName")
return
basePath = os.path.dirname(fileName)
if not basePath:
print("NF: no basePath")
return
print("NF: "+basePath)
newView.settings().set('default_dir', basePath)
@Whoaa512

This comment has been minimized.

Copy link

@Whoaa512 Whoaa512 commented Oct 22, 2015

Thank you!

@rexzj266

This comment has been minimized.

Copy link

@rexzj266 rexzj266 commented Oct 29, 2015

This is what I need. Thank you. :)

@Rykus0

This comment has been minimized.

Copy link

@Rykus0 Rykus0 commented Oct 29, 2015

Not sure why they changed it. This is much better, thank you!

@RonanCodes

This comment has been minimized.

Copy link

@RonanCodes RonanCodes commented Mar 12, 2016

In case anybody is wondering where to save this file.
Just drop the NewFile.py file into your Packages/User folder within your Sublime folder.

For Sublime 3 this is my location (where <your_name> is, your name):
/Users/<your_name>/Library/Application Support/Sublime Text 3/Packages/User

@samharad

This comment has been minimized.

Copy link

@samharad samharad commented Apr 6, 2016

Very helpful - thank you!

@clowestab

This comment has been minimized.

Copy link

@clowestab clowestab commented Oct 15, 2016

Thanks for this.

@Tehada

This comment has been minimized.

Copy link

@Tehada Tehada commented Feb 19, 2017

@RonanC Thanks!

@iminif

This comment has been minimized.

Copy link

@iminif iminif commented Jul 29, 2017

Great!

@toph-allen

This comment has been minimized.

Copy link

@toph-allen toph-allen commented Nov 7, 2019

Awesome!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
You can’t perform that action at this time.