104 lines
5.6 KiB
HTML
104 lines
5.6 KiB
HTML
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Strict//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-strict.dtd">
|
|
<html xmlns="http://www.w3.org/1999/xhtml"><head>
|
|
<meta http-equiv="Content-type" content="text/html;charset=UTF-8" />
|
|
<meta name="viewport" content="width=device-width, initial-scale=1.0" />
|
|
<link rel="stylesheet" href="main.css" type="text/css" />
|
|
<link rel="stylesheet" href="blog.css" type="text/css" />
|
|
<link rel="alternate" type="application/rss+xml" title="Subscribe to this page..." href="feed.rss" />
|
|
<title>Vim and Powershell</title>
|
|
</head><body>
|
|
<div id="divbodyholder">
|
|
<div class="headerholder"><div class="header">
|
|
<div id="title">
|
|
<h1 class="nomargin"><a class="ablack" href="http://zigford.org/index.html">zigford.org</a></h1>
|
|
<div id="description"><a href="about.html">About</a><a href="links.html"> | Links</a><a href="scripts.html"> | Scripts</a><br>Sharing linux/windows scripts and tips</br></div>
|
|
</div></div></div>
|
|
<div id="divbody"><div class="content">
|
|
<!-- entry begin -->
|
|
<h3><a class="ablack" href="vim-and-powershell.html">
|
|
Vim and Powershell
|
|
</a></h3>
|
|
<!-- bashblog_timestamp: #201903310044.43# -->
|
|
<div class="subtitle">March 31, 2019 —
|
|
Jesse Harris
|
|
</div>
|
|
<!-- text begin -->
|
|
<p>Back in the days when Powershell was just a young pup there were a few
|
|
Vim users contributing to Vim via <a href="https://github.com/PProvost/Vim-ps1">plugins</a> to make writing powershell
|
|
a nicer experience. Syntax highlighting, auto filetype detection, snippets
|
|
and other quality of life things.</p>
|
|
<hr />
|
|
<p>Since then, the release and rise of VSCode with it's strong Powershell
|
|
integrations have drawn most developer types away from Vim and new QOL features
|
|
have been few and far between.</p>
|
|
<p>I haven't given up on using Vim for powershell however for a few reasons:</p>
|
|
<ul>
|
|
<li>Battery life.</li>
|
|
</ul>
|
|
<p>I spend most of my time running off laptops, and VSCode and other electron
|
|
based apps are designed for development speed first, execution speed second.
|
|
Running a terminal based app all day vs running an electron app can make
|
|
a serious difference to your battery life.</p>
|
|
<ul>
|
|
<li>Updates too often.</li>
|
|
</ul>
|
|
<p>Every update to a tool like VSCode broadens it's audience and makes it a
|
|
great tool for more people. This is great to make an app with thousands of
|
|
features that each user will use a tiny sliver of those features.
|
|
I, on the other hand don't need or want 99% of those features.</p>
|
|
<ul>
|
|
<li>Focusing your skills</li>
|
|
</ul>
|
|
<p>I'm pretty much a generalist in skills in IT, but there are a few tools
|
|
were I keep my focus to be as effective as possible. Using Vim well is one
|
|
of them</p>
|
|
<p>So with all this, I have been searching for a while for a plugin to make some
|
|
QOL improvements to Vim. A couple of months ago I stumbled upon <a href="https://github.com/w0rp/ale">ale</a> a
|
|
general plugin that can be adapted to any language. It started out for
|
|
<a href="https://en.wikipedia.org/wiki/Lint_%28software%29">linting</a> as the name implies, but it had grown to support fixing and
|
|
completion too.</p>
|
|
<p>At the time, there was an <a href="https://github.com/w0rp/ale/issues/1264">issue</a>
|
|
raised to add <a href="https://github.com/PowerShell/PSScriptAnalyzer">PSScriptAnalyzer</a> as a linter, and so I decided to see if
|
|
I could understand how to add a linter to ale.</p>
|
|
<p>I didn't know the <a href="https://en.wikipedia.org/wiki/Vim_(text_editor)#Vim_script">VimScript</a> language and trawling through the ale codebase
|
|
didn't make much sense to me. The project has some developer documentation,
|
|
however it assumes pre-knowledge of VimScript. That's when I did something
|
|
out of character. I read a book. <a href="http://learnvimscriptthehardway.stevelosh.com/">Learn VimScript The Hard Way</a> by Steve
|
|
Losh. It was a fun and enjoyable read, especially following along with the
|
|
exercises. I highly recommend reading it, even if you only have an interest
|
|
in using Vim.</p>
|
|
<p>Toward about half-way through reading the book, I felt confident enough to
|
|
have another crack at the PSScriptAnalyzer linter. This time the codebase
|
|
made much more sense to me and I was able to get a nicely working prototype
|
|
done in a morning.</p>
|
|
<p>Since then, I've written some tests, documentation and created a pull request
|
|
which was merged today on the ale project.</p>
|
|
<p>To use it, you just need to install the ale plugin. It defaults to using
|
|
PowerShell core, so if you want to use <code>powershell.exe</code> you will need to read
|
|
the help: <code>:help ale-powershell</code> to see the variable to override this setting.
|
|
Of course you will also need to have the PSScriptAnalyzer module installed.</p>
|
|
<p>Finally, there is one issue you can encounter particularly on windows
|
|
(btw, I've used it fine on Linux and MacOS), if you launch Vim using
|
|
<code>powershell.exe</code> but ale is using <code>pwsh.exe</code>, Vim will pass it's inherited
|
|
environment variables to it's child processes. This can lead to an issue where
|
|
the variable <code>$Env:PSModulePath</code> contains paths for <code>powershell.exe</code> and not
|
|
<code>pwsh.exe</code>, therefore if you don't have the PSScriptAnalyzer module installed
|
|
in both shells, ale won't be able to do any linting for you.</p>
|
|
<p>Tags: <a href='tag_powershell.html'>powershell</a>, <a href='tag_vim.html'>vim</a>, <a href='tag_ale.html'>ale</a></p>
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
<!-- text end -->
|
|
<!-- entry end -->
|
|
</div>
|
|
<div id="footer">© <a href="http://twitter.com/zigford_org">Jesse Harris</a> — <a href="mailto:jesse@zigford.org">jesse@zigford.org</a><br/>
|
|
Generated with <a href="https://github.com/cfenollosa/bashblog">bashblog</a>, a single bash script to easily create blogs like this one</div>
|
|
</div></div>
|
|
</body></html>
|