{"id":15287027,"url":"https://github.com/lahmatiy/open-in-editor","last_synced_at":"2025-04-04T22:08:24.657Z","repository":{"id":46113876,"uuid":"42957287","full_name":"lahmatiy/open-in-editor","owner":"lahmatiy","description":"NPM package to open a file in editor","archived":false,"fork":false,"pushed_at":"2021-11-13T14:53:01.000Z","size":58,"stargazers_count":207,"open_issues_count":12,"forks_count":18,"subscribers_count":6,"default_branch":"master","last_synced_at":"2025-03-28T21:07:56.800Z","etag":null,"topics":["atom-editor","idea","phpstorm","sublime-text","vscode","webstorm"],"latest_commit_sha":null,"homepage":"","language":"JavaScript","has_issues":true,"has_wiki":null,"has_pages":null,"mirror_url":null,"source_name":null,"license":"mit","status":null,"scm":"git","pull_requests_enabled":true,"icon_url":"https://github.com/lahmatiy.png","metadata":{"files":{"readme":"README.md","changelog":"HISTORY.md","contributing":null,"funding":null,"license":"LICENSE","code_of_conduct":null,"threat_model":null,"audit":null,"citation":null,"codeowners":null,"security":null,"support":null}},"created_at":"2015-09-22T19:53:24.000Z","updated_at":"2025-02-20T07:10:29.000Z","dependencies_parsed_at":"2022-09-26T18:31:06.805Z","dependency_job_id":null,"html_url":"https://github.com/lahmatiy/open-in-editor","commit_stats":null,"previous_names":[],"tags_count":6,"template":false,"template_full_name":null,"repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/lahmatiy%2Fopen-in-editor","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/lahmatiy%2Fopen-in-editor/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/lahmatiy%2Fopen-in-editor/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/lahmatiy%2Fopen-in-editor/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/lahmatiy","download_url":"https://codeload.github.com/lahmatiy/open-in-editor/tar.gz/refs/heads/master","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":247256115,"owners_count":20909240,"icon_url":"https://github.com/github.png","version":null,"created_at":"2022-05-30T11:31:42.601Z","updated_at":"2022-07-04T15:15:14.044Z","host_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub","repositories_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories","repository_names_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repository_names","owners_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners"}},"keywords":["atom-editor","idea","phpstorm","sublime-text","vscode","webstorm"],"created_at":"2024-09-30T15:23:55.456Z","updated_at":"2025-04-04T22:08:24.633Z","avatar_url":"https://github.com/lahmatiy.png","language":"JavaScript","funding_links":[],"categories":[],"sub_categories":[],"readme":"[![NPM version](https://img.shields.io/npm/v/open-in-editor.svg)](https://www.npmjs.com/package/open-in-editor)\n\nNPM package to open a file in editor.\n\nSupported editors:\n\n- [Sublime Text](http://www.sublimetext.com/)\n- [Atom Editor](https://atom.io/)\n- [Visual Studio Code](https://code.visualstudio.com/)\n- [WebStorm](https://www.jetbrains.com/webstorm/)\n- [PhpStorm](https://www.jetbrains.com/phpstorm/)\n- [IDEA 14 Community Edition](https://www.jetbrains.com/idea/download/)\n- [Vim](http://www.vim.org/)\n- [Emacs](https://www.gnu.org/software/emacs/)\n- [Visual Studio](https://www.visualstudio.com/)\n\nYou also can use any other editor that is able to open files from command line.\n\n## Installation\n\n```\nnpm install open-in-editor\n```\n\n## Usage\n\nFirst of all you should create an interface with your settings.\n\n```js\nvar openInEditor = require('open-in-editor');\nvar editor = openInEditor.configure({\n  // options\n}, function(err) {\n  console.error('Something went wrong: ' + err);\n});\n```\n\nResulting object has a single method `open`. This method runs terminal command that opens an editor. Result of this method is a promise:\n\n```js\neditor.open('path/to/file.js:3:10')\n  .then(function() {\n    console.log('Success!');\n  }, function(err) {\n    console.error('Something went wrong: ' + err);\n  });\n```\n\n## API\n\n```\nopenInEditor.configure([options][, failCallback]);\n```\n\nArguments:\n\n- `options` – *optional* is used to set up a command to launch an editor. If no options set it will try to get the command from [environment](#environment)\n- `failCallback` – *optional* function that is called when something's wrong with editor setup.\n\nIf editor setup was successful `configure` method returns an interface with single method `open`. The method accepts file reference with the following format: `filename[:line[:column]]`, where `line` and `column` tell the editor where to place cursor when file is opened.\n\n### Options\n\n#### editor\n\nType: `String` or `null`  \nValues: `'sublime'`, `'atom'`, `'code'`, `'webstorm'`, `'phpstorm'`, `'idea14ce'`, `'vim'`, `'emacs'`, `'visualstudio'`  \nDefault: `null`\n\nEditor to open a file. Once value is set, we try to detect a command to launch an editor.\n\nSupported editors:\n\n- `sublime` – Sublime Text\n- `atom` – Atom Editor\n- `code` – Visual Studio Code\n- `webstorm` – WebStorm\n- `phpstorm` - PhpStorm\n- `idea14ce` – IDEA 14 CE\n- `vim` – Vim (via Terminal, Mac OS only)\n- `emacs` – Emacs (via Terminal, Mac OS only)\n- `visualstudio` – Visual Studio\n\n#### cmd\n\nType: `String` or `null`  \nDefault: `null`\n\nCommand to launch an editor.\n\n```js\nvar openInEditor = require('open-in-editor');\nvar editor = openInEditor.configure({\n  cmd: '/path/to/editor/app'\n});\n```\n\nIf `editor` option is also set, an editor settings are using as default settings.\n\n```js\nvar openInEditor = require('open-in-editor');\nvar editor = openInEditor.configure({\n  editor: 'code',\n  cmd: '/path/to/editor/app' // will be called as '/path/to/editor/app -r -g {filename}:{line}:{column}'\n});\n```\n\n#### pattern\n\nType: `String` or `null`  \nDefault: `null`\n\nOption to specify arguments for a command. Pattern can contain placeholders to be replaced by actual values. Supported placeholders: `filename`, `line` and `column`.\n\n```js\nvar openInEditor = require('open-in-editor');\nvar editor = openInEditor.configure({\n  cmd: 'code',\n  pattern: '-r -g {filename}:{line}:{column}'\n});\n```\n\nIf there's no `{filename}` placeholder in the command then `{filename}:{line}:{column}` is appended. That way previous example can be simplified:\n\n```js\nvar openInEditor = require('open-in-editor');\nvar editor = openInEditor.configure({\n  cmd: 'code',\n  pattern: '-r -g' // the same as '-r -g {filename}:{line}:{column}'\n});\n```\n\n#### line\n\nType: `Number`  \nDefault: `1`\n\nDefines the number of the first line in the editor. Usually it's `1`, but you can set it to `0`.\n\n#### column\n\nType: `Number`  \nDefault: `1`\n\nDefines the number of the first column in the editor. Usually it's `1`, but you can set it to `0`.\n\n\n## Environment\n\nIf no `editor` or `cmd` option is specified, we try to get the command to launch an editor using environment settings. Following values can be used (in descending priority):\n\n- `process.env.OPEN_FILE`\n- `process.env.VISUAL`\n- `process.env.EDITOR`\n\nFirst value found is used. If it's `process.env.VISUAL` or `process.env.EDITOR`, it's used directly as `cmd` option. But `process.env.OPEN_FILE` is different: if value is a valid for `editor` option, it's used for it, otherwise it's used as a value for `cmd` option.\n\nYou can set env settings per command:\n\n```\nOPEN_FILE=atom oe path/to/file.js:4:15\nOPEN_FILE=\"code -r -g\" node script.js\n```\n\n## CLI\n\nPackage could be installed globally.\n\n```\nnpm install open-in-editor -g\n```\n\nIn this case `oe` command will be available in terminal.\n\n```\nUsage:\n\n  oe [filename] [options]\n\nOptions:\n\n      --cmd \u003ccommand\u003e      Command to open file\n      --debug              Debug errors\n  -e, --editor \u003ceditor\u003e    Editor: atom, code, sublime, webstorm, phpstorm, idea14ce, vim, visualstudio, emacs\n  -f, --file \u003cfilename\u003e    File to open\n  -h, --help               Output usage information\n  -p, --pattern \u003cpattern\u003e  Filename pattern and args, i.e. something going after cmd\n  -v, --version            Output the version\n```\n\n## Related projects\n\n- [express-open-in-editor](https://github.com/lahmatiy/express-open-in-editor) – `Express` extension to open files from browser.\n- [babel-plugin-source-wrapper](https://github.com/restrry/babel-plugin-source-wrapper) – `Babel` plugin that instruments source code to associate objects with location they defined in code base.\n- [Component Inspector](https://github.com/lahmatiy/component-inspector) – developer tool to inspect components that can open component creation source location in editor. Has integrations for `React`, `Backbone` and can be adopted for other frameworks.\n\n## License\n\nMIT\n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Flahmatiy%2Fopen-in-editor","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Flahmatiy%2Fopen-in-editor","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Flahmatiy%2Fopen-in-editor/lists"}