将 Gedit 作为代码编辑器的 10 项增强调整
Gedit
![](/data/attachment/album/202304/03/163721ts31zsxhs1wuwp63.jpg)



> 
> Gedit 是一个好的文本编辑器。用这些技巧、窍门和调整把它变成一个好的代码编辑器。
> 
> 
> 


GNOME 可能已经抛弃了 Gedit 作为默认的文本编辑器，但它仍然是 Linux 老用户的最爱。


它主要是一个文本编辑器，但通过一些调整，它可以作为一个轻量级的代码编辑器使用。


是啊！为什么要用 VS Code 或其他专门的代码编辑器来编写 Bash 脚本或其他语言的简单程序？用 Gedit 也可以过一天。


我将在本文中分享一些我最喜欢的 Gedit 技巧和窍门。虽然大多数的调整对写代码是有益的，但有些对一般的文本写作也是有帮助的。


### 1、安装插件


可能个别人甚至不知道 Gedit 有强大的插件功能。你可以安装插件来获得额外的功能。


有两种类型的插件：


* 可以从编辑器菜单中访问的官方 Gedit 插件
* 第三方插件，可以从项目网站上下载，并放入插件目录中（下面讨论）。


Gedit 插件可以放在 `/usr/share/gedit/plugins` 或 `~/.local/share/gedit/plugins` 目录下。


![](/data/attachment/album/202304/03/163724kxe65v6v7b6yugs5.png)


你可以通过点击 “汉堡包” 菜单，然后打开 “<ruby> 首选项 <rt>  Preferences </rt></ruby>” 窗口来访问可用和已安装的插件。


![](/data/attachment/album/202304/03/163724k8a88x767elzzj4l.png)


首选项窗口有 “<ruby> 插件 <rt>  Plugins </rt></ruby>” 标签，你可以看到所有可用的插件。你可以使用复选框来启用和禁用这些插件。


![](/data/attachment/album/202304/03/163725uze81etglc8st7zi.png)


### 2、在侧边栏中显示文件浏览器


如果你正在处理一个有多个文件和文件夹的项目，在侧边栏中用文件浏览器看到所有可用的文件是相当有用的。


进入 “首选项” -> “插件”，启用 “<ruby> 文件浏览器面板 <rt>  File Browser Panel </rt></ruby>”。


![](/data/attachment/album/202304/03/163725j0i19zpdnd1642st.png)


之后，点击右上角的汉堡包菜单，从菜单 “<ruby> 查看 <rt>  View </rt></ruby>” -> “<ruby> 侧面板 <rt>  Side Panel </rt></ruby>” 启用侧面板视图。


现在把侧面板视图改为文件浏览器，如果还没有的话。


![](/data/attachment/album/202304/03/163726jhz7x7unzp0xnssr.png)


### 3、嵌入一个终端


是的！你可以在 Gedit 文本编辑器中直接嵌入一个终端。


这有什么意义呢？嗯，如果你正在写程序或脚本，嵌入终端可以帮助你运行脚本，并在编辑器中检查代码的变化。


![](/data/attachment/album/202304/03/163726xjmqj7blykjjmqye.png)


要得到这个，首先要安装这个插件（针对 Ubuntu）：



```
sudo apt install gedit-plugin-terminal

```

一旦插件安装完毕，从 “首选项” -> “插件” 中启用它。


![](/data/attachment/album/202304/03/163726cy0lhbx4mgw9umwc.png)


嗯，从汉堡包菜单-> “查看”-> “<ruby> 底部面板 <rt>  Bottom Panel </rt></ruby>” 中启用底部面板。


![](/data/attachment/album/202304/03/163727q110ulnm4lllwbl3.png)


### 4、Markdown 预览


喜欢 Markdown 吗？我也是！


有几个适用于 Linux 的 Markdown 编辑器，但你不必为了使用 Markdown 而去安装另一个应用程序。


