You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
{{ message }}
Instantly share code, notes, and snippets.
Kevin Yokley
kyokley
Software developer. Loves python, vim, and anything with a terminal interface
git blame and git show are useful commands for giving context of the code you're viewing. Since I spend the majority of my time in Vim, they become even more useful if they are executable from inside the editor. Of course, Vim makes this easy by giving a way to call external commands.
Vim (vimrc)
Git
Blame
For git blame, I wanted the ability to either blame the entire file or just part of one. By default, I blame the entire file but take advantage of Vim's visual mode to filter for only the selected lines.
nnoremapgb:!git blame =expand("%:p") \| color_git_blame \| less +=line("w0")
Since I always forget how to write a git hook to prevent pushing certain branches to remotes, I'm writing this gist to, hopefully, help my future self remember...
To prevent local branch "work" from being pushed to the github remote:
#!/bin/sh
remote="$1"
url="$2"
while read local_ref local_sha remote_ref remote_sha
Checking for Python Security Vulnerabilities with VIM
Checking for Python Security Vulnerabilities with VIM (Buffer Pre-write Hook Part 3)
Introduction
To continue my series of vim pre-write hooks, I wanted to add a new check for security static analysis failures. To see the progression of the series, please check out my other gists.
Back to security... In my office, we use OpenStack's Bandit static analysis tool. If you're not familiar with it, you should check it out. It's pretty nifty.
I am a big fan of the syntastic package. In python, it is useful for viewing both Pyflakes and Bandit errors. However, this only works if syntastic knows what python interpreter to use.
Not everyone is fortunate enough to have upgraded all of their software to python3. For reasons out of my control, I end up spending most of my time writing python2 code. This means that the times when I finally get to write python3, all of my syntax checking is broken. How cool would it be to have VIM determine what version of python to use automatically? So, begins my grand experiment...
Prerequisites
For this to work, I will be using a virtualenv for python2 and one for python3. It's not absolutely necessary to use virtualenvs but I definitely recommend it. Setting up virtualenvs is out of the scope of this gist but make sure that each virtualenv
Have you ever tried running a file only to be stopped by "<<<<<<<"?
Wouldn't it be nice to be able to automatically run your code through pyflakes before actually saving it? Maybe even raise an error for showstopping bugs in your code?
I ran into this issue while at work and came up with this solution. This gist is mostly just documentation for myself so I can remember what I did 6 months from now. I am in no way saying that this is the right way to fix things but I'll be thrilled if this is in any way helpful to others. That being said, I make no guarantees that bad things will not happen to your machine if you follow these directions. Proceed at your own risk.
Although, I mention using the following setup to resolve an issue I was having using xmonad as my windows manager, I don't think there's anything special about it. It should be possible to use the following steps with any windows manager.
Problem
Setting up multiple monitors in xmonad requires defining the screen configuration using xrandr. The problem is that xmonad does not respond to a laptop being placed or removed from a docking station. Obviously, the solution is to update the monitor configuration on the
Bash Docker VIM: Quick bash functions to support using a dockerized Vim
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters