UNPKG

2.14 kBMarkdownView Raw
1# open-editor
2
3> Open files in your editor at a specific line and column
4
5Supports any editor, but only the following editors will open at a specific line and column:
6
7- Sublime Text
8- Atom
9- Visual Studio Code
10- VSCodium
11- WebStorm*
12- TextMate
13- Vim
14- NeoVim
15- IntelliJ IDEA*
16
17*\*Doesn't support column.*
18
19## Install
20
21```sh
22npm install open-editor
23```
24
25## Usage
26
27```js
28import openEditor from 'open-editor';
29
30openEditor([
31 {
32 file: 'readme.md',
33 line: 10,
34 column: 2,
35 }
36]);
37
38openEditor([
39 'unicorn.js:5:3',
40]);
41```
42
43## API
44
45### openEditor(files, options?)
46
47Open the given files in the user's editor at specific line and column if supported by the editor. It does not wait for the editor to start or quit unless you specify `wait: true` in the options.
48
49#### files
50
51Type: `Array<string | object>`
52
53Items should be in the format `foo.js:1:5` or `{file: 'foo.js', line: 1: column: 5}`.
54
55#### options
56
57Type: `object`
58
59##### wait
60
61Type: `boolean`\
62Default: `false`
63
64Wait until the editor is closed.
65
66```js
67import openEditor from 'open-editor';
68
69await openEditor(['unicorn.js:5:3'], {wait: true});
70
71console.log('File was closed');
72```
73
74##### editor
75
76Type: `string`\
77Default: [Auto-detected](https://github.com/sindresorhus/env-editor)
78
79The name, command, or binary path of the editor.
80
81**Only use this option if you really have to.** Can be useful if you want to force a specific editor or implement your own auto-detection.
82
83### getEditorInfo(files, options?)
84
85Same as `openEditor()`, but returns an object with the binary name, arguments, and a flag indicating whether the editor runs in the terminal.
86
87Example: `{binary: 'subl', arguments: ['foo.js:1:5'], isTerminalEditor: false}`
88
89Can be useful if you want to handle opening the files yourself.
90
91```js
92import {getEditorInfo} from 'open-editor';
93
94getEditorInfo([
95 {
96 file: 'foo.js',
97 line: 1,
98 column: 5,
99 }
100]);
101//=> {binary: 'subl', arguments: ['foo.js:1:5'], isTerminalEditor: false}
102```
103
104## Related
105
106- [open-editor-cli](https://github.com/sindresorhus/open-editor-cli) - CLI for this module
107- [open](https://github.com/sindresorhus/open) - Open stuff like URLs, files, executables