在一个名为 “[Gedit Markdown Preview](https://github.com/maoschanz/gedit-plugin-markdown_preview?ref=itsfoss.com)” 的插件的帮助下，Gedit 完全有能力呈现 Markdown 代码。


Arch 用户可以在 AUR 中找到它，软件包为 `gedit-plugin-markdown_preview`。


其他 Linux 用户可以找到 [项目网页上的安装说明](https://github.com/maoschanz/gedit-plugin-markdown_preview?ref=itsfoss.com#installation)。


一旦安装，在插件中启用它。你必须从汉堡包菜单 -> “查看”-> “侧面板” 中启用侧面板视图。


![](/data/attachment/album/202304/03/163727c88mg8ew11hlrir8.png)


有了这个，它就开始在侧面板或底部窗格中显示 Markdown 文本的渲染文本。


![](/data/attachment/album/202304/03/163727rj55yylh8j2mmy92.png)


### 5、创建代码片段


*好的码农编码，优秀码农复用。*


如果你发现自己重复使用同一段代码或文本，你可以将其保存为片段，并在需要时插入。这将为你节省一些时间（和挫折）。


先启用片段插件：


![](/data/attachment/album/202304/03/163728qkcrr3gc3ydcvxmy.png)


现在你可以从汉堡包菜单-> “<ruby> 管理片段 <rt>  Manage Snippets </rt></ruby>” 来访问片段。


![](/data/attachment/album/202304/03/163728ysgj77bleeb9z1fs.png)


你会发现它已经有几个为各种编程语言添加的片段。


![](/data/attachment/album/202304/03/163728lx0a6lnyj3icai8n.png)


你也可以通过点击左下角的 “+” 号将你的片段添加到所需的文件夹中。你也可以为片段指定一个快捷键，以便更快速地插入它们。


![](/data/attachment/album/202304/03/163729p5cppapi15fzfmpa.png)


例如，我为 [添加一个 Markdown 表格](https://itsfoss.com/markdown-table/) 添加了一个新的片段，并为其分配了一个键盘快捷键和 TAB 触发器（如上图所示）。现在，如果我在 Markdown 文档中按 `CTRL + Alt + S`，就会添加一个表格。或者，输入 `table` 并按下 `TAB` 键也会添加 Markdown 表格。



> 
> ? 通常，片段被保存在 `/usr/share/gedit/plugins/snippet` 文件夹中作为 XML 文档，但我找不到新添加的片段被保存在哪里。
> 
> 
> 


### 6、修复深色模式的问题


编码员喜欢深色模式。Gedit 遵守系统主题，如果你在操作系统层面切换到深色模式，它也会切换到深色模式。


一个主要的问题是，你无法阅读当前选定行的任何内容，因为文本和行的高亮部分都是白色的。


![](/data/attachment/album/202304/03/163729sk08mmtlrwmrerot.png)


这个问题没有解决办法。然而，一个变通的办法是，要么禁用当前行的高亮显示，要么使用不同的颜色方案。


进入 “首选项” -> “<ruby> 字体和颜色 <rt>  Font &amp; Colors </rt></ruby>”，然后选择像 Oblivion 这样的深色方案。这将稍微改变颜色方案，但至少你能看到高亮行的文字。


![](/data/attachment/album/202304/03/163729gohgshogogzalahf.png)


### 7、快速高亮选中的文本


双击一个词，Gedit 就会高亮显示整个文档中出现的所有相同的词。


![](/data/attachment/album/202304/03/163730bltknsltaky6aljd.png)


虽然有一个官方插件，但这个功能默认是不启用的。


进入 “首选项” -> “插件”，启用 “<ruby> 快速高亮 <rt>  Quick Highlight </rt></ruby>” 选项。


![](/data/attachment/album/202304/03/163730jzee85snsgh6ph4x.png)


### 8、显示行号


许多代码编辑器默认都会显示行号。当你看到 “第 X 行的语法错误 ” 时，它可以帮助你快速找到该行。


你可以通过进入 “首选项” -> “查看” -> “<ruby> 显示行号来启用行号 <rt>  Display Line Numbers </rt></ruby>”：


![](/data/attachment/album/202304/03/163731lb5hegchhebbxcn5.png)


你也可以从底部启用或停用它。


![](/data/attachment/album/202304/03/163731k3ktc8b8yj5eqk3e.png)


### 9、保存一个版本


如果你正在修改一个文件，也许建立一个备份副本会更好？Gedit 可以自动做到这一点。


在 “首选项” -> “<ruby> 编辑器 <rt>  Editor </rt></ruby>” -> “<ruby> 创建一个备份副本 <rt>  Create a Backup copy </rt></ruby>” 中启用这个功能。


![](/data/attachment/album/202304/03/163732zr8lokokdz88za2a.png)


一个在原文件名称后面加上 `~` 符号的文件将作为备份文件出现。


![](/data/attachment/album/202304/03/163732wn8ut47ixz4y7nxp.png)


### 10、自动保存文件


既然我们在谈论版本和备份，那么 [在 Gedit 中启用自动保存](https://itsfoss.com/how-to-enable-auto-save-feature-in-gedit/) 怎么样？这样，如果你在处理一个文件时，忘记用 `Ctrl+S` 手动保存，修改的内容会自动保存。



> 
> ? 这个功能对一个从未在磁盘上保存过的全新文档不起作用。
> 
> 
> 


从 “偏好” -> “编辑器”，你可以启用 “<ruby> 自动保存 <rt>  Autosave </rt></ruby>” 功能。默认情况下，它每 10 分钟自动保存一次，但你可以根据自己的喜好改变时间。


![](/data/attachment/album/202304/03/163732zrqk4m8xnnhxhemx.png)


还有一个第三方的 [smart-auto-save 扩展](https://github.com/seanh/gedit-smart-autosave/?ref=itsfoss.com)，可以在你停止输入时自动保存文档。


![](/data/attachment/album/202304/03/163733pt0rdprpr0tjdrsi.png)


### 知道更多的 Gedit 技巧吗？


使用任何软件的乐趣之一是发现它不那么明显的功能。


在这里，你最喜欢哪个 Gedit 的调整？你知道一个没有多少人知道的 Gedit 的秘籍吗？在评论中与我们分享吧？




---


via: <https://itsfoss.com/gedit-tweaks/>


作者：[Abhishek Prakash](https://itsfoss.com/author/abhishek/) 选题：[lkxed](https://github.com/lkxed/) 译者：[wxy](https://github.com/wxy) 校对：[wxy](https://github.com/wxy)


本文由 [LCTT](https://github.com/LCTT/TranslateProject) 原创编译，[Linux中国](https://linux.cn/) 荣誉推出


OK
![Warp Terminal](/assets/images/warp-terminal.webp)


![Warp Terminal](/assets/images/warp-terminal.webp)

GNOME may have ditched Gedit as the default text editor but it is still a favorite of long-time Linux users.

It is primarily a text editor, but with some tweaks, it can work as a lightweight code editor.

Yeah! Why use VS Code or other dedicated code editors for writing Bash scripts or simple programs in other languages? Gedit saves the day.

I'll share some of my favorite Gedit tips and tricks in this article. While most of the tweaks are beneficial for writing codes, some could be helpful for general text writing as well.

## 1. Install plugins

Few people don't even know that Gedit has a robust plugin feature. You can install plugins to get additional features.

There are two kinds of plugins:

- Official Gedit plugins that are accessible from the editor menu
- Third-party plugins that can be downloaded from the project websites and placed into the plugins directory (discussed below)

The Gedit plugins can be located in `/usr/share/gedit/plugins`

or `~/.local/share/gedit/plugins`

directories.

![](https://itsfoss.com/content/images/2023/03/PLUGIN-INSTALL-gedit-plugin-saved-to-the-directory.png)

You can access the available and installed plugins by clicking the Hamburger menu and then opening the Preference window,

![](https://itsfoss.com/content/images/2023/03/ACCESS-PREFERENCES.png)

The Preferences window has the Plugins tab and you can see all the plugins available to you. You can use the checkbox to enable and disable the plugins.

![](https://itsfoss.com/content/images/2023/03/PLUGIN-INSTALL-plugins-in-prefereneces.png)

## 2. Show file browser in the side panel

If you are working on a project that has multiple files and folders, getting the file browser to see all the available files in the sidebar is quite helpful.

Go to **Preferences -> Plugins** and enable the **File Browser Panel**.

![](https://itsfoss.com/content/images/2023/03/FILE-BROWSER-file-browser-plugin-in-preferences.png)

After that, click on the hamburger menu at top right and enable the Side Panel View from Menu **View -> Side Panel**

Now change the side panel view to file browser, if not already.

![](https://itsfoss.com/content/images/2023/03/FILE-BROWSER-file-browser-as-a-side-pane.png)

## 3. Embed a terminal

Yes! You can embed a terminal right into the Gedit text editor.

What's the point? Well, if you are writing programs or scripts, an embed terminal helps you run the script and check the code changes right there in the editor.

![](https://itsfoss.com/content/images/2023/03/TERMINAL-gedit-embedded-terminal.png)

To get this, first install the plugin (for Ubuntu):

`sudo apt install gedit-plugin-terminal`


Once the plugin is installed, enable it from Preferences->Plugin.

![](https://itsfoss.com/content/images/2023/03/TERMINAL-embedded-terminal-plugin-in-plugins-tab.png)

Mow, enable bottom panel from hamburger menu -> **View -> Bottom Panel**

![](https://itsfoss.com/content/images/2023/03/TERMINAL-enable-bottom-panel-for-embedded-terminal.png)

## 4. Markdown preview

Love Markdown? Me too!

There are several Markdown editors available for Linux but you don't have to install another application just to use Markdown.

With the help of a plugin, unsurprisingly called [Gedit Markdown Preview](https://github.com/maoschanz/gedit-plugin-markdown_preview), Gedit is perfectly capable of rendering Markdown code.

Arch users can find it in the AUR as gedit-plugin-markdown_preview package.

Other Linux users can find the [installation instructions on the project webpage](https://github.com/maoschanz/gedit-plugin-markdown_preview#installation).

Once it is installed, enable it in plugins. You must enable the side panel view from the hamburger menu --> View > Side panel

![](https://itsfoss.com/content/images/2023/03/ENABLE-SIDE-PANEL.png)

With that, it starts showing rendered text for Markdown text in the side or bottom pane.

![](https://itsfoss.com/content/images/2023/03/MARKDOWN-PREVIEW-markdown-preview.png)

## 5. Create snippets

*Good coders code. Better coders reuse.*

If you find yourself reusing same piece of code or text, you can save it as snippet and insert it when needed. This will save you some time (and frustration).

Enable the Snippet plugin first.

![](https://itsfoss.com/content/images/2023/03/ENABLE-SNIPPET-PLUGLIN.png)

Now you can access the snippets from **Hamburger Menu -> Manage Snippets**

![](https://itsfoss.com/content/images/2023/03/ACCESS-MANAGE-SNIPPET.png)

You'll find that it already has several snippets added for various programming languages.

![](https://itsfoss.com/content/images/2023/03/SNIPPET-pre-created-snippets-in-gedit-showing-cpp-main-snippet.png)

You can also add your snippets in the desired folder by clicking the + sign on the bottom left. You may also assign a shortcut key to snippets to insert them even more quickly.

![](https://itsfoss.com/content/images/2023/03/adding-a-custom-markdown-table-snippet.png)

For example, I added a new snippet for [adding a Markdown table](https://itsfoss.com/markdown-table/) and assigned a keyboard shortcut and tab trigger to it (as seen in the above image). Now, if I press **CTRL + Alt + S **in a Markdown document, a table is added. Alternatively, typing **table **and pressing the TAB key also adds the Markdown table.

`/usr/share/gedit/plugins/snippet`

folder as XM docs, but I could not find where the newly added snippets are saved.## 6. Fix the dark mode problem

Coders love dark mode. Gedit adheres to the system theme, and if you switch to dark mode at the OS level, it also switches to dark mode.

The one major problem is that you cannot read anything on the currently selected line because both text and line highlights are white colored.

![](https://itsfoss.com/content/images/2023/03/DARK-MODE-ISSUE-text-not-visible-in-highlight-line.png)

There is no fix for this. However, a workaround is to either disable highlighting the current line or use a different color scheme.I prefer choosing a different color scheme.

Go to Preferences -> Font & Colors and then select a dark color scheme like Oblivion. It will change the color scheme a little but at least you will be able to see the text on the highlighted lines.

![](https://itsfoss.com/content/images/2023/03/DARK-MODE-ISSUE-settting-a-new-clor-scheme-to-the-dark-mode-font-issue.png)

## 7. Quick highlight selected text

Double-click a word and Gedit highlights all the occurrences of the same word in the entire document.

![](https://itsfoss.com/content/images/2023/03/QUICK-HIGHLIGHT-result.png)

This feature is not enabled by default though an official plugin is available.

Go to Preferences -> Plugins and enable the Quick Highlight option.

![](https://itsfoss.com/content/images/2023/03/QUICK-HIGHLIGHT-already-available-plugin-no-external-needed.png)

**Quick highlight**default plugin in Preferences > Plugins

## 8. Show line numbers

Many code editors show the line numbers by default. It helps you quickly go to the line when you see a 'syntax error at line X'.

You can enable line numbers by going to **Preferences -> View -> Display Line Numbers:**

![](https://itsfoss.com/content/images/2023/03/LINE-NUMBER-display-line-numbers-in-gedit.png)

You may also enable or disable it from the bottom.

![](https://itsfoss.com/content/images/2023/03/SHOW-LINE-NUMBERS.png)

## 9. Save a version

If you are modifying a file, perhaps it would be better to create a backup copy? Gedit can do this automatically.

Enable this feature in **preferences -> Editor -> Create a Backup copy**.

![](https://itsfoss.com/content/images/2023/03/SAVE-BACKUP.png)

A file with the name of the original file appended with a `~`

symbol will appear as the backup file.

![](https://itsfoss.com/content/images/2023/03/VERSION-in-file-manager.png)

## 10. Autosave files

Since we are talking about versions and backups, how about [enabling autosave in Gedit](https://itsfoss.com/how-to-enable-auto-save-feature-in-gedit/)? This way, if you are working on a document and forgot to save it using Ctrl+S manually, the changes get saved automatically.

From **Preferences -> Editor**, you can enable the Autosave feature. By default, it autosaves every 10 minutes but you can change the duration to your liking.

![](https://itsfoss.com/content/images/2023/03/AUTO-SAVE-files-the-built-in-save-function-that-saves-the-document-after-some-time.png)

There is also a third-party [smart-auto-save extension](https://github.com/seanh/gedit-smart-autosave/) that autosaves the document as soon as you stop typing it.

![](https://itsfoss.com/content/images/2023/03/AUTO-SAVE-Smart-auto-save.png)

## Know more Gedit tricks?

If you want, you can also change the Gedit theme.

[Install and Use Additional Gedit Color ThemesDon’t like the default looks for the Gedit text editor? You can surely try to change the color themes. Here’s how to do that.](https://itsfoss.com/gedit-themes/)![](https://itsfoss.com/content/images/2023/07/gedit-theme-change.png)


![](https://itsfoss.com/content/images/2023/07/gedit-theme-change.png)

One of the joys of using any piece of software is discovering it's not-so-obvious features. We have covered such application-specific tweaks in the past. Take a look at Nautilus tips:

[13 Ways to Tweak Nautilus File Manager in Linux to Get More Out of itNautilus is GNOME’s default file manager application, and you may have seen it in many Linux distributions. It’s a good file manager with plenty of features. However, you can enhance your experience by employing some tweaks and tips. I am going to share such tips and tweaks in](https://itsfoss.com/nautilus-tips-tweaks/)![](https://itsfoss.com/content/images/wordpress/2022/07/customizing-GNOME-Nautilus-File-Manager.png)


![](https://itsfoss.com/content/images/wordpress/2022/07/customizing-GNOME-Nautilus-File-Manager.png)

Or, the [Flatpak tips and tweaks](https://itsfoss.com/flatpak-tips-tweaks/):

[6 Tips and Tools to Enhance Your Flatpak Experience in LinuxIf you love using Flatpak applications, here are a few tips, tools, and tweaks to make your Flatpak experience better and smoother.](https://itsfoss.com/flatpak-tips-tweaks/)![](https://itsfoss.com/content/images/wordpress/2022/07/enhance-flatpak-experience-in-linux.png)


![](https://itsfoss.com/content/images/wordpress/2022/07/enhance-flatpak-experience-in-linux.png)

Which Gedit tweaks you liked the most here? Do you know a killer Gedit feature that not many people are aware of? Share it with us in the comments?