惯性聚合 高效追踪和阅读你感兴趣的博客、新闻、科技资讯
阅读原文 在惯性聚合中打开

推荐订阅源

Webroot Blog
Webroot Blog
T
Troy Hunt's Blog
S
Security Affairs
Hacker News: Ask HN
Hacker News: Ask HN
Attack and Defense Labs
Attack and Defense Labs
P
Proofpoint News Feed
大猫的无限游戏
大猫的无限游戏
G
Google Developers Blog
WordPress大学
WordPress大学
T
The Blog of Author Tim Ferriss
N
Netflix TechBlog - Medium
博客园_首页
Recorded Future
Recorded Future
罗磊的独立博客
I
InfoQ
cs.AI updates on arXiv.org
cs.AI updates on arXiv.org
雷峰网
雷峰网
博客园 - Franky
Project Zero
Project Zero
T
Tailwind CSS Blog
Microsoft Azure Blog
Microsoft Azure Blog
V2EX - 技术
V2EX - 技术
MyScale Blog
MyScale Blog
C
Check Point Blog
博客园 - 【当耐特】
D
Docker
aimingoo的专栏
aimingoo的专栏
宝玉的分享
宝玉的分享
小众软件
小众软件
Microsoft Security Blog
Microsoft Security Blog
P
Privacy & Cybersecurity Law Blog
酷 壳 – CoolShell
酷 壳 – CoolShell
C
Cyber Attacks, Cyber Crime and Cyber Security
C
CXSECURITY Database RSS Feed - CXSecurity.com
Jina AI
Jina AI
N
News | PayPal Newsroom
Cisco Talos Blog
Cisco Talos Blog
L
Lohrmann on Cybersecurity
T
Tenable Blog
Forbes - Security
Forbes - Security
V
Vulnerabilities – Threatpost
阮一峰的网络日志
阮一峰的网络日志
H
Heimdal Security Blog
Google Online Security Blog
Google Online Security Blog
Threat Intelligence Blog | Flashpoint
Threat Intelligence Blog | Flashpoint
量子位
I
Intezer
H
Hacker News: Front Page
博客园 - 司徒正美
cs.CV updates on arXiv.org
cs.CV updates on arXiv.org

CSS Wizardry

Front-End’s Missing Metric: The TBT Window Meet Your Users Where They Are with Obs.js Better Browser Caching with No-Vary-Search font-family Doesn’t Fall Back the Way You Think What Is CSS Containment and How Can I Use It? When All You Can Do Is All or Nothing, Do Nothing Obs.js: Context-Aware Web Performance for Everyone Low- and Mid-Tier Mobile for the Real World (2025) The Fastest Site in the Tour de France Making Sense of the Performance Extensibility API Why Do We Have a Cache-Control Request Header? HTML Is Not a Programming Language… Build for the Web, Build on the Web, Build with the Web Licensing Code on CSS Wizardry A Layered Approach to Speculation Rules Designing (and Evolving) a New Web Performance Score Core Web Vitals Colours The Ultimate Contract Templates for Tech Consultants: Protect Your Business and Get Paid Optimising for High Latency Environments Cache Grab: How Much Are You Leaving on the Table? blocking=render: Why would you do that?! Correctly Configure (Pre) Connections The Three Cs: 🤝 Concatenate, 🗜️ Compress, 🗳️ Cache What Is the Maximum max-age? How to Clear Cache and Cookies on a Customer’s Device The Ultimate Low-Quality Image Placeholder Technique Core Web Vitals for Search Engine Optimisation: What Do We Need to Know? The HTTP/1-liness of HTTP/2 In Defence of DOM­Content­Loaded Site-Speed Topography Remapped Why Not document.write()? Speeding Up Async Snippets Critical CSS? Not So Fast! Measure What You Impact, Not What You Influence Optimising Largest Contentful Paint Measuring Web Performance in Mobile Safari Site-Speed Topography Speed Up Google Fonts Real-World Effectiveness of Brotli Performance Budgets, Pragmatically Lazy Pre-Browsing with Prefetch Making Cloud.typography Fast(er) Time to First Byte: What It Is and How to Improve It Self-Host Your Static Assets Tips for Technical Interviews Cache-Control for Civilians Bandwidth or Latency: When to Optimise for Which ITCSS × Skillshare What If? CSS and Network Performance The Three Types of Performance Testing Getting to Know a Legacy Codebase Image Inconsistencies: How and When Browsers Download Images Identifying, Auditing, and Discussing Third Parties My Digital Music Setup Measuring the Hard-to-Measure Finding Dead CSS The Fallacies of Distributed Computing (Applied to Front-End Performance) Ten Years Old Relative Requirements Airplanes and Ashtrays Performance and Resilience: Stress-Testing Third Parties Refactoring Tunnels Little Things I Like to Do with Git Writing Tidy Code Base64 Encoding & Performance, Part 2: Gathering Data Base64 Encoding & Performance, Part 1: What’s Up with Base64? Code Smells in CSS Revisited Typography for Developers Moving CSS Wizardry onto HTTPS and HTTP/2 Ack for CSS Developers A New Year, a New Focus Preparing Vim for Apple’s Touch Bar Choosing the Correct Average CSS Shorthand Syntax Considered an Anti-Pattern CSS Wizardry Newsletter Nesting Your BEM? Improving Perceived Performance with Multiple Background Images Continue Normalising Your CSS Pure CSS Content Filter Pragmatic, Practical, and Progressive Theming with Custom Properties Refactoring CSS: The Three I’s Speaker’s Checklist: Before and After Your Talk Improving Your CSS with Parker The Importance of !important: Forcing Immutability in CSS Mixins Better for Performance Managing Typography on Large Apps White October Events Workshop Partnership BEMIT: Taking the BEM Naming Convention a Step Further Travelling Like You Want to, When You Have To Contextual Styling: UI Components, Nesting, and Implementation Detail Subtleties with Self-Chained Classes Cyclomatic Complexity: Logic in CSS Immutable CSS Can CSS Be Too Modular? More Transparent UI Code with Namespaces When to use @extend; when to use a mixin The Specificity Graph CSS Wizardry Ltd.: Year 1 in review CSS Guidelines 2.0.0
Configuring Git and Vim
Harry Roberts · 2017-03-17 · via CSS Wizardry

