Source: WeChat Official Account 【Osprey Talks Microcontrollers】
Author: Osprey
ID: emOsprey
This note introduces some commonly used KEIL editing methods and techniques by Osprey to speed up editing.
Of course, many people now prefer using software like VSCode or SI for editing, but it cannot be denied that many practitioners still choose KEIL as their editing software, as it is their first love and they are already accustomed to it.
Thus, this note serves as a summary of editing techniques.
Additionally, there is a series of references regarding the usage of KEIL software:
Setting Up the KEIL Development Platform for STM32 Project Templates (1)
Creating a New Project in STM32 Project Templates (2)
Simu Target in STM32 Project Templates (3)
FLASH Target in STM32 Project Templates (4)
RAM Target in STM32 Project Templates (5)
1、Dual Screen
Sometimes it is necessary to view the contents of two files simultaneously, such as a C file and an H file. In this case, you can use the dual screen feature in KEIL.
Choose between landscape or portrait mode; below is the portrait effect:
2、Replacing TAB with Space Key
After installing the KEIL software, by default, the TAB key occupies 2 spaces. Although this is stated, it is still a TAB key, just displayed differently.
To distinguish between TAB and spaces, we can enable this display feature:
We can see the effect in the image below, where the left dot represents a space and the right arrow represents the TAB key.
Why is this important? We know that some editors occupy 2 spaces for the TAB key, while others occupy 4 or 8 spaces, and there is no standard. Therefore, when you open the same file in different editors, the displayed format may vary.
The specific manifestation is that in one editor, the code appears neat, but when switching to another editor, the code becomes messy.
Thus, a better approach is to replace the TAB key with the space key, so regardless of which editor you open it in, it remains tidy, and you do not have to modify how many spaces a TAB occupies.
So, we can enable this option:
Now, when you press the TAB key, it automatically converts to the space key, eliminating the need to manually replace or type spaces.
Another trick that experienced users employ is that shift + TAB can shift the selected multiple lines of code left, while the TAB key can shift the selected multiple lines of code right.
3、Open Header Files
A significant drawback of KEIL is that it is difficult to find a file. Here, Osprey introduces a quick method to open the corresponding H file for a C file:
If the file has a header file, it can be opened quickly.
For included header files, you can perform the following operations:
Version 5.30 introduced a new feature that allows switching back and forth between C files and H files using a similar method.
Also, for commonly used header files, we can add them directly to the project directory, making it easier to open files (it is not recommended to place all header files in the project directory, as it will clutter the files).
If too many files are open and you do not want to close them, you can select files in this way:
If you want to close them, you can use the following method:
Of course, you can open the corresponding folder or copy the file path, which is very convenient for opening library files.
You no longer need to search for files one by one in the installation directory.
4、Add Description File
Sometimes, it is necessary to add a description to the project. In this case, we can add a txt file for explanation:
5、Temporarily Disable Files
When we do not want a source file to participate in linking and compilation, we can remove it from the project. However, sometimes we want to keep it in the project directory for easy viewing, just like the printf_fifo.c file shown above. We can set it as follows:
Then enter the following window and uncheck it:
For more information about it, refer to Osprey’s STM32 project template series articles.
6、Search
Using CTRL + F or CTRL + H shortcuts allows for quick searching or replacing. There is also an option to display all search results:
You can also search in a precise manner, such as matching whole words (Match whole word), case-sensitive matching (Match case), or even using regular expressions.
If you have other useful editing tips, feel free to leave a comment for discussion.
-THE END-
If this was helpful to you, remember to share it!
WeChat Official Account: Osprey Talks Microcontrollers
Weekly Updates on Microcontroller Knowledge
Long press to follow the WeChat account included in the image
Osprey, a bestselling author who is lost in embedded systems
Personal WeChat: EmbeddedOsprey
Long press to open the other person’s business card follow