Ubuntu 美化与终端配置

最近又需要用 Ubuntu 笔电作为主力开发机,于是又将系统配置了一遍。俗话说:“好看是第一生产力”,下面记录了我的主题、终端等工具的配置过程。

系统设置与美化

主题调整

原生的 Ubuntu 18.04 Gnome 界面的风格我个人不是非常喜欢,个人偏向于更加扁平的风格。以前在 Ubuntu 16.04 的时候,会使用 Flatabulous。但 Ubuntu 18.04 将默认的桌面环境从 Unity 换到了 GNOME,导致这个主题没法使用。好在有 Gnome Look 这个网站,上面有非常多的主题可供挑选。

首先我们需要安装 gnome-tweaks 工具:

1
sudo apt install gnome-tweaks

主题的话我目前用了 Mcata,一款仿 macOS Catalina 的主题。图标使用了非常精致好看的 Papirus 。鼠标指针采用了 McMojave cursors。这些主题的下载和使用也非常简单,对于主题只需下载后解压到 ~/.themes 目录下,图标和鼠标指针需解压到 ~/.icons 目录下,之后即可在 gnome-tweaks 工具中修改。

字体设置

系统字体使用 Google Noto 系列的字体,可以通过 apt 便捷的安装

1
sudo apt install fonts-noto

安装完成后即可在 gnome-tweaks 中将系统界面的字体设置为 Noto Sans Regular,需要中文显示支持就设置为思源黑体系列 Noto Sans CJK

编程等宽字体可以使用上面安装好的 Noto Sans Mono 系列,当然我个人用的是 Meslo Nerd Font 中的 MesloLGM NF,支持 Powerline 的符号显示。

添加中文支持

假如你的系统是英文版的话,如果有中文输入的需求,首先在设置中找到语言选项,添加中文为第二语言,之后再在输入法设置里面添加汉语拼音。

终端配置

安装 zsh

首先安装 zsh 并通过 chsh 命令将其设置为默认的 Shell 环境。zsh 是和 Bash 一样最流行的终端命令解释器,已经成为了 macOS 10.15 Catalina 中默认的 Shell 了。

1
2
3
4
5
6
7
8
# 安装 zsh
sudo apt install zsh

# 确认 zsh 成功安装
which zsh

# 设置为默认 Shell
chsh -s /usr/bin/zsh

安装 Oh My Zsh

Oh My Zsh 是一个开源的“开箱即用”的 zsh 配置管理框架,安装之后可以很方便的为 zsh 安装主题、插件等,一行命令即可安装:

1
sh -c "$(curl -fsSL https://raw.github.com/ohmyzsh/ohmyzsh/master/tools/install.sh)"

https://ohmyz.sh/img/themes/kolo.jpg

配置 Zsh 主题

安装好 zsh 之后,继续设置其主题为 Powerlevel10k

1
git clone --depth=1 https://github.com/romkatv/powerlevel10k.git ${ZSH_CUSTOM:-~/.oh-my-zsh/custom}/themes/powerlevel10k

接着在 ~/.zshrc 中设置 ZSH_THEME="powerlevel10k/powerlevel10k",重启 zsh 即可看见设置向导,按照提示可以选择自己喜欢的样式。

自动补全与语法高亮

Oh My Zsh 比较常用的两个插件是 zsh-autosuggestionszsh-syntax-highlighting

1
2
git clone https://github.com/zsh-users/zsh-autosuggestions ${ZSH_CUSTOM:-~/.oh-my-zsh/custom}/plugins/zsh-autosuggestions
git clone https://github.com/zsh-users/zsh-syntax-highlighting.git ${ZSH_CUSTOM:-~/.oh-my-zsh/custom}/plugins/zsh-syntax-highlighting

安装完成后在 ~/.zshrc 中设置 plugins=(git zsh-autosuggestions zsh-syntax-highlighting),重启终端后即可查看到效果。

配置颜色主题

Gnome 的 Terminal 可以在 Gogh 这个项目里找到合适的颜色主题,我选用了 OneDark

安装 Terminator

Terminator 是一个非常好用的终端管理软件,支持标签页以及像 tmux 一样分屏。如果需要开启多个终端、或者是连接多个远程服务器,Terminator 会是非常好用的工具。

1
sudo apt install terminator

编辑器配置

安装 Visual Studio Code

Visual Studio Code 官网下载安装 .deb 安装包,双击即可安装。VS Code 配合其丰富的插件,做到了开箱即用。同时在 Remote Development 的辅助下,能够便捷的在服务器、容器中进行开发。

安装 Vim

Ubuntu 是没有默认安装 Vim 的,因此需要手动安装

1
sudo apt install vim

安装完成后可以编辑 ~/.vimrc 文件来修改 Vim 的配置。还可以安装 vim-plug 给 Vim 添加插件支持

1
2
curl -fLo ~/.vim/autoload/plug.vim --create-dirs \
    https://raw.githubusercontent.com/junegunn/vim-plug/master/plug.vim

安装 NeoVim

如果没有管理员权限,或者需要更现代的编辑器体验,不妨试试 NeoVim

 1
 2
 3
 4
 5
 6
 7
 8
 9