Written by on CSS Wizardry.

Table of Contents

Independent writing is brought to you via my wonderful Supporters.

  1. Commit Message Templates
  2. Writing Commit Messages in Vim
    1. Constraining Columns
    2. Update 2017-04-09
  3. Git Commit Messages in Atom…

Two of my absolute all time favourite development tools have to be Git and Vim. Easily. I’ve used both almost daily for the last (at least) five or so years, so I want to share a handful of tips to help when using both together.

This is a very short post that only shares a couple of pertinent tips, so if you have any advancements or additional insights then please do let me know.

Commit Message Templates

If you’re anything like me, you’re a bit of a stickler for formatting, consistency, and process. If that is the case, you might be interested in setting up a Git commit template that will be loaded every time you run:

This template works across all text editors (i.e. you don’t have to be using Vim), and will automatically pre-populate the commit message with your chosen placeholder text, ready for you to fill in and customise.

The benefits of a template are manifold, but the main points for me are:

  1. Process is adhered to every time you make a commit.
  2. Automation means that you don’t need to lift a finger, but still get nicely formatted commit messages every time.
  3. Consistency means that you could roll the template out across your team and get identical commit messages from everyone.

Luckily, Git commit templates are incredibly simple to set up. Start by creating a file called .git-commit-template in your home directory (~/).

Now open this file and add your placeholder text. Mine is as simple as this:

