使用Ubuntu

/ 教程

谈起Ubuntu系统,早在很早的时候2011年开始,我就渐渐的将其作为自己的桌面使用了。大概三年前,因为字体渲染和公司使用MacMini的原因,我全方位的切换成了用MacOS。最近,因为某些契机,我重新安装使用了Ubuntu。三年多不见,Ubuntu在我看来,变得是更加好用了。从某种角度来说,Macos与Windows都难媲美他了。或者说,Ubuntu独有的开放风格,将他的使用性提升到了MacOS和Windows因为自身原因不能轻易企及的程度,就如移动时代的Android,只是他们际遇不同,结果不同罢了。

Ubuntu系统在我看来,完全是的结合了Windows和MacOS的优点,又具有高度的可定制性,发展至2022年对我来说,已经找不到使用另外两个系统的理由了。简单的就拿其系统的键盘快捷键来说,设置的非常合理且非常丰富,其他两个系统完全不是对手,例如:

  • [Alt + Esc] 直接切换窗口
  • [Alt + Tab] 在打开的窗口之间切换
  • [Alt + `] 切换至当前窗口应用的其他已打开窗口
  • [Super + Tab] 切换至其他应用的窗口
  • [Ctrl + Super + D] 隐藏所有正常窗口
  • [Shift + Ctrl + Alt + R] 开始或结束屏幕录像
  • [Alt + 鼠标右键] 移动窗口
  • [Super + V] 打开系统通知列表
  • [Shift + PrtSc] 屏幕截图一个选取的区域

4K分辨率

  1. 如果使用「设置」中「显示器」的「缩放」进行150的比例缩放,鼠标的移动会变得很奇怪。所以直接使用gnome-tweak-tool工具作如下调整: AgaveXX-Bold字体在Ubuntu系统的Emacs下的代码
  2. /etc/default/grub中添加RUB_CMDLINE_LINUX_DEFAULT="libata.noacpi=1",如果开机报错:ACPI BIOS Error(bug):Could not resolve symbol [\SB.PCI0.SAT0.S

Emacs的字体渲染问题

遥想三四年前,我那时候开始使用Agave字体,但是发现在我的Ubuntu下的显示效果不如MacOS下。最近重新看了下这个问题,才明白这个本质上是Emacs字体渲染的问题,当在Emacs编辑器中设置一个字体时,如果并没有安装该字体的Bold版本,比如只安装了Agave-Regular字体却并没有安装Agave-Bold,则设置Bold在Emacs系统中是不能生效的。

AgaveXX-Bold字体在Ubuntu系统的Emacs下的代码

AgaveXX-Bold字体在Ubuntu系统的Emacs下的代码

使MonacoBSemi字体的英文与使用文泉微米黑的中文字体对齐

使MonacoBSemi字体的英文与使用文泉微米黑的中文字体对齐

Bold字体

然而不管是在Ubuntu系统还是MacOS系统比如是在Terminal中,假设配置使用了一个字体的Bold但却并没有安装该字体的Bold版本,则系统会自动处理渲染出该字体的Bold。不同的是,因为MacOS系统的字体渲染非常的优秀(至此相信乔布斯曾经演讲说自己大学辍学前旁听过美术课所言不虚),所以即使是只安装了Regular字体比如Agave-Regualar,其系统的渲染效果肉眼看起来辨识度也好似安装在使用了Bold一样,我因此误以为我在MacOS下设置Agave字体的Bold代码生效了,但其实没有,这也是为什么我以前在MacOS的Emacs中设置Agave使用Book有时候看起来比Bold显示的字体还会更粗一些的原因。

鉴于Ubuntu并没有MacOS系统的这种渲染效果,我索性安装FontForge手动调整了Agave字体的Weight,可见我的AgaveXX-BoldAgaveB字体。另外我收集的加粗版的Monaco字体,和本身就加粗的苹果苹方字体(PingFangSC)也在里面。

中英文等宽

Emacs另外的一个跟字体设置有关的问题是中文显示的问题,一个汉字对应的宽度应该和两个英文字母一样,而这本质上算是Emacs需要处理的问题,无关于系统,解决方法就是中英文使用不同字号的字体。

Emacs中可用(set-face-attribute 'default nil :font "Agave-12:bold")来设置英文字体,使用(dolist (charset '(kana han symbol cjk-misc bopomofo gb18030)) (set-fontset-font t charset "文泉驿等宽微米黑-12:normal"))来设置中文字体,可见:我的Emacs配置代码

行间距

另外的是,Emacs可以通过(setq-default line-spacing 3)来调整行间距的。

Ubuntu下字体的调整

使用UbuntuMono-Bront字体

Ubuntu系统自带一款等宽字体叫Ubuntu Mono,该字体的中文部分应该使用的是文泉字体。而他的英文部分其实不够好看,可以安装他的一个修改版字体Ubuntu Mono - Bront,在终端中显示效果更好。

文泉微米黑的问题

如上所说,Ubuntu系统中默认使用的字体的中文部分应该借自文泉正黑,正黑字体看起来更高,而文泉微米黑较之会更方正且会更粗一切。文泉字体的安装命令是:aptitude install fonts-wqy-zenhei fonts-wqy-microhei xfonts-wqy ttf-wqy-microhei ttf-wqy-zenhei

然而,安装完成会依然觉得效果不如MacOS,比如Ubuntu下的Ibus输入法的输入框字体即使改成使用文泉依旧觉得偏细,我起初以为这是Ubuntu系统渲染的问题,最后发现其实某种程度上跟文泉字体有些关系。

查一下发现MacOS系统默认的中文字体叫苹方(PingFangSC),该字体共有6种粗细的变体字体(UltraLight/Thin/Light/Regular/Medium/Semibold)。相比之下,文泉字体只有一种常规字体并无任何变体字体,其Bold字体完全依赖于系统的字体渲染程序,而这就是Ibus的中文输入框字体不够粗的原因。

使用苹方(PingFangSC)简体中文字体

细看MacOS系统的苹方字体,会发现即使是该字体的Regular变种字体,也比其他类似的字体更粗一些,字体更粗我觉得是会让人看起来更舒服的,下载后双击安装或者复制到~/.local/share/fonts/目录然后执行命令fc-cache -fv刷新下字体缓存。

另外扩展开来,如果把苹方字体或其更粗的变体字体用作系统界面的主字体或浏览器默认字体,效果也非常的好。

Ubuntu优化

Ubuntu优化

Ubuntu系统设置

Ubuntu系统设置

Ubuntu文件管理

Ubuntu文件管理

Ubuntu扩展

Ubuntu扩展

休眠功能

根据论坛里面的指引: 1. sudo apt install pm-utils hibernate来安装之后,把blkid | grep swap显示的swap分区的UUID以GRUB_CMDLINE_LINUX_DEFAULT="quiet splash resume=UUID=<YOUR_COPIED_UUID>"的形式替换/etc/default/grub文件中的GRUB_CMDLINE_LINUX_DEFAULT="quiet splash"那行。 2. 运行sudo update-grub来更新启动项。 3. 使用命令sudo systemctl hibernate来启动休眠,或者安装SeSimplr Off Menu系统插件以增加系统休眠项到系统的左上角菜单栏来使用。

Ubuntu系统安装

使用balenaEtcher可以非常容易的制作一个USB启动U盘来进行安装,Ubuntu官方有详尽文档

我一般都是先划分一个单独的20G空间安装系统,使用一段时间发现需要空间再扩展系统容量,以防使用度不高或者感觉新系统不够稳定想继续使用旧系统的话,就直接删掉新系统。如果需要扩展系统分区容量,建议使用GParted来操作。

Ubuntu系统,除了传统的可以使用apt来安装系统软件外,现在有了另外三种方式:

系统自定义设置

  • 整点半点自动报时功能:使用crontab实现,https://github.com/yanyingwang/hours-chime
  • 交换ctrl和capslock:需要安装sudo aptitude install gnome-tweak-tool然后在键盘和鼠标其他布局选项中设置。
  • vim和系统共享粘贴板:sudo aptitude install vim-gtk
  • 挂载exfat分区:打开磁盘程序,编辑相应分区的挂载选项,填写加入选项uid=1000,gid=1000,dmask=022,fmask=133,可以参见Ubuntu Web Manuals
  • 我收集的编程字体:https://github.com/yanyingwang/favfonts

系统扩展和软件

  • Firefox切换使用中国同步服务器:直接安装插件https://g-fox.cn/chinaedition/addons/cpmanager/cpmanager-latest.xpi
  • Firefox的视频播放:需要安装ffmpegsudo apt install ffmpeg
  • Shadowsocks-Qt5:使用appimageAppImageHub下载。
  • Qv2ray: 因为Shadowsocks很容易被屏蔽,所以我转而使用Qv2ray,Qv2ray也可以添加一个订阅地址,然后自动更新订阅里面的所有可用连接,安用命令snap install Qv2ray,然后v2ray内核可以在其github的release页面下载比如linux的可为v2ray-linux–64.zip。
  • 词典:sudo aptitude install goldendict使用第三方词库:索引1 / 索引2
  • VLC:加入PPA源sudo add-apt-repository ppa:savoury1/vlc3或者直接使用snap安装sudo snap install vlc
  • 安装最新版terminator终端(旧版无法调整字体行高):需要加入PPA源sudo add-apt-repository ppa:mattrose/terminator
  • 安装Dropbox:参见官方文档
  • 安装qbittorrent:https://github.com/c0re100/qBittorrent-Enhanced-Edition
  • icloud-for-linux:snap安装命令snap install icloud-for-linux
  • electronic-wechat:使用snap安装命令snap install electronic-wechat
  • gedit-plugin-bracket-completion / gedit-plugin-draw-spaces … Gedit文本编辑器的插件(apt命令安装)。
  • gnome-sushi: 实现在文件管理中类似MacOS系统的按空格键预览文件的功能(apt命令安装)。
  • sudo apt-get install gnome-clock
  • aptitude install cutmp3
  • 其他:snap install pinta telegramsudo aptitude install proxychains4

我的Gnome Extensions

Ubuntu把系统的可定制化发挥到了极致,其系统的整个桌面有官方的插件市场可以选装定制,安装完Gnome的浏览器插件即可直接从官方插件市场中点击安装,安装完的插件在本地系统的位置是~/.local/share/gnome-shell/extensions/

  • GSConnect by dlandau:手机电脑设备共享通知信息。
  • Net speed Simplified by prateeksu:可以在Ubuntu桌面的顶部显示当前网络使用的带宽。
  • Lock Keys by kazimieras.vaina:当按下CapsLock或者NumberLock按键时,显示桌面OSD通知告知开关状态。
  • Nothing to say by wbolster:桌面顶部状态栏增加麦克风开关图标,并可设置快捷按键开关之。
  • Bedtime Mode by ionutbortis:设置一个时间使屏幕色彩变黑白,以提醒用户睡眠时间已到。
  • Lunar Calendar 农历 by Nei:增加中国时辰和日历日期到顶部的时间日期显示中。
  • Notifications Alert by hackedbellini:如果系统有通知,则在闪烁显示系统顶部状态栏的时间以提醒用户。
  • Always Indicator by mzur:如果系统有通知,则在系统顶部状态栏时间的右边一直显示一个原点。
  • Show Desktop Button by JSZVB:增加一个桌面图标到顶部状态栏中,以供点击后隐藏窗口查看桌面和恢复隐藏窗口。
  • Tweaks & Extensions in System Menu by philippetroin:将优化扩展设置选项加入到系统顶部状态栏最右边的关机图标下拉菜单栏内。
  • Customize IBus by HollowMan6:自定义Ibus输入法的设置(但是我最后还是使用了ibus的搜狗输入法)。
  • Overview Navigation by nathanielsimard:桌面预览时,按下space按键后赋予窗口字母,以供使用键盘快速切换。
  • Workspace Switcher Manager by GdH:自定义切换工作区时的显示。
  • Jiggle by jeffchannell:像MacOS一样,当快速晃动鼠标时,鼠标会变大,以供用户可以在屏幕上轻松的找到鼠标位置。
  • Eye and Mouse Extended by alexey.lovchikov:在系统顶部状态栏增加一个眼睛图标,眼睛会一直指向着屏幕上的鼠标。
  • Mouse battery by mouse-battery:显示鼠标电量图标在系统顶部状态栏。
  • Color Picker by grroot:点击选取查看桌面任意部分的颜色。
  • Titlebar Screenshot by jmaargh:在窗口的右键菜单里加入截屏当前窗口的选项。
  • Screenshot Locations by TimurKiyivinski:自定义系统截图程序的储存位置。
  • EasyScreenCast by tobias47n9e:屏幕录像。
  • Panel OSD by jens:设置系统通知的位置和大小。
  • Better OSD by StopLemming:自定义系统OSD通知的位置和大小,并且使其透明。
  • GNOME Fuzzy Search by fffilo:使系统搜索的时候可以模糊搜索,比如搜索ffx可以搜索到firefox程序.
  • Places Status Indicator by fmuellner:在系统顶部的状态栏增加位置图标以供快速打开文件。
  • Sound Input & Output Device Chooser by kgshank:在系统顶部状态栏最右边的关机图标菜单栏中加入音频设置选择选项。
  • 其他:Clipboard Indicator by Tudmotu,Customize Clock on Lock Screen by pratap@fastmail.fm,Freon by UshakovVasilii,Vitals by corecoding

Emacs style shortcut

在Ubuntu系统的各个输入框和进行文本输入时,如何最大程度的兼容使用Emacs风格的快捷键,比如Ctrl+a到行首,Ctrl+b光标向后移动等。 1. 先安装gnome-tweak-tool然后在键盘和鼠标中找到Emacs输入打开。 2. 删除或者重命名/usr/share/themes/Emacs/gtk-3.0/gtk-keys.css,然后创建~/.config/gtk-3.0/gtk.css文件,内容为:

  1
  2
  3
  4
  5
  6
  7
  8
  9
 10
 11
 12
 13
 14
 15
 16
 17
 18
 19
 20
 21
 22
 23
 24
 25
 26
 27
 28
 29
 30
 31
 32
 33
 34
 35
 36
 37
 38
 39
 40
 41
 42
 43
 44
 45
 46
 47
 48
 49
 50
 51
 52
 53
 54
 55
 56
 57
 58
 59
 60
 61
 62
 63
 64
 65
 66
 67
 68
 69
 70
 71
 72
 73
 74
 75
 76
 77
 78
 79
 80
 81
 82
 83
 84
 85
 86
 87
 88
 89
 90
 91
 92
 93
 94
 95
 96
 97
 98
 99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
/* ~/.config/gtk-3.0/gtk.css */

/*run below code on terminal to reload gtk theme:
function reload_gtk_theme() {
  theme=$(gsettings get org.gnome.desktop.interface gtk-theme)
  gsettings set org.gnome.desktop.interface gtk-theme ''
  sleep 1
  gsettings set org.gnome.desktop.interface gtk-theme $theme
}
reload_gtk_theme
*/


/*
https://askubuntu.com/questions/221291/remove-ugly-fat-bazel-from-gnome-terminal-with-multiple-tabs
https://www.preining.info/blog/2020/03/de-uglify-gtk3-tabs-of-terminals/

https://bbs.archlinux.org/viewtopic.php?id=221876
https://wiki.archlinux.org/title/Terminator#GTK.2B_customization
*/

.terminator-terminal-window notebook tab {
  min-height: 0;
  padding: 0px;
  margin: 0px;
  font-size: 14px;
  font-weight: 800;
}

.terminator-terminal-window notebook tab button {
  min-height: 0;
  min-width: 0;
  padding: 0px;
  margin: 0px;
}


/* 
below code is the full defination of th keybinding of emacs style, instead of 
@import url("file:///usr/share/themes/Emacs/gtk-3.0/gtk-keys.css"); 
we should `rm /usr/share/themes/Emacs/gtk-3.0/gtk-keys.css` first. 
*/


/* A keybinding set implementing Emacs-like keybindings */

/* Bindings for GtkTextView and GtkEntry */
@binding-set gtk-emacs-text-entry
{
  bind "<ctrl>b" { "move-cursor" (logical-positions, -1, 0) };
  bind "<shift><ctrl>b" { "move-cursor" (logical-positions, -1, 1) };
  bind "<ctrl>f" { "move-cursor" (logical-positions, 1, 0) };
  bind "<shift><ctrl>f" { "move-cursor" (logical-positions, 1, 1) };

  bind "<alt>b" { "move-cursor" (words, -1, 0) };
  bind "<shift><alt>b" { "move-cursor" (words, -1, 1) };
  bind "<ctrl><alt><shift>b" { "move-cursor" (words, -1, 1) };

  bind "<alt>f" { "move-cursor" (words, 1, 0) };
  bind "<shift><alt>f" { "move-cursor" (words, 1, 1) };
  bind "<ctrl><alt><shift>f" { "move-cursor" (words, 1, 1) };

  bind "<ctrl>a" { "move-cursor" (paragraph-ends, -1, 0) };
  bind "<shift><ctrl>a" { "move-cursor" (paragraph-ends, -1, 1) };
  bind "<ctrl>e" { "move-cursor" (paragraph-ends, 1, 0) };
  bind "<shift><ctrl>e" { "move-cursor" (paragraph-ends, 1, 1) };


  bind "<ctrl>w" { "cut-clipboard" () };
  bind "<alt>w" { "copy-clipboard" () };
  bind "<ctrl>y" { "paste-clipboard" () };

  bind "<ctrl><alt>w" { "cut-clipboard" () };
  bind "<ctrl><alt><shift>w" { "cut-clipboard" () };

  bind "<alt>x" { "cut-clipboard" () };
  bind "<alt>c" { "copy-clipboard" () };
  bind "<alt>v" { "paste-clipboard" () };


  bind "<ctrl>d" { "delete-from-cursor" (chars, 1) };
  bind "<alt>d" { "delete-from-cursor" (word-ends, 1) };
  bind "<ctrl>k" { "delete-from-cursor" (paragraph-ends, 1) };
  bind "<alt>k" { "delete-from-cursor" (paragraph-ends, 1) };
  bind "<alt>backslash" { "delete-from-cursor" (whitespace, 1) };

  
  bind "<alt>space" { "delete-from-cursor" (whitespace, 1)
                      "insert-at-cursor" (" ") };
  bind "<alt><shift>space" { "delete-from-cursor" (whitespace, 1)
                             "insert-at-cursor" (" ") };
  bind "<ctrl><alt>space" { "delete-from-cursor" (whitespace, 1)
                      "insert-at-cursor" (" ") };

  bind "<alt>KP_Space" { "delete-from-cursor" (whitespace, 1)
                         "insert-at-cursor" (" ")  };
  bind "<alt><shft>KP_Space" { "delete-from-cursor" (whitespace, 1)
                               "insert-at-cursor" (" ")  };
  bind "<ctrl><alt>KP_Space" { "delete-from-cursor" (whitespace, 1)
                         "insert-at-cursor" (" ")  };
  
  /*
   * Some non-Emacs keybindings people are attached to
   */
  bind "<ctrl>u" { "move-cursor" (paragraph-ends, -1, 0)
                   "delete-from-cursor" (paragraph-ends, 1) };

  bind "<ctrl>h" { "delete-from-cursor" (chars, -1) };
  bind "<alt>h" { "delete-from-cursor" (word-ends, -1) };
  bind "<ctrl><alt>h" { "delete-from-cursor" (word-ends, -1) };

  /* bind "<ctrl>w" { "delete-from-cursor" (word-ends, -1) }; */

  bind "<alt>BackSpace" { "delete-from-cursor" (word-ends, -1) };
  bind "<ctrl><alt>backspace" { "delete-from-cursor" (word-ends, -1) };
}

/* Bindings for GtkTextView */
@binding-set gtk-emacs-text-view
{
  bind "<ctrl>p" { "move-cursor" (display-lines, -1, 0) };
  bind "<shift><ctrl>p" { "move-cursor" (display-lines, -1, 1) };
  bind "<ctrl>n" { "move-cursor" (display-lines, 1, 0) };
  bind "<shift><ctrl>n" { "move-cursor" (display-lines, 1, 1) };

  bind "<alt>p" { "move-cursor" (display-lines, -1, 0) };
  bind "<shift><alt>p" { "move-cursor" (display-lines, -1, 1) };
  bind "<alt>n" { "move-cursor" (display-lines, 1, 0) };
  bind "<shift><alt>n" { "move-cursor" (display-lines, 1, 1) };

  bind "<ctrl>space" { "set-anchor" () };
  bind "<ctrl>KP_Space" { "set-anchor" () };
}

/*
 * Bindings for GtkTreeView
 */
@binding-set gtk-emacs-tree-view
{
  bind "<ctrl>s" { "start-interactive-search" () };
  bind "<ctrl><alt><shift>s" { "start-interactive-search" () };
  bind "<ctrl>f" { "move-cursor" (logical-positions, 1) };
  bind "<ctrl>b" { "move-cursor" (logical-positions, -1) };
}

/*
 * Bindings for menus
 */
@binding-set gtk-emacs-menu
{
  bind "<ctrl>n" { "move-current" (next) };
  bind "<ctrl>p" { "move-current" (prev) };
  bind "<ctrl>f" { "move-current" (child) };
  bind "<ctrl>b" { "move-current" (parent) };

  bind "<alt>n" { "move-current" (next) };
  bind "<alt>p" { "move-current" (prev) };
  bind "<alt>f" { "move-current" (child) };
  bind "<alt>b" { "move-current" (parent) };
}

entry {
  -gtk-key-bindings: gtk-emacs-text-entry, gtk-emacs-text-view;
}

textview {
  -gtk-key-bindings: gtk-emacs-text-entry, gtk-emacs-text-view;
}

treeview {
  -gtk-key-bindings: gtk-emacs-tree-view;
}

GtkMenuShell {
  -gtk-key-bindings: gtk-emacs-menu;
}