


Comprehensively learn the Vim editor and become a 'super user' under the Linux command line
If you are a Linux user, then the Vim editor is one of the indispensable tools. Vim is an efficient, powerful and flexible text editor that can be used under the command line interface. However, due to its unique design and high degree of customization, some novices feel unfamiliar and confused about it, and some even give up using it. However, this article will introduce you to the basic usage methods and techniques of Vim to help you master this powerful editor.
I've been using Linux for about 25 years, and a few years of Unix before that. During this time, I developed preferences for a few tools that I use daily. Vim is one of the most important tools I use.
I started using Vi when I was learning Solaris in the early 1990s because I was told it would work on any system. From my experience, this is indeed the case. I've also tried other editors and they all do the job. However, for me, Vim works best. I use it so often that I've developed muscle memory and even subconsciously hit Vim shortcuts when using other editors.
In addition, I just simply like Vim.
Many configuration files use the name Vi instead of Vim, you can run the vi command. However, the vi command is actually a link to the vim command.
Many Linux tools use editors that emulate or directly call Nano, Emacs or Vim. Other tools allow users (for example, those who have a clear preference) to use their preferred editor. To give two examples that have the greatest impact on me, one is the Bash command line, which uses Emacs by default; the other is the Alpine text mode mail client, which uses Pico by default. In fact, Pico was written specifically for the Pine mail client, the predecessor of Alpine.
Not all programs that use external editors are configurable. Some programs only use the editor specified by the developer. For those applications that are configurable, there are different ways to choose your preferred editor.
Editing from the Linux command line
In addition to actually editing text files, another tool that I often use and is closely related to editing is the Bash shell. Bash's default editor is Emacs. Although I've also used Emacs, I definitely prefer Vim. So many years ago I changed my default editor for the Bash command line from Emacs to Vim, which is more comfortable for me.
There are many ways to configure Bash. You can use a local configuration file, such as /home/yourhomedirectory/.bashrc, which only makes default modifications to your user account and not to other users on the same system. I personally prefer to make these changes global, basically to my personal account and root. If you also want to configure it globally, you can create your own configuration file and place it in the /etc/profile.d directory.
I added a file named ??myBashConfig.sh?? in /etc/profile.d. The startup files for all installed shells are stored in the /etc/profile.d directory. When starting a terminal session, each shell reads only the startup file it was prepared for, based on the filename's extension. For example, the Bash shell only reads files with a .sh extension.
alias vim='vim -c "colorscheme desert" ' # 把 vi 设置为 Bash 的默认编辑器 set -o vi # 为所有检查 $EDITOR 变量的程序设置默认编辑器为 vi EDITOR=vi
In this global Bash configuration file section, set -o vi sets Vi as the default editor. The -o option in this set command defines vi as the editor. For the configuration to take effect, you need to close all running Bash sessions and open new ones.
Now you can use all the Vim commands you are familiar with, including cursor movement. Just press the Esc key to enter Vim editing mode. I particularly like the ability to use ??b?? multiple times to move the cursor back multiple words.
Set Vim as the default for other programs
Some Linux command line tools and programs check the $EDITOR environment variable to determine which editor to use. You can check the current value of this variable with the following command. I ran this command on a freshly installed virtual machine to see what the default editor was.
# echo $EDITOR /usr/bin/nano #
By default, Fedora programs that check the $EDITOR environment variable use the Nano editor. Adding a line EDITOR=vi to myBashConfig.sh (as shown in the snippet above) changes the default to the Vi (Vim) editor. However, not all command-line programs that use external editors check this environment variable.
Edit Email in Alpine
A few weeks ago I decided that Pico was not a good fit as my email editor. I can use it, and I did for a while after switching from Thunderbird to Alpine. But I found that Pico got in the way and I was always stuck using Vim key sequences, which affected my productivity.
I saw in Alpine's user help that the default editor can be modified. I decided to change it to Vim. It's actually very easy to do.
在 Alpine 主菜单上,按 S 键进入设置,然后按 C 键进行配置。在 “编辑器设置Composer Preferences” 部分,按 X 选择 “启用外部编辑器命令Enable Alternate Editor Command” 和 “隐式启用外部编辑器Enable Alternate Editor Implicitly” 项目。在往下滚动几页的 “高级用户设置Advanced User Preferences” 部分,找到 `Editor 那一行。如果它还没有被修改的话,它应该是这样的:
Editor =
用光标栏突出显示 Editor 这一行,然后按回车键来编辑。将 改为 vim ,再按回车键,然后按 E 键退出,最后按 Y 键保存修改。
要用 Vim 编辑电子邮件,只需进入电子邮件正文,Vim 就会自动启动,就像 Pico 那样。所有我喜欢的编辑功能都还在,因为它实际上是在使用 Vim。甚至退出 Vim 的 Esc :wq 序列也是一样的。
通过本文的介绍,您已经了解了Vim的基本使用方法和部分高级技巧,包括创建、打开、编辑、保存文件等操作。当然,Vim是一个非常庞大和灵活的工具,还有许多其他的功能和命令需要您探索和学习。希望本文能够为您提供足够的启发和指导,并且鼓励您深入学习Vim编辑器,成为Linux命令行下的“超级用户”。
The above is the detailed content of Comprehensively learn the Vim editor and become a 'super user' under the Linux command line. For more information, please follow other related articles on the PHP Chinese website!


For years, Linux software distribution relied on native formats like DEB and RPM, deeply ingrained in each distribution's ecosystem. However, Flatpak and Snap have emerged, promising a universal approach to application packaging. This article exami

The differences between Linux and Windows in handling device drivers are mainly reflected in the flexibility of driver management and the development environment. 1. Linux adopts a modular design, and the driver can be loaded and uninstalled dynamically. Developers need to have an in-depth understanding of the kernel mechanism. 2. Windows relies on the Microsoft ecosystem, and the driver needs to be developed through WDK and signed and certified. The development is relatively complex but ensures the stability and security of the system.

The security models of Linux and Windows each have their own advantages. Linux provides flexibility and customizability, enabling security through user permissions, file system permissions, and SELinux/AppArmor. Windows focuses on user-friendliness and relies on WindowsDefender, UAC, firewall and BitLocker to ensure security.

Linux and Windows differ in hardware compatibility: Windows has extensive driver support, and Linux depends on the community and vendors. To solve Linux compatibility problems, you can manually compile drivers, such as cloning RTL8188EU driver repository, compiling and installing; Windows users need to manage drivers to optimize performance.

The main differences between Linux and Windows in virtualization support are: 1) Linux provides KVM and Xen, with outstanding performance and flexibility, suitable for high customization environments; 2) Windows supports virtualization through Hyper-V, with a friendly interface, and is closely integrated with the Microsoft ecosystem, suitable for enterprises that rely on Microsoft software.

The main tasks of Linux system administrators include system monitoring and performance tuning, user management, software package management, security management and backup, troubleshooting and resolution, performance optimization and best practices. 1. Use top, htop and other tools to monitor system performance and tune it. 2. Manage user accounts and permissions through useradd commands and other commands. 3. Use apt and yum to manage software packages to ensure system updates and security. 4. Configure a firewall, monitor logs, and perform data backup to ensure system security. 5. Troubleshoot and resolve through log analysis and tool use. 6. Optimize kernel parameters and application configuration, and follow best practices to improve system performance and stability.

Learning Linux is not difficult. 1.Linux is an open source operating system based on Unix and is widely used in servers, embedded systems and personal computers. 2. Understanding file system and permission management is the key. The file system is hierarchical, and permissions include reading, writing and execution. 3. Package management systems such as apt and dnf make software management convenient. 4. Process management is implemented through ps and top commands. 5. Start learning from basic commands such as mkdir, cd, touch and nano, and then try advanced usage such as shell scripts and text processing. 6. Common errors such as permission problems can be solved through sudo and chmod. 7. Performance optimization suggestions include using htop to monitor resources, cleaning unnecessary files, and using sy


Hot AI Tools

Undresser.AI Undress
AI-powered app for creating realistic nude photos

AI Clothes Remover
Online AI tool for removing clothes from photos.

Undress AI Tool
Undress images for free

Clothoff.io
AI clothes remover

Video Face Swap
Swap faces in any video effortlessly with our completely free AI face swap tool!

Hot Article

Hot Tools

ZendStudio 13.5.1 Mac
Powerful PHP integrated development environment

MantisBT
Mantis is an easy-to-deploy web-based defect tracking tool designed to aid in product defect tracking. It requires PHP, MySQL and a web server. Check out our demo and hosting services.

SublimeText3 Chinese version
Chinese version, very easy to use

EditPlus Chinese cracked version
Small size, syntax highlighting, does not support code prompt function

Atom editor mac version download
The most popular open source editor
