Click on filename to open in new tab with Sublime


Budge

Usually in my personal readme.txt file/log file I have some references to other .txt files. It can be a relative path ( ..\notes\blah.txt) or an absolute path (as shown in the screenshot below).

Is it possible for a .txt file to have this behavior in Sublime: double click on the filename to open it in a new tab?

enter image description here

Budge

Note: The Clickable URLs plugin isn't really useful to me as it parses the entire file, highlights the URL (due to nice regex), then listens for CTRL+ALT+ENTER: if the highlighted item Above 500, Sublime Text becomes unresponsive.


This is a workable solution.

  1. First put this file lllaunch.pyin your user package (for example C:\Users\User\AppData\Roaming\Sublime Text 2\Packages\User\):

    import sublime, sublime_plugin
    import subprocess
    import webbrowser
    import re
    
    BROWSER = 'C:\Program Files (x86)\Google\Chrome\Application\chrome.exe'
    EDITOR = 'C:\Program Files\Sublime Text 2\sublime_text.exe'
    
    class LllaunchCommand(sublime_plugin.TextCommand):
        def run(self, edit):
            for region in self.view.sel():
                s = self.view.substr(self.view.line(region))
                i = region.begin() - self.view.line(region).begin()
    
                start = 0
                end = -1
                for j, c in enumerate(s):
                    if c == ' ':
                        if j < i:
                            start = j
                        else:
                            end = j
                            break
                word = s[start:end].strip() if end != -1 else s[start:].strip()
                isurl = bool(re.match("\\bhttps?://[-A-Za-z0-9+&@#/%?=~_()|!:,.;']*[-A-Za-z0-9+&@#/%=~_(|]", word))
                if isurl:
                    webbrowser.register('mybrowser', None, webbrowser.GenericBrowser(BROWSER))
                    webbrowser.get('mybrowser').open(word)
                else:
                    s = '"' + s.split('"')[s[:i].count('"')] + '"'
    
                    command = '"%s" %s' % (EDITOR, s)
                    subprocess.Popen(command)
    
  2. Then add the following lines to C:\Users\User\AppData\Roaming\Sublime Text 2\Packages\User\Default (Windows).sublime-keymap:

    { "keys": ["ctrl+alt+enter"], "command": "lllaunch" }
    
  3. Restart Sublime Text.

  4. Now:

    • Doing CTRLALTENTERthe right URL will open the browser.
    • Doing it CTRLALTENTERwith quotes (like filename "C:\test\readme.txt") will edit the file in your favorite editor.

Related


Click on filename to open in new tab with Sublime

Budge Usually in my personal readme.txt file/log file I have some references to other .txt files. It can be a relative path ( ..\notes\blah.txt) or an absolute path (as shown in the screenshot below). Is it possible for a .txt file to have this behavior in Sub

Click on filename to open in new tab with Sublime

Budge Usually in my personal readme.txt file/log file I have some references to other .txt files. It can be a relative path ( ..\notes\blah.txt) or an absolute path (as shown in the screenshot below). Is it possible for a .txt file to have this behavior in Sub

Click on filename to open in new tab with Sublime

Budge Usually in my personal readme.txt file/log file I have some references to other .txt files. It can be a relative path ( ..\notes\blah.txt) or an absolute path (as shown in the screenshot below). Is it possible for a .txt file to have this behavior in Sub

Click on filename to open in new tab with Sublime

Budge Usually in my personal readme.txt file/log file I have some references to other .txt files. It can be a relative path ( ..\notes\blah.txt) or an absolute path (as shown in the screenshot below). Is it possible for a .txt file to have this behavior in Sub

Click on filename to open in new tab with Sublime

Budge Usually in my personal readme.txt file/log file I have some references to other .txt files. It can be a relative path ( ..\notes\blah.txt) or an absolute path (as shown in the screenshot below). Is it possible for a .txt file to have this behavior in Sub

CakePHP open to new tab on click

mark I have a function in my app where user can upload files to web server. These uploaded files will then appear in another page where another type of user can click the link. After clicking the link, a new tab will open and the file will be displayed. But I

Click the button to open a new tab

Nathan Wilson I want to create a link with a button that opens in a new tab. The code I'm currently using is currently opening a blank tab and I'm not sure why. <div class="text text-left"> <h2>WORK</h2> <h1>Title</h1> <p>Lorem ipsum dolor sit am

Click the button to open a new tab

Nathan Wilson I want to create a link with a button that opens in a new tab. The code I'm currently using is currently opening a blank tab and I'm not sure why. <div class="text text-left"> <h2>WORK</h2> <h1>Title</h1> <p>Lorem ipsum dolor sit am

CakePHP open to new tab on click

mark I have a function in my app where user can upload files to web server. These uploaded files will then appear in another page where another type of user can click the link. After clicking the link, a new tab will open and the file will be displayed. But I

Open a new tab after button click in AngularJS

Neptune: <button type="button" class="btn btn-primary" ng-click="openTab()">new tab</button> openTab = function () { $http.post('www.google.com'); } What I want is to post a requirement and then open the response html in a new tab when the "openTab" button

