In addition to Weibo, there is also WeChat
Please pay attention
WeChat public account
Shulou
2025-03-29 Update From: SLTechnology News&Howtos shulou NAV: SLTechnology News&Howtos > Servers >
Share
Shulou(Shulou.com)06/03 Report--
I believe that when you write code with a variety of powerful IDE, you will notice that various types of keywords in the code will be marked with unique colors, and then form a set of syntax highlighting rules. This is not only beautiful, but also easy to read the code. In the ancient artifact Vim, what we usually see is white characters on a black background, without any other colors. Is our Vim so boring? Of course not, Vim hides a lot of very practical functions and skills, not that the old driver doesn't know it at all.
Let's introduce it in detail. Before we begin, we need to check to see if the Vim editor is installed on the system. Generally speaking, the Ubuntu system comes with it by default. If you don't have it, please install it yourself first.
$sudo apt-get install vim
Then we run the following command to see the version of the installed Vim editor.
$vim-version
Next, we can add a color scheme to the Vim editor. In order to see the effect, we have prepared a bash file called login.sh, which contains the following contents: login.sh
#! / bin/bashecho "Type your username" read usernameecho "Type your password" read passwordif [[($username = = "admin" & & $password = = "secret")]]; thenecho "Authorized user" elseecho "Unauthorized user" fi
Run the following command to open the file using the Vim editor:
$vim login.sh
Enable / disable syntax highlighting
Some distributions of Vim editors have enabled syntax highlighting by default, while others do not. If syntax highlighting is not turned on by default, then we need to open it ourselves. The way to open it is actually very simple. After opening the login.sh file in the Vim editor, press the ESC key and type: syntax on, and the syntax highlighting opens, which is very convenient.
Similarly, turning off syntax highlighting is as simple as pressing the ESC key and typing: syntax off.
Permanently enable or disable syntax highlighting
The method of opening syntax highlighting is only temporary. Once the current file is closed, the syntax highlighting needs to be reopened the next time the file is opened. If you want to permanently enable or disable syntax highlighting, you need to modify the .vimrc file. First, we use Vim to open the .vimrc file.
$sudo vim ~ / .vimrc
Then, add a syntax on command to the open file to permanently enable syntax highlighting. Finally, enter: wq to save and close the file.
If you want to permanently disable syntax highlighting, add the syntax off command.
Change the color scheme
By default, when syntax highlighting is turned on, Vim applies a default color scheme for you, but in fact, Vim has many color schemes available for us to use, and we can modify them ourselves. After installing Vim, the color scheme file is located in / usr/share/vim/vim*/colors/. We can run the following command to view a list of Vim color scheme files.
$ls-l / usr/share/vim/vim*/colors/
We can see that Vim provides us with a lot of color schemes, and we are free to choose according to our own needs. Suppose we have a html file for hello.html and we want to change its color scheme to the morning type.
Hello.html
Welcome
Hello Everybody, Welcome to our site
Let's first run the following command to open the html file in Vim.
$vim hello.html
Press ESC and type: colorscheme morning, so we change the current color scheme of the file.
After applying the new color scheme. However, this change is still temporary, and the color scheme will be reset when the editor is closed.
If you want to permanently set a specific color scheme and background, we need to open the .vimrc file again and add the following command text. The following configuration is the night color scheme, which sets the background color to dark.
Color eveningset background=dark
Choose a color scheme according to the language
The Vim editor supports syntax in multiple languages, such as PHP,Perl,Python,awk, etc. Depending on the language, it applies a set of color schemes for the corresponding language. For example, there is now a Python file called average.py, which we open with a Vim editor. Through the default color scheme of the Vim editor.
This is a Python file, but what if we want to display it in the syntax style of Perl? All we have to do is type: set syntax=perl, press the Enter key, and the effect is shown in the following figure.
: set syntax=perl
Custom color scheme
In fact, the color schemes introduced above are all included in the system, and we just choose them. What if we want to personalize and customize a color scheme? Powerful Vim also supports this need of you! Generally speaking, syntax needs to be highlighted only by variables, comments, constants, and so on. There are nine syntax highlight groups supported by the Vim editor:
Identifier variable Statement keywords, such as Comment comment Type data types such as if,else,do,while, PreProc preprocessor statements such as int, double, string, etc., such as # includeConstant constants, such as numbers, quoted strings, true / false and other Special special symbols, such as "\ t", "\ n" and other Underlined underlined text Error errors
Let me give you an example. Open the Python script file named leap.py in the Vim editor. By default, the syntax of the file is highlighted as shown in the following illustration.
What should we do if we want to turn the keyword red? Just type: hi Statement ctermfg=red. At this point, the color of if and else will turn red. : hi Statement ctermfg=red
Of course, we can use the same method to change colors for comments, constants, and data types. In this way, you will form your own color scheme, doesn't it feel very sour?
These are the details of creating a color Vim editor, please pay attention to other related articles!
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: 256
*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.