Sysadmins are always looking for ways to optimize their workflow and accomplish more in the time they have. When using a text editor like Vim (and its derivatives), one way you can become more efficient is by saving typing. One of Vim's most overlooked features in this category is Vim abbreviations.
[ Get the Vim cheat sheet. ]
An abbreviation is a Vim feature that replaces a small chunk of text—the abbreviation—with another chunk of text as you type. In most cases, the abbreviation replaces text that is much longer, saving you from typing it all out. For example, you can create an abbreviation that replaces sig with your full email signature.
You generally use abbreviations to replace text you often type, such as signatures, comments, code blocks, or even long words or expressions. You can also use it as a quick autocorrect feature for words you often misspell.
Define an abbreviation
To create abbreviations in Vim, you can use the command :abbreviate (which itself can be abbreviated as :ab) followed by the abbreviation and the text you want to replace it with. For example, to abbreviate the word "operating system" as "os," use the abbreviate command like this:
:ab os operating system
By default, the command :abbreviate creates an abbreviation that works in insert and command modes. You can use variations such as :iab to create an abbreviation that works only in insert mode or :cab for command mode only.
[ Keep your favorite Git commands, aliases, and tips close at hand. Download the Git cheat sheet. ]
Use an abbreviation
To trigger an abbreviation, type the abbreviation word, for example os in the example above, followed by a non-keyword character; for example, you can use the Space bar or Enter.
Unlike mappings, abbreviations trigger only when you type the abbreviation by itself and not in the middle of another word. This is a great option when you're typing text because it's usually what you want. For example, in the example above, Vim will not trigger the abbreviation when you type the word autos or oscar.
To prevent an abbreviation from expanding, type Ctrl+V before entering the abbreviated word.
Remove an abbreviation
Use the command :ab without any parameters to see a list of all abbreviations defined for the current buffer. To remove an abbreviation, use the command :unab followed by the abbreviation or :abc to clear all abbreviations.
Common ways to use Vim abbreviations
Now that you can define and use abbreviations, here are some common ways to use them to gain efficiency.
Autocorrect mistakes
Use abbreviations to quickly autocorrect frequently misspelled words, such as teh, adn, and tihs:
:ab teh the
:ab adn and
:ab tihs this
Since you can misspell these words on the command line and in insert mode, use :ab to define the abbreviations. Now, as soon as you type one of those misspellings, Vim will correct it for you right away.
Type long text strings
Use Vim abbreviations to type frequently used long strings of text, such as your email signature. You can use special characters; for example, use <CR> to add a new line:
:iab sig Regards,<CR>Ricardo<CR>
Or a comment you often type, like "looks good to me":
:iab lgtm looks good to me
Because you'll almost always use these abbreviations only when typing text and almost never in command mode, use :iab to define an insert mode abbreviation.
Enter code snippets
You can also use abbreviations to define common code blocks for your favorite programming language. For example, define a common if error block for Go programs:
:iab ife if err != nil {<CR><tab>return err<CR>}<CR>
When you type ife, this abbreviation expands to:
if err != nil {
return err
}
[ Want to test your sysadmin skills? Take a sysadmin skills assessment today. ]
You can also use more complex abbreviations that include cursor movement. For example, the following creates a Go for block, then positions your cursor in insert mode to define the loop's termination condition by adding <esc> to enter normal mode, and uses movement keys to move the cursor to the correct position:
:iab ffi for i := 0; i<; i++ {<CR><CR>}<esc>2k14li
This abbreviation expands to:
for i := 0; i< ; i++ {
}
The cursor is positioned after i< in insert mode, allowing you to type the condition immediately.
You can use the same idea to create an HTML tag, like this:
:iab p <p></p><esc>3hi
Or a markdown code block:
:iab 3~ ~~~<CR><CR>~~~<esc>kI
This abbreviation expands to:
~~~
~~~
This abbreviation was handy when I wrote this article.
Abbreviations are a good way to save time typing in code blocks, but they lack some features. For more complex snippets, try snippet plugins.
Don't overlook abbreviations
Abbreviations are one of Vim's most overlooked features. They are powerful, flexible, and easier to start using than mappings or more advanced features like snippet plugins.
You can define these abbreviations in your Vim configuration file and even associate them with particular file types. For example, you can add Go-related code abbreviations only for Go files.
For more details, check the Vim tips wiki's Vim abbreviations page.
저자 소개
Ricardo Gerardi is a Principal Consultant at Red Hat, having transitioned from his previous role as a Technical Community Advocate for Enable Sysadmin. He's been at Red Hat since 2018, specializing in IT automation using Ansible and OpenShift.
With over 25 years of industry experience and 20+ years as a Linux and open source enthusiast and contributor, Ricardo is passionate about technology. He is particularly interested in hacking with the Go programming language and is the author of Powerful Command-Line Applications in Go and Automate Your Home Using Go. Ricardo also writes regularly for Red Hat and other blogs, covering topics like Linux, Vim, Ansible, Containers, Kubernetes, and command-line applications.
Outside of work, Ricardo enjoys spending time with his daughters, reading science fiction books, and playing video games.
유사한 검색 결과
Friday Five — February 13, 2026 | Red Hat
PNC’s infrastructure modernization journey with Red Hat OpenShift Virtualization
Data Security And AI | Compiler
Data Security 101 | Compiler
채널별 검색
오토메이션
기술, 팀, 인프라를 위한 IT 자동화 최신 동향
인공지능
고객이 어디서나 AI 워크로드를 실행할 수 있도록 지원하는 플랫폼 업데이트
오픈 하이브리드 클라우드
하이브리드 클라우드로 더욱 유연한 미래를 구축하는 방법을 알아보세요
보안
환경과 기술 전반에 걸쳐 리스크를 감소하는 방법에 대한 최신 정보
엣지 컴퓨팅
엣지에서의 운영을 단순화하는 플랫폼 업데이트
인프라
세계적으로 인정받은 기업용 Linux 플랫폼에 대한 최신 정보
애플리케이션
복잡한 애플리케이션에 대한 솔루션 더 보기
가상화
온프레미스와 클라우드 환경에서 워크로드를 유연하게 운영하기 위한 엔터프라이즈 가상화의 미래