Selenium - click on the link to open a new tab

tree 55 I've seen a lot of threads on how to open a link in a new tab, but what if you have a link that creates a new tab and you need to verify the title? All I need to do is click the link -> confirm the new tab has the correct title -> close the tab and con

Protractor button click and open page in new tab

Sumitomo I am new to protractor. I'm trying to automate a scenario where I click a button and it opens a page in a new tab and then we need to populate the form in the new page and submit it. Problem : When I click the button to open a new page. My tests don't

Click on DIV to open embedded background in new tab

Paul VI I am dynamically inserting a background image in a DIV. <div class="mc-image " title="The Bridges" style="background-image: url(image.jpg);" data-href="link.html"></div> <div class="mc-image " title="The Bridges" style="background-image: url(image2.jpg

Click Primefaces in a new tab on the button to open the page

username i have this <h:outputLink value="http://.....index.html" target="_blank">open</h:outputLink> But it shows up as a link. How to create a similar button? I need the "Open" button. When I press this button I need to open the link in a new tab in the bro

Protractor button click and open page in new tab

Sumitomo I am new to protractor. I'm trying to automate a scenario where I click a button and it opens a page in a new tab and then we need to populate the form in the new page and submit it. Problem : When I click the button to open a new page. My tests don't

Open a new tab after button click in AngularJS

Neptune: <button type="button" class="btn btn-primary" ng-click="openTab()">new tab</button> openTab = function () { $http.post('www.google.com'); } What I want is to post a requirement and then open the response html in a new tab when the "openTab" button

Right click on svg to open new tab with element

Yukulele With firefox, when I middle-click (or ctrl+click) on an useelement , it will open the url xlink:hrefin a new tab (like href) Bug or feature? <svg viewBox="0 0 400 80"> <circle id="circle" cx="40" cy="40" r="30" fill="#29e"></circle> <use xlink

Selenium - click on the link to open a new tab

tree 55 I've seen a lot of threads on how to open a link in a new tab, but what if you have a link that creates a new tab and you need to verify the title? All I need to do is click the link -> confirm the new tab has the correct title -> close the tab and con

Selenium - click on the link to open a new tab

tree 55 I've seen a lot of threads on how to open a link in a new tab, but what if you have a link that creates a new tab and you need to verify the title? All I need to do is click the link -> confirm the new tab has the correct title -> close the tab and con

Open new tab on button click using JQUERY

Rajan My scene is like this: I have edit user module. Each user is assigned a base INI file . When we edit a user, we have a drop down menu from which to select his base INI file. After selection, we can save the user. And the ID of the selected file is also s

Right click on svg to open new tab with element

Yukulele With firefox, when I middle-click (or ctrl+click) on an useelement , it opens the url xlink:hrefin a new tab (like href) Bug or feature? <svg viewBox="0 0 400 80"> <circle id="circle" cx="40" cy="40" r="30" fill="#29e"></circle> <use xlink:hre

Click on the image to open a new tab in the HTML page

Gillan click on image to open new tab in html page how to add clickable image to open new tab in html page? Jeffrey Try this https://www.w3schools.com/jsref/met_win_open.asp <!DOCTYPE html> <html> <body> <p>Click the button to open multiple windows.</p> <a h

Click on DIV to open embedded background in new tab

Paul VI I am dynamically inserting a background image in a DIV. <div class="mc-image " title="The Bridges" style="background-image: url(image.jpg);" data-href="link.html"></div> <div class="mc-image " title="The Bridges" style="background-image: url(image2.jpg

Protractor button click and open page in new tab

Sumitomo I am new to protractor. I'm trying to automate a scenario where I click a button and it opens a page in a new tab and then we need to populate the form in the new page and submit it. Problem : When I click the button to open a new page. My tests don't

Click Primefaces in a new tab on the button to open the page

username i have this <h:outputLink value="http://.....index.html" target="_blank">open</h:outputLink> But it shows up as a link. How to create a similar button? I need the "Open" button. When I press this button I need to open the link in a new tab in the bro

Click Primefaces in a new tab on the button to open the page

username i have this <h:outputLink value="http://.....index.html" target="_blank">open</h:outputLink> But it shows up as a link. How to create a similar button? I need the "Open" button. When I press this button I need to open the link in a new tab in the bro

Click Primefaces in a new tab on the button to open the page

username i have this <h:outputLink value="http://.....index.html" target="_blank">open</h:outputLink> But it shows up as a link. How to create a similar button? I need the "Open" button. When I press this button I need to open the link in a new tab in the bro

Click on DIV to open inline background in new tab

Paul VI I am dynamically inserting a background image in a DIV. <div class="mc-image " title="The Bridges" style="background-image: url(image.jpg);" data-href="link.html"></div> <div class="mc-image " title="The Bridges" style="background-image: url(image2.jpg

Right click to enable "open in new tab/window"

Michael Chodakis My link is a javascript function that shows the loader and then navigates to the target link: <script> function go(url) { document.body.innerHTML = "some loader html"; window.location = url; } </script> <a href="javascript:go('test.php');"