In addition to Weibo, there is also WeChat
Please pay attention
WeChat public account
Shulou
2025-04-02 Update From: SLTechnology News&Howtos shulou NAV: SLTechnology News&Howtos > Development >
Share
Shulou(Shulou.com)06/01 Report--
This article mainly introduces the Vim advanced use method has what related knowledge, the content is detailed and easy to understand, the operation is simple and fast, has a certain reference value, I believe that after reading this Vim advanced use method which articles will have some gains, let's take a look at it together.
You'll find that very convenient scenarios for using Vim almost always involve tasks that run remote Shell operations. If you use ssh from time to time, for example:
$ ssh user@hostname.provider.com
and work in virtual private servers (VPS) or on-premises virtualization containers, you can benefit from these powerful Vim skills.
Set Vim as the default text editor
In almost all modern Linux(or BSD) distributions, Vim is available from the shell command prompt of the terminal emulator. Once Vim is defined as the default editor in your user shell, you can use familiar Vim key bindings to navigate through built-in utilities such as man. I'll show you how to do this using Bash and the Z shell(zsh), which is now the default shell for macOS users (since Catalina).
(1)Set Vim as default in Bash
Bash manages settings through combinations of dot files. The most common way to do this is to add your editor to a.bashrc file in your home directory, but you can also add it to a.bash_profile. (Please read the GNU Bash documentation for differences.)
Set Vim as the default editor by adding the following to ~/.bashrc:
# set default editor to Vimexport EDITOR=vim
The line that starts with #is an optional comment, which is a good way to remind yourself of what the command does.
(2)Set Vim as default in zsh
zsh is an increasingly popular terminal emulator, especially since Apple's FreeBSD-based Darwin system recently switched from Bash to zsh.
Zsh dot files are comparable to Bash files, so you can choose between ~/.zshrc or ~/.zprofile. For details on when to use which, see the zsh documentation.
Set it to default:
# set default editor to Vimexport EDITOR=vim Optimize Vim Configuration
Like a terminal emulator shell, Vim uses dot files to set personal preferences. If you see this pattern, you probably guessed it was ~/.vimrc.
The first setting you might want to change is to switch the compatibility mode for legacy Vi to "OFF." Since Vim is a superset of Vi, all the features in Vi are available in Vim, and are greatly improved in Vim, you can get many advanced features. The latest version (8.2) allows you to open a terminal as a child process shell in a split window.
By the way, explicitly turning off compatibility with legacy Vi doesn't seem to make a difference (in fact, it probably doesn't). When Vim encounters a.vimrc file, it silently switches compatibility mode off automatically. But sometimes it's still important to turn it off explicitly. The acronym nocp is synonymous with nocompatible, which works the same way. All roads lead to Rome, and there are many ways to switch preferences.
In the.vimrc syntax, the lines that begin with "are comments (like #in the.bashrc file) that help you remember things like why you chose an obscure setting name.
To turn off Vi compatibility, add the following to the ~/.vimrc file:
" ensure that legacy compatibility mode is off" documentation: #'compatible>'set nocp understand mode
Vim's concept of "mode" is very important, especially the difference between "normal mode" and "insertion mode." Confusion about patterns is a problem for most new users. Patterns are not unique to Vim or even introduced by Vi. Command mode is so old that it predates the copy-and-paste feature invented in the 70s.
Vim relies on different patterns to define the typing behavior of the keyboard. Important patterns to understand are:
Normal mode: Default mode, mainly used for navigation and opening files.
Insert mode (including substitution): In this mode Vim allows text to be entered into an open file.
Visual mode: Vim behaves like mouse-based input, such as copy, edit, replace, etc.
Command Mode (including Line Mode, Ex Command Mode, and Last Line Mode): is a powerful way to do more in Vim.
Each model has a lot to explore. Use Vimtutor (vimtutor) to interactively learn to move the cursor, mode, and run Ex commands in last line mode. Some indispensable productivity operators include:
Play Vim like a piano
Although it is important to remember the operator "language" of Vim, the difficulty in mastering it lies in learning to think like a musician, combining operators and movements into "chords" so that you can play Vim like a piano player. This is where Vim's text-manipulation capabilities rival Emacs, another famous command-line editor. (Although one editor will wear out your Esc key, the other will wear out your Ctrl key.)
When describing the key "chord," tradition in Vim is to use a capital letter C followed by a hyphen (C-) to refer to the Ctrl key. This is not universal, but I will follow the convention from here on out and explain it where confusion is likely.
If you type long lines in Vim, you'll want to set it to wrap. To personalize Vim for how you work, consider this: By default, how do you want Vim to handle text breaks when it starts? On or off? I like to turn it off and leave it out of the run-command file. When I want text to wrap automatically, I simply set it with:set wrap in command line mode.
There's nothing wrong with having Vim set to wrap automatically by default, it's just a matter of preference--it may change over time. You can also control paste, code language indentation syntax, and tab settings (tab or space?). How many spaces? These options can also be explored in depth here). All of these default behavior options are fully configurable and changeable, and can be changed in real time as you operate in command-line mode.
You'll find plenty of advice on setting Vim defaults in community forums, the Vim wiki, and articles like this one. You should be familiar with setting preferences for your personal computing environment, and Vim is no exception. I strongly recommend that you start with minor changes to settings and slowly make other changes so that you can easily revert to settings. This way, you can avoid plug-ins for years or not use them at all.
Split, label and termination in Vim 8.2
There are two ways to split the files you're working on into different views: they can be displayed side by side, or you can use the app tabs to switch between full-screen (windowed) views. These changes to the application window are initiated from command mode, which requires a colon (:) to invoke the prompt.
Each split window can hold one file for editing, and you can switch between more files at will via tabs. Split screen space is limited, so tabs are handy when you want to split more screens. How you want to set it is purely a matter of personal preference. To split a window horizontally, use:sp, or vertically: vs.
Starting with Vim 8.2, you can open a vertically partitioned terminal shell subprocess with:vert term to operate on the command line next to your code. You need to type exit to close your terminal process, just as you would close a shell session, but you close the split window and tabs the same way you close any normal Vim window, with:q.
To initialize a tab, use a special editing command:tabedit, which automatically switches to the newly opened tab. If you give the command a filename as an argument, it opens the file and edits it. If you omit to give it a filename as an argument, you can edit it using the command:e filename.txt in command-line mode, just like in any normal Vim window. You can navigate between tabs using the Next (:tabn) and Previous (:tabp) commands.
To use split, you need to know how to use the key combination C-w and the move key in the direction you want to move, such as left (h), down (j), left (k), right (l).
The content of this article on "What are the advanced ways to use Vim" is introduced here. Thank you for reading! I believe everyone has a certain understanding of "what are the advanced use methods of Vim". If you still want to learn more knowledge, please pay attention to the industry information channel.
Welcome to subscribe "Shulou Technology Information " to get latest news, interesting things and hot topics in the IT industry, and controls the hottest and latest Internet news, technology news and IT industry trends.
Views: 0
*The comments in the above article only represent the author's personal views and do not represent the views and positions of this website. If you have more insights, please feel free to contribute and share.
Continue with the installation of the previous hadoop.First, install zookooper1. Decompress zookoope
"Every 5-10 years, there's a rare product, a really special, very unusual product that's the most un
© 2024 shulou.com SLNews company. All rights reserved.