[refs #00000] Subject line

Body (72 chars)

The first line is the title of the commit. This should be short enough to be digestible, but long enough to convey the general scope of the commit.

You’ll notice that it starts with [refs #00000]: this is a reference to an issue or ticket number that lives elsewhere (e.g. GitHub issues). Let’s say somebody opened an issue on your open source project to let you know that your function wasn’t rounding its output to the nearest integer. That issue will have an associated number, e.g. 57.

To that end, we’d have a commit title that looks like this:

[refs #00057] Fix rounding issue with grid mixin

This means that when I’m viewing a $ git log, I can quickly see what each commit is working toward, which is particularly useful when I’m logging any non-feature branches that contain commits from many different places. As well as that, we also get the added benefit of services like GitHub actually linking that commit message directly to the issue in their GUI.

The next section is the body of the commit message, where we describe or explain the commit in greater detail, for example:

[refs #00057] Fix rounding issue with grid mixin

The grid mixin was working largely as expected, but would not round
the output if passed an odd number. This led to scenarios where
developers were seeing grid gutters of e.g. 12.5px.

I’ve simply wrapped the Sass `round()` function around the output, so
people will now get the nearest integer whether rounded up or down.

This expanded message offers up additional insights as to why the commit exists and how we implemented it, and is also constrained to 72 characters in width to ensure it fits on most (if not all) terminal screens1.

Finally, we need to tell Git that the template exists:

$ git config --global commit.template ~/.git-commit-template

Which should leave something like the following new lines in your .gitconfig:

[commit]
  template = /Users/<username>/.git-commit-template

Writing Commit Messages in Vim

By default, whenever we write a commit message (not using the -m flag) we’re going to get thrown into Vim. If you’re a Vim user, this is great! This is exactly what we want. If you’re not a Vim user, skip ahead: I got you covered.

Constraining Columns

You may well have Vim set up to constrain your text editing to a certain number of columns (usually 80). If you do, great! If you don’t, simply add the following to your .vimrc:

" Force the cursor onto a new line after 80 characters
set textwidth=80

This will forcibly push your cursor onto a new line (and wrap your text for you!) if you go beyond your 80 character limit. This is really nice whilst writing code, because 80 characters is a pretty widely agreed standard.

We can also set another option—colorcolumn—to let us know visually when we’re approaching our boundary:

What this will do is highlight our 81st column which lets us know that no text should sit on this line. Pretty neat!

However, as above, our commit messages need to be constrained to 72 characters, not 80. How do we solve that problem?

One option is to run this every time we end up writing a commit message:

…but who’s got time for that?! Not me.

Luckily we can use an autocmd to solve this for us! We can tell Vim that Hey! Any time I enter a Git commit message, please can you do something for me?

That looks like this:

" However, in Git commit messages, let’s make it 72 characters
autocmd FileType gitcommit set textwidth=72
autocmd FileType gitcommit set colorcolumn=73

If the filetype is a Git commit message, automatically set new values for textwidth and colorcolumn.

As nice as this is, we can actually go one step further: wouldn’t it be nice to not have to hard code our colorcolumn every time we change our textwidth? It turns out that we can actually set colorcolumn to be relative to textwidth2:

This means that the column immediately after (+1) our textwidth cutoff point will be highlighted, regardless of whether the number is 80, 72, or anything. So now our Vim settings look a little like this (There is a more up to date snippet below):

" Force the cursor onto a new line after 80 characters
set textwidth=80
" However, in Git commit messages, let’s make it 72 characters
autocmd FileType gitcommit set textwidth=72
" Colour the 81st (or 73rd) column so that we don’t type over our limit
set colorcolumn=+1

It’s just a single line of config to get Vim in perfect shape for commit messages.

Update 2017-04-09

It gets even better! The ideal commit message has a title constrained to 50 characters and a body constrained to 72 characters. The setup we have above will only highlight our 72 character limit for body text though, meaning we have to work out our title’s limit more manually. However, I recently learned that the colorcolumn setting can accept more than one value! We can highlight both our title and our body’s constraints:

" Force the cursor onto a new line after 80 characters
set textwidth=80
" However, in Git commit messages, let’s make it 72 characters
autocmd FileType gitcommit set textwidth=72
" Colour the 81st (or 73rd) column so that we don’t type over our limit
set colorcolumn=+1
" In Git commit messages, also colour the 51st column (for titles)
autocmd FileType gitcommit set colorcolumn+=51

The key difference in this snippet is the last line, in which we don’t set a new colorcolumn value, but we actually append the existing one (by using +=) and add column number 51. This means that—in Git commit messages—we’re still highlighting the column immediately after our character limit by using the relative +1 value, and the 51st column by using the absolute 51 value.

Columns 51 and 73 highlighted in a Git commit message in Vim. View full size/quality (132KB).

Git Commit Messages in Atom…

…or Sublime, or VS Code, etc.

You might not want to use Vim at all, and that’s cool! But you will have probably noticed an annoying default in Git: commit messages open in a Vim instance!

I can’t remember exactly, but I’m willing to bet that my first ever exposure to Vim was through a merge conflict or expanded commit message in Git. As a full-time Vim user now, this isn’t an issue at all, but if you prefer Atom, or Sublime Text, or VS Code, or whatever it is you use, you’d probably rather write your commit messages there than in Vim.

Thankfully this is a really simple change to make:

$ git config --global core.editor <your editor of choice here>

For example, if you use Atom:

$ git config --global core.editor atom

If you use Sublime:

$ git config --global core.editor 'subl --wait'

This will now open all of your commit messages there, instead of the command line. For Sublime you need subl; for TextMate you need mate. If in doubt, just Google Open <your editor of choice here> from the command line.

Hopefully now you’ll see something like this in your .gitconfig:

[core]
  editor = atom --wait

The --wait flag tells the editor to Wait for window to be closed before returning., meaning our committing doesn’t resume/continue until we’ve saved and closed our text editor window.

Vim users, we’re probably pretty well set already, but if you want to make double sure then just run:

$ git config --global core.editor vim

Which will look like this inside of ~/.gitconfig:


Regardless of which editor you use, it’s worth knowing that you can tie it and Git together a little more closely. This should, if nothing else, make you more comfortable, if not more productive.