noi linux gedit 配置(c++环境)
基本配置
方法一
查看所有命令:
gsettings list-recursively | grep -i gedit
命令解释
gsettings set org.gnome.gedit.preferences.editor tabs-size 4
//设置缩进
gsettings set org.gnome.gedit.preferences.editor auto-save true
//设置自动保存
gsettings set org.gnome.gedit.preferences.editor auto-indent true
//设置自动缩进
gsettings set org.gnome.gedit.preferences.editor bracket-matching true
//设置显示匹配括号
gsettings set org.gnome.gedit.preferences.editor display-line-numbers true
//设置行号
gsettings set org.gnome.gedit.preferences.editor highlight-current-line true
//设置高亮
bash代码
gsettings set org.gnome.gedit.preferences.editor tabs-size 4
gsettings set org.gnome.gedit.preferences.editor auto-save true
gsettings set org.gnome.gedit.preferences.editor auto-indent true
gsettings set org.gnome.gedit.preferences.editor bracket-matching true
gsettings set org.gnome.gedit.preferences.editor display-line-numbers true
gsettings set org.gnome.gedit.preferences.editor highlight-current-line true
gsettings set org.gnome.gedit.preferences.editor create-backup-copy false
gsettings set org.gnome.gedit.plugins active-plugins "['docinfo', 'filebrowser', 'zeitgeistplugin', 'snippets', 'spell', 'time', 'externaltools', 'modelines']"
升级版本
#!/bin/bash
if [ `gsettings get org.gnome.gedit.preferences.editor display-line-numbers` == true ]; then
echo "检测到旧的 gedit 配置, 移动至 /tmp/gedit 目录"、
[ -d /tmp/gedit ] && rm /tmp/gedit -r
mv /home/hzoi/.config/gedit /tmp
fi
echo -e "Tab 大小\t: 4\n自动保存\t: true\n自动缩进\t: true\n括号匹配\t: true\n显示行号\t: true\n高亮当前行\t: true\n创建备份文件\t: true"
gsettings set org.gnome.gedit.preferences.editor tabs-size 4
gsettings set org.gnome.gedit.preferences.editor auto-save true
gsettings set org.gnome.gedit.preferences.editor auto-indent true
gsettings set org.gnome.gedit.preferences.editor bracket-matching true
gsettings set org.gnome.gedit.preferences.editor display-line-numbers true
gsettings set org.gnome.gedit.preferences.editor highlight-current-line true
gsettings set org.gnome.gedit.preferences.editor create-backup-copy false
echo -e "启用插件\t: externaltools"
gsettings set org.gnome.gedit.plugins active-plugins "['docinfo', 'filebrowser', 'zeitgeistplugin', 'snippets', 'spell', 'time', 'externaltools', 'modelines']"
echo -e -n "请输入主题前的数字(默认为0):\n\t(0) classic\n\t(1) tango\n\t(2) oblivion\n\t(3) kate\n\t(4) cobalt\n> "
read scheme
listscheme=(classic tango oblivion kate cobalt)
scheme=${listscheme[${scheme:-0}]:-classic}
gsettings set org.gnome.gedit.preferences.editor scheme $scheme
echo "gedit 主题已被设置为 $scheme"
echo "正在下载外部工具..."
wget http://files.cnblogs.com/files/youxam/gedit.tar.gz -q
wget http://files.cnblogs.com/files/youxam/bin.tar.gz -q
echo "正在解压..."
tar xzvf gedit.tar.gz -C /home/hzoi/.config > /dev/null
tar xzvf bin.tar.gz -C /home/hzoi/ > /dev/null
rm gedit.tar.gz
rm bin.tar.gz
echo "PATH=\${PATH}:/home/hzoi/.bin" >> /home/hzoi/.bashrc
source /home/hzoi/.bashrc
echo "正在下载 vim配置文件 ..."
wget http://files.cnblogs.com/files/youxam/.vimrc.js -O .vimrc -q
rm config.sh
保存文件为 set.sh
终端运行 sh ./set.sh
方法二
直接通过编辑-首选项
进行设置,太过简单不多描述。
编译配置
首先通过编辑-首选项-插件-外部命令
来打开外部命令,然后在工具-Manage External Tools
来添加新工具,工具代码使用bash
语言。
代码使用方式:+添加新插件,在编辑框中粘贴代码,快捷键:自定义,保存为:当前文档,输入为:当前文档,输出为:在下方面板中显示,适用范围为:所有文档 C++。
下面提供两种代码:
代码一:
#!/bin/sh
dir=$GEDIT_CURRENT_DOCUMENT_DIR
name=$GEDIT_CURRENT_DOCUMENT_NAME
pre=${name%.*}
g++ $dir/$name -o $pre -g -Wall
if test $? -eq 0; then
gnome-terminal -x bash -c "$dir/$pre;echo;read;"
fi
这种代码会打开一个终端,然后需要手动输入。调试代码时,比较繁琐。
那么我们就搞了一个更简单的方式。代码如下:
代码二
#!/bin/sh
fullname=$GEDIT_CURRENT_DOCUMENT_NAME
dir=$GEDIT_CURRENT_DOCUMENT_DIR
name=${fullname%.*}
inname=${name}.input
outname=${name}.output
ansout=${name}.ansout
cd $dir
cat $fullname | awk 'BEGIN{a=0} /\*\//{a=1} a==0{print $0}' | grep -v "\/\*" | cat > $inname
cat $fullname | awk 'BEGIN{a=0} /\*\//{a++} a==1{print $0}' | grep -v ["*\/""\/*"]| cat >$outname
g++ $fullname -o $name && ./$name <$inname >$ansout
diff -a -b -B -c -q $ansout $outname && echo Accept || echo Wrong Answer
cat $ansout
rm $ansout $outname $inname $names -rf
这个版本无需文件输入输出,只需要在文件头加入两个注释,第一个为样例输入,第二个为样例输出。
举个例子:
/*
6
1 30 3 2 3 4
2 16 2 5 6
3 5 0
4 4 0
5 11 0
6 5 0
*/
/*
25
*/
#include <iostream>
using namespace std;
....<code>
这样在编译时会在下方面板输出
Running tool: 运行命令
25
Done.
主题配置
在编辑-首选项-字体和颜色
中有许多配色方案可以选择,这里我们在推荐一个,同样附上源码:
<?xml version="1.0" encoding="UTF-8"?>
<!--
Copyright (C) 2011 Craig Russell
Author: Craig Russell <craig@craig-russell.co.uk>
This library is free software; you can redistribute it and/or
modify it under the terms of the GNU Library General Public
License as published by the Free Software Foundation; either
version 2 of the License, or (at your option) any later version.
This library is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
Library General Public License for more details.
You should have received a copy of the GNU Library General Public
License along with this library; if not, write to the
Free Software Foundation, Inc., 59 Temple Place - Suite 330,
Boston, MA 02111-1307, USA.
-->
<style-scheme id="ubistive" _name="Ubistive" version="1.0">
<author>tmz</author>
<_description>qtmz</_description>
<!-- Solarized Palette -->
<color name="base03" value="#000000"/>
<color name="base02" value="#041323"/>
<color name="base01" value="#233445"/>
<color name="base00" value="#456676"/>
<color name="base0" value="#839496"/>
<color name="base1" value="#A1A164"/>
<color name="base2" value="#EEE8D5"/>
<color name="base3" value="#FDF6E3"/>
<color name="yellow" value="#B58900"/>
<color name="orange" value="#CB4B16"/>
<color name="red" value="#DC322F"/>
<color name="magenta" value="#D38662"/>
<color name="violet" value="#AC71C4"/>
<color name="blue" value="#268BD2"/>
<color name="cyan" value="#2AA198"/>
<color name="green" value="#A5AF00"/>
<!-- Global Settings -->
<style name="text" foreground="base1" background="base03"/>
<style name="selection" foreground="base03" background="base00"/>
<style name="cursor" foreground="base1"/>
<style name="current-line" background="base02"/>
<style name="line-numbers" foreground="base01" background="base02"/>
<!-- Bracket Matching -->
<style name="bracket-match" foreground="base03" background="base01"/>
<style name="bracket-mismatch" foreground="red" background="base01"/>
<!-- Search Matching -->
<style name="search-match" foreground="base03" background="yellow"/>
<!-- Comments -->
<style name="def:comment" foreground="base01"/>
<style name="def:shebang" foreground="base01" bold="true"/>
<style name="def:doc-comment-element" italic="true"/>
<!-- Constants -->
<style name="def:constant" foreground="cyan"/>
<style name="def:special-char" foreground="green"/>
<!-- Identifiers -->
<style name="def:identifier" foreground="blue"/>
<!-- Statements -->
<style name="def:statement" foreground="orange"/>
<!-- Types -->
<style name="def:type" foreground="yellow"/>
<!-- Operators -->
<style name="def:operator" foreground="green"/>
<style name="def:bracket" foreground="red"/>
<!-- Others -->
<style name="def:preprocessor" foreground="violet"/>
<style name="def:error" foreground="red" bold="true"/>
<style name="def:note" foreground="magenta" bold="true"/>
<style name="def:underlined" italic="true" underline="true"/>
</style-scheme>
把它保存为a.xml。然后在回到编辑-首选项-字体和颜色
中点击 + 号,然后选择a.xml文件,便可以添加主题。(ps:有推荐者欢迎在下面留言,谢谢)。
自动补全
gedit的自动补全叫做片段,不像vscode,gedit的片段只能进行一些简单的操作,比如打出for,然后按下tab键,这样会出现一个
for (unsigned int i = 0; i < count; i += 1)
{
}
的代码片段,然后就可以通过移动tab键,来改变各个参量的值。同时可以通过工具-Manage Snippets
来管理片段。
嗯,就这些吧,若有疑问,随时留言。