Editing Tips and Techniques for KEIL

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.

Editing Tips and Techniques for KEIL

Choose between landscape or portrait mode; below is the portrait effect:

Editing Tips and Techniques for KEIL

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:

Editing Tips and Techniques for KEIL

We can see the effect in the image below, where the left dot represents a space and the right arrow represents the TAB key.

Editing Tips and Techniques for KEIL

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:

Editing Tips and Techniques for KEIL

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:

Editing Tips and Techniques for KEIL

If the file has a header file, it can be opened quickly.

For included header files, you can perform the following operations:

Editing Tips and Techniques for KEIL

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).

Editing Tips and Techniques for KEIL

If too many files are open and you do not want to close them, you can select files in this way:

Editing Tips and Techniques for KEIL

If you want to close them, you can use the following method:

Editing Tips and Techniques for KEIL

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:

Editing Tips and Techniques for KEIL

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:

Editing Tips and Techniques for KEIL

Then enter the following window and uncheck it:

Editing Tips and Techniques for KEIL

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:

Editing Tips and Techniques for KEIL

Editing Tips and Techniques for KEIL

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.

Recommended Reading:
Years Later, You Will Thank Yourself for Writing Exception Handling Code
The Ultimate Serial Port Reception Method, Extreme Efficiency
Why You Must Master KEIL Debugging Methods?
Evolution of Delay Functions (Collection)
Pointers, Are They Really That Difficult? | Analyzing the Process and Significance of Pointers (1)
How to Write a Robust and Efficient Serial Port Receiving Program?
Things About KIEL Debugging: Window Display – Variables (2)
How Should You Set Breakpoints After Years of Debugging Microcontrollers? | Subverting Cognition

-THE END-

If this was helpful to you, remember to share it!

WeChat Official Account: Osprey Talks Microcontrollers

Weekly Updates on Microcontroller Knowledge

Editing Tips and Techniques for KEIL

Long press to follow the WeChat account included in the image

Osprey, a bestselling author who is lost in embedded systems

Personal WeChat: EmbeddedOsprey

Editing Tips and Techniques for KEIL

Long press to open the other person’s business card follow

Leave a Comment