10
11
12
13
14
15
16
17
18
# 下载 NeoVim
wget --quiet https://github.com/neovim/neovim/releases/download/nightly/nvim.appimage --output-document nvim

# 添加权限
chmod +x nvim

# 移动到系统路径
# 若没有权限,也可以直接添加到 PATH
sudo chown root:root nvim
sudo mv nvim /usr/bin

# 添加配置文件目录
# 配置文件将保存在 init.vim 中
mkdir -p ~/.config/nvim

# 安装 vim-plug
sh -c 'curl -fLo "${XDG_DATA_HOME:-$HOME/.local/share}"/nvim/site/autoload/plug.vim --create-dirs \
       https://raw.githubusercontent.com/junegunn/vim-plug/master/plug.vim'

配置 Vim / NeoVim

这个之后打算再写一篇文章。在线的 VimConfig 可以帮助简单的调整 Vim 的设置。下面贴上我的配置,仅供参考

  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
"++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++"
"                                                                              "
"                       __   _ _ _ __ ___  _ __ ___                            "
"                       \ \ / / | '_ ` _ \| '__/ __|                           "
"                        \ V /| | | | | | | | | (__                            "
"                         \_/ |_|_| |_| |_|_|  \___|                           "
"                                                                              "
"                                                                              "
"++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++"


set langmenu=en_US                          " set to English menu
let $LANG = 'en_US'

set nocompatible                            " use Vim

filetype on                                 " filetype
filetype plugin indent on

"=====================================================
""" Vim-plug settings
"=====================================================

call plug#begin('~/.vim/plugged')

Plug 'scrooloose/nerdtree'                  " nerdtree
Plug 'itchyny/lightline.vim'                " status bar

Plug 'tpope/vim-fugitive'                   " git plugin

Plug 'sheerun/vim-polyglot'                 " language support
Plug 'mhinz/vim-startify'                   " start screen

Plug 'joshdick/onedark.vim'                 " color schemes
"Plug 'flazz/vim-colorschemes'

"Plug 'neoclide/coc.nvim', {'branch': 'release'}

call plug#end()

"=====================================================
"" General settings
"=====================================================

syntax on                                   " syntax highlighting

set background=dark
colorscheme onedark                         " color scheme

set termguicolors
set cursorline

set encoding=utf-8                          " file encoding

set number                                  " show line numbers
set ruler
set ttyfast                                 " terminal acceleration

set tabstop=4                               " 4 whitespaces for tabs visual presentation
set shiftwidth=4                            " shift lines by 4 spaces
set smarttab                                " set tabs for a shifttabs logic
set expandtab                               " expand tabs into spaces
set autoindent smartindent                  " indent when moving to the next line while writing code

set showmatch                               " shows matching part of bracket pairs (), [], {}
set matchpairs+=<:>                         " highlight match pairs

set magic                                   " regular expression
set title                                   " display title

set nobackup 	                            " no backup files
set nowritebackup                           " only in case you don't want a backup file while editing
set noswapfile 	                            " no swap files

set backspace=indent,eol,start              " fix common backspace problems

set nowrap                                  " line wrap
set history=1000                            " history

set autoread                                " reload files when changed on disk, i.e. via `git checkout`
set shortmess=atI
set noshowmode
set showcmd

set selection=inclusive
set selectmode=mouse,key

set scrolloff=10                            " let 10 lines before/after cursor during scroll

set clipboard+=unnamed                      " use system clipboard
set laststatus=2

set exrc                                    " enable usage of additional .vimrc files from working directory
set secure                                  " prohibit .vimrc files to execute shell, create files, etc...

set pastetoggle=<C-p>                       " toggle paste mode

"=====================================================
"" Search settings
"=====================================================

set incsearch                               " incremental search
set hlsearch                                " highlight search results
set ignorecase                              " ignore search cases
set smartcase                               " unless there is capital

"=====================================================
"" Plugin settings
"=====================================================

let g:lightline = {
            \ 'colorscheme': 'onedark',
            \ }

" Some key remapping
map <C-n> :NERDTreeToggle<CR>

"=====================================================
"" Keybindings
"=====================================================

inoremap <C-a> <Home>
inoremap <C-e> <End>
inoremap <C-v> <ESC>"+pa

" Quick Esc 
inoremap jj <Esc>
inoremap jk <Esc>

" Easy window navigation
nnoremap <C-J> <C-W>j
nnoremap <C-K> <C-W>k
nnoremap <C-L> <C-W>l
nnoremap <C-H> <C-W>h

" Quick yanking to the end of the line
nnoremap Y y$

" Jump to matching pairs easily, with Tab
nnoremap <Tab> %
vnoremap <Tab> %

" Folding
nnoremap <Space> za
vnoremap <Space> za

" Map ; to : and save a million keystrokes
" ex mode commands made easy 用于快速进入命令行
nnoremap ; :

" Shift+H goto head of the line, Shift+L goto end of the line
nnoremap H ^
nnoremap L $

" Tab
nnoremap <C-Left> :tabprevious<CR>
nnoremap <C-Right> :tabnext<CR>

" Auto indent pasted text
"nnoremap p p=`]<C-o>
"nnoremap P P=`]<C-o>
加载评论