Emacs is a text editing tool that comes out-of-the-box with Linux and macOS. As a (less popular) cousin of Vim, Emacs also offers powerful capabilities with easy-to-install language support, and can even help you navigate faster in macOS with the same keybindings. If you want to know why you should learn Emacs and how to get started, please keep reading.
Emacs vs. Vim
If you are new to text editing, you may wonder if you should go with Emacs or Vim, since remembering all of the commands for either can involve a significant investment of muscle memory. There’s a dedicated Wikipedia page with a summary of the differences and pros vs. cons to help you decide what side of the editor war between Vim and Emacs you’re on.
One of the most notable differences between is two editors is that, unlike Emacs, Vim has two modes: Insert mode (where you can edit the file and cannot enter commands) and Command mode (where you can only enter commands and the file is read-only). Because Emacs is modeless, its keyboard commands often start with the Ctrl key or the Meta key (which can be Esc or Opt if configured in your macOS terminal preferences), so that the system can distinguish actual edits from commands. In my experience, Emacs resembles editors like Microsoft Word and Google Docs more than Vim because of its modelessness, and this fact may make it easier to get used to than Vim.
As noted in the Wikipedia editor war article, the "non-modal nature of Emacs keybindings makes it practical to [use them as] OS-wide keybindings." This sentiment summaries the biggest reason that I choose Emacs over Vim. As an Apple addict, many of the Emacs keyboard shortcuts come out-of-the-box with macOS, such as:
Key combo | Description |
---|---|
Ctrl+A | Go to the beginning of the line. |
Ctrl+E | Go to the end of the line. |
Meta+Delete | Delete the last word before the cursor. |
Ctrl+F | Go forward by one letter. |
Ctrl+B | Go back by one letter. |
Ctrl+K | Delete the rest of the current line starting from the cursor. |
Note: Whether you use capital or lowercase letters does not matter in this case.
This setup makes navigating any text field faster in tools such as browsers and Google Docs.
Quickstart guide
The basic navigation commands below include the shortcuts listed in the previous section (many of these are out-of-the-box shortcuts in macOS, too):
Key combo | Description |
---|---|
Ctrl+N | Go to the next line. |
Ctrl+P | Go to the previous line. |
Ctrl+S | Search for a word (repeat the same key combination to find the next occurrence, or use Ctrl+R to find the previous one.) |
Ctrl+X Ctrl+S | Save your file. |
Ctrl+X U | Undo the last edit. |
Ctrl+X Ctrl+C | Exit the Emacs application. |
Note: You can customize Emacs to be case-sensitive, but it is not set up that way by default.
You can find other commonly used Emacs commands here.
Making Emacs your default terminal editor
Now, let’s practice the basic navigation commands. If these files don’t yet exist, opening an unknown file name with the emacs command will create a new file for you when you save.
(The -nw
Emacs flag opens the editor in non-GUI mode.)
If you’re using macOS, use Emacs to open your .bash_profile
file:
$ emacs -nw ~/.bash_profile
If you’re using Linux, use Emacs to open your .bashrc
file:
$ emacs -nw ~/.bashrc
Add this line to the end of either file. You may need to change the path to your Emacs binary if it’s in a different location:
export EDITOR="/usr/local/bin/emacs -nw"
Save the file, exit the editor, and then restart your terminal. No more googling how to get out of Vim when running git rebase
.
Installing plugins and setting up language modes
You can install plugins for different language support easily with Emacs (more on language support in the next section). In general, Emacs has the same package installation mechanism for all packages. Read this to understand how that mechanism works.
Here are tutorials for how to set up Emacs for three different languages:
Emacs vs. IDEs
There’s the ancient question of whether text editors or IDEs (e.g., the JetBrains suite or Eclipse) are better for everyday coding activities. Everyone has different preferences, and the best way for you to find yours is to try both. You may find out that a hybrid approach works best for you.
How well a text editor works depends on the plugin support for the specific language you're using. Furthermore, many IDEs may not work well for certain languages. For example, for a scripting language like Python, go-to-definition and finding usage does not work well with most IDEs I’ve tried (such as JetBrains' PyCharm) because of poor indexing. As a result, my default tool of choice when developing in Python is Emacs, as a simple rgrep
will do the job for finding usage.
On the other hand, a strongly typed language like C++ or Java makes a good IDE shine like nothing else. I have not had a good experience with go-to-definition in Emacs when working with C++, especially when there are multiple levels of virtualness and overloaded functions. Out of all of the IDEs I’ve tried, the JetBrains suite (Goland for Golang, IntelliJ for Java, and CLion for C/C++) in my opinion works best for object-oriented programming. The downside is that the JetBrains suite does have a larger CPU and memory footprint, as it’s constantly processing your project code and its dependencies in the background (hence the close-to-perfect indexing), and many of the JetBrains products are not free (such as Goland).
If you decide to go with an IDE, you can still keep your Emacs command muscle memory, because you can use the same key bindings when navigating in the IDE. For the JetBrains suite, you can:
- Go to the menu bar.
- Select Goland -> Preferences -> Keymap
- Select Emacs from the dropdown menu.
A good IDE makes reading a large project’s code easier. However, when it comes to coding, it’s important to note that my editing experience is not quite the same in JetBrains Goland even though I’ve set up Emacs keybindings. Completely mouse-free coding is not achievable with an IDE, so when I’m focused on developing one piece of logic, I still fire up good old Emacs.
Summary
Different text editors have their own strengths and weaknesses, and how well they work can vary a lot between individuals. Emacs works for me because I can reuse many of the same shortcuts with macOS. In my day-to-day development within Golang, I use a combination of JetBrains' Goland and Emacs. If you are not too deeply invested in Vim, I encourage you to give Emacs a try.
저자 소개
Tara Gu is a software engineer at IBM. She started contributing to Kubernetes as a hobbyist in 2018. She has recently joined the IBM Digital Business Group - Open Technology division and now contributes to Knative full-time. She is a reviewer of Knative and a member of Kubernetes. She enjoys running and weightlifting in her spare time.
유사한 검색 결과
채널별 검색
오토메이션
기술, 팀, 인프라를 위한 IT 자동화 최신 동향
인공지능
고객이 어디서나 AI 워크로드를 실행할 수 있도록 지원하는 플랫폼 업데이트
오픈 하이브리드 클라우드
하이브리드 클라우드로 더욱 유연한 미래를 구축하는 방법을 알아보세요
보안
환경과 기술 전반에 걸쳐 리스크를 감소하는 방법에 대한 최신 정보
엣지 컴퓨팅
엣지에서의 운영을 단순화하는 플랫폼 업데이트
인프라
세계적으로 인정받은 기업용 Linux 플랫폼에 대한 최신 정보
애플리케이션
복잡한 애플리케이션에 대한 솔루션 더 보기
오리지널 쇼
엔터프라이즈 기술 분야의 제작자와 리더가 전하는 흥미로운 스토리
제품
- Red Hat Enterprise Linux
- Red Hat OpenShift Enterprise
- Red Hat Ansible Automation Platform
- 클라우드 서비스
- 모든 제품 보기
툴
체험, 구매 & 영업
커뮤니케이션
Red Hat 소개
Red Hat은 Linux, 클라우드, 컨테이너, 쿠버네티스 등을 포함한 글로벌 엔터프라이즈 오픈소스 솔루션 공급업체입니다. Red Hat은 코어 데이터센터에서 네트워크 엣지에 이르기까지 다양한 플랫폼과 환경에서 기업의 업무 편의성을 높여 주는 강화된 기능의 솔루션을 제공합니다.