mirror of
https://github.com/jbranchaud/til
synced 2026-01-04 23:58:01 +00:00
Add Check For An Executable as a vim til
This commit is contained in:
@@ -10,7 +10,7 @@ smart people at [Hashrocket](http://hashrocket.com/).
|
|||||||
For a steady stream of TILs from a variety of rocketeers, checkout
|
For a steady stream of TILs from a variety of rocketeers, checkout
|
||||||
[til.hashrocket.com](https://til.hashrocket.com/).
|
[til.hashrocket.com](https://til.hashrocket.com/).
|
||||||
|
|
||||||
_547 TILs and counting..._
|
_548 TILs and counting..._
|
||||||
|
|
||||||
---
|
---
|
||||||
|
|
||||||
@@ -544,6 +544,7 @@ _547 TILs and counting..._
|
|||||||
- [Case-Aware Substitution With vim-abolish](vim/case-aware-substitution-with-vim-abolish.md)
|
- [Case-Aware Substitution With vim-abolish](vim/case-aware-substitution-with-vim-abolish.md)
|
||||||
- [Case-Insensitive Substitution](vim/case-insensitive-substitution.md)
|
- [Case-Insensitive Substitution](vim/case-insensitive-substitution.md)
|
||||||
- [Center The Cursor](vim/center-the-cursor.md)
|
- [Center The Cursor](vim/center-the-cursor.md)
|
||||||
|
- [Check For An Executable](vim/check-for-an-executable.md)
|
||||||
- [Check Your Current Color Scheme](vim/check-your-current-color-scheme.md)
|
- [Check Your Current Color Scheme](vim/check-your-current-color-scheme.md)
|
||||||
- [Close All Other Splits](vim/close-all-other-splits.md)
|
- [Close All Other Splits](vim/close-all-other-splits.md)
|
||||||
- [Close All Other Windows](vim/close-all-other-windows.md)
|
- [Close All Other Windows](vim/close-all-other-windows.md)
|
||||||
|
|||||||
24
vim/check-for-an-executable.md
Normal file
24
vim/check-for-an-executable.md
Normal file
@@ -0,0 +1,24 @@
|
|||||||
|
# Check For An Executable
|
||||||
|
|
||||||
|
Sometimes Vim needs to reach outside of itself to use an existing program.
|
||||||
|
For example, wiring up [auto-formatting of JavaScript
|
||||||
|
code](https://hashrocket.com/blog/posts/writing-prettier-javascript-in-vim)
|
||||||
|
requires Vim to call out to the
|
||||||
|
[`prettier`](https://github.com/prettier/prettier) binary.
|
||||||
|
|
||||||
|
We want our `.vimrc` files and plugins to, generally, be as portable as
|
||||||
|
possible. What happens if you haven't yet installed a particular program?
|
||||||
|
Vim will likely experience a runtime exception. One way to get around this
|
||||||
|
is to check for the presence of that program on the path. If it isn't there,
|
||||||
|
don't do the thing. We can use the `executable()` function for this.
|
||||||
|
|
||||||
|
```vimscript
|
||||||
|
if executable('prettier')
|
||||||
|
...
|
||||||
|
endif
|
||||||
|
```
|
||||||
|
|
||||||
|
It will return `1` (true) if `prettier` is an executable on the path,
|
||||||
|
otherwise it will return `0` (false).
|
||||||
|
|
||||||
|
See `:help executable()` for more details.
|
||||||
Reference in New Issue
Block a user