File tree Expand file tree Collapse file tree 2 files changed +26
-1
lines changed Expand file tree Collapse file tree 2 files changed +26
-1
lines changed Original file line number Diff line number Diff line change @@ -10,7 +10,7 @@ smart people at [Hashrocket](http://hashrocket.com/).
10
10
For a steady stream of TILs from a variety of rocketeers, checkout
11
11
[ til.hashrocket.com] ( https://til.hashrocket.com/ ) .
12
12
13
- _ 547 TILs and counting..._
13
+ _ 548 TILs and counting..._
14
14
15
15
---
16
16
@@ -544,6 +544,7 @@ _547 TILs and counting..._
544
544
- [ Case-Aware Substitution With vim-abolish] ( vim/case-aware-substitution-with-vim-abolish.md )
545
545
- [ Case-Insensitive Substitution] ( vim/case-insensitive-substitution.md )
546
546
- [ Center The Cursor] ( vim/center-the-cursor.md )
547
+ - [ Check For An Executable] ( vim/check-for-an-executable.md )
547
548
- [ Check Your Current Color Scheme] ( vim/check-your-current-color-scheme.md )
548
549
- [ Close All Other Splits] ( vim/close-all-other-splits.md )
549
550
- [ Close All Other Windows] ( vim/close-all-other-windows.md )
Original file line number Diff line number Diff line change
1
+ # Check For An Executable
2
+
3
+ Sometimes Vim needs to reach outside of itself to use an existing program.
4
+ For example, wiring up [ auto-formatting of JavaScript
5
+ code] ( https://hashrocket.com/blog/posts/writing-prettier-javascript-in-vim )
6
+ requires Vim to call out to the
7
+ [ ` prettier ` ] ( https://github.com/prettier/prettier ) binary.
8
+
9
+ We want our ` .vimrc ` files and plugins to, generally, be as portable as
10
+ possible. What happens if you haven't yet installed a particular program?
11
+ Vim will likely experience a runtime exception. One way to get around this
12
+ is to check for the presence of that program on the path. If it isn't there,
13
+ don't do the thing. We can use the ` executable() ` function for this.
14
+
15
+ ``` vimscript
16
+ if executable('prettier')
17
+ ...
18
+ endif
19
+ ```
20
+
21
+ It will return ` 1 ` (true) if ` prettier ` is an executable on the path,
22
+ otherwise it will return ` 0 ` (false).
23
+
24
+ See ` :help executable() ` for more details.
You can’t perform that action at this time.
0 commit comments