BNU-FZH

fengzhenhua@outlook.com

在使用vim或neovim编辑文件时,需要经常在插入模式和编辑模式来回切换,之前已经记录了方法,但本文作为一个正式的版本记录一下,并随ArchLinux的更新相应改变。

源自Fcitx5-ArchWiki的方法

1
2
3
let fcitx5state=system("fcitx5-remote")
autocmd InsertLeave * :silent let fcitx5state=system("fcitx5-remote")[0] | silent !fcitx5-remote -c
autocmd InsertEnter * :silent if fcitx5state == 2 | call system("fcitx5-remote -o") | endif

注意:vim将上述代码添加到~/.vimrc, neovim将上述代码添加到~/.config/nvim/init.vim

使用插件fcitx.vim

由于不同的插件管理器多少有差异,此处不记录详细配置,请将lilydjwg/fcitx.vim放入到配置文件对应位置即可。插件和官方的脚本区别在于:

ArchLinux官方脚本可以实现在一个文件中输入法的切换,即按Esc后切换为英文输入法,再切换到插入模式后Fcitx5自动切换为刚才输入时的输入法。这个功能基本满足大家的要求。插件fcitx.vim的优势在于可以记录不同文件的输入法状态,例如有两个文件A和B, 编辑文件A时插入模式使用中文输入,编辑文件B时插入模式使用英文输入,在A或B按Esc后统一转换成了英文输入法,但是在A文件中插入时Fcitx5就切换到中文输入法,在B文件中插入时Fcitx5就切换到英文输入法。

由于ArchLinux脚本仅是一段简单代码,基本上不占用启动时间,所以vim或nvim都启动的很快,而插件fcitx.vim虽然功能强大,但是需要借助于python3python-dbus,所以启动会慢一些,使用Lazy插件管理器,在nvim启动时发现插件fcitx.vim占用了90ms左右的时间,它是所有插件中占用时间最多的,其他的插件最多也就几秒.

由于同时编辑两种文本一个为中文另一个为英文的概率很小,从性能和实现简易程度上讲优先考虑使用Fcitx5-ArchWiki所提供的脚本,如果您在工作中经常处理多个文件,且这多个文件分别使用不同语言,需要分别记录不同的输入状态,那请使用插件fcitx.vim.

Keep and restore fcitx state for each buffer separately when leaving/re-entering insert mode or search mode. Like always typing English in normal mode, but Chinese in insert mode.

D-Bus only works with the same user so this won't work with sudo vim. See the fcitx5-server branch for an experimental implementation that supports sudo vim.

By default, it use python3 and D-Bus to toggle IME state. If you set g:fcitx5_remote to the executable path of fcitx5-remote BEFORE loading the plugin, it will use fcitx5-remote instead of python and D-Bus. In this case, python3 support is optional.

Usually fcitx5-remote mode is way faster to start up since Python script need quite some time for the initial load if you don't use any other plugins that load Python. The Python version will be faster while switching.

Base requirements:

  • fcitx 5

Requirements for Python mode (g:fcitx5_remote is not set):

  • Vim with Python 3 compiled in
  • The python-dbus package

Requirements for fcitx5-remote mode (g:fcitx5_remote is set):

  • fcitx5-remote

If you are using fcitx5-rime (which has its own state), let g:fcitx5_rime = 1 in your .vimrc.

The FcitxCurrentIM() function can be used to get current IM's name.

Links:

Warning:

  1. If you use Vim in terminal, to avoid the Esc delay, please set 'ttimeoutlen' to 100 or some other value. And check screen's maptimeout or tmux's escape-time option if you use it too.

在离开或重新进入插入模式或搜索模式时自动记录和恢复每个缓冲区各自的输入法状态,以便在普通模式下始终是英文输入模式,切换回插入模式时恢复离开前的输入法输入模式。

D-Bus 只在同一用户时有效,所以使用 sudo vim 时本代码就失效了。在 fcitx5-server 分支有一个实验性的版本支持 sudo vim 的用法。

本插件默认会使用 Python 3 并通过 D-Bus 来切换输入法状态。 但如果你在加载插件之前设置了 g:fcitx5_remote 为你已安装的 fcitx5-remote 可执行文件的路径,那么本插件会使用它来切换输入法状态;此模式下本插件并不需要 Python。

如果你没有其他使用 Python 的 Vim 插件,本插件的 Python 模式初始化可能会显著拖慢启动时间;而 fcitx5-remote 模式则没有这个问题。Python 模式会在切换时更快。

基本要求:

  • fcitx 5

使用 Python 模式的要求(未设置 g:fcitx5_remote):

  • 带有 Python 3 支持的 Vim
  • python-dbus 包

使用 fcitx5-remote 模式的要求(需设置 g:fcitx5_remote):

  • fcitx5-remote

如果使用 fcitx5-rime(它自己有输入状态),在 .vimrc 中设置 let g:fcitx5_rime = 1

FcitxCurrentIM() 函数可以用于获取当前输入法的名字。

链接:

注意事项:

  1. 终端下请设置 Vim 'ttimeoutlen' 选项为较小值(如100),否则退出插入模式时会有较严重的延迟。同样会造成延迟的还有 screen 的 maptimeout 选项以及 tmux 的 escape-time 选项。
  2. 请在 fcitx5-configtool 中确认英语是第一个输入法,中文是第二个输入法,rime 用户可能需要设置 g:fcitx5_rime = 1

其他插件替代方案

注意:由于这些插件我并没有一一测试,所以请大家自行决定如何选择使用。

今天本想解决Neovim自动化配置脚本编写问题,意外得知Packer已经不再维护,其官方仓库packer.nvim 写到:

This repository is currently unmaintained. For the time being (as of August, 2023), it is recommended to use one of the following plugin managers instead:

  • lazy.nvim: Most stable and maintained plugin manager for Nvim.
  • pckr.nvim: Spiritual successor of packer.nvim. Functional but not as stable as lazy.nvim.
阅读全文 »

vim-templates是一款相当好用的vim插件,同时支持neovim, 当使用vimneovim建立文件时,此插件会导入预先设置模板,这大大提高了工作效率。虽然默认配置了好多的模板,但都是一些通用模板,于是就需要自己定义模板,在定义模板的过程中一些变量的引用是重要的内容。本文从官方网站: tibabit/vim-templatesREADME.md文件中截取相关变量部分,以方便编写模板之用。同时也可以在安装插件后,使用命令::help template.txt调出使用细节。

Customization

Creating your own templates

  • Create a file <template_name>.template inside a folder which is searched by the plugin( see below), e.g. if you want to create a template file for a c++ main file you can name it cppmain.template or cppm.template
  • Open the file and edit, for example
阅读全文 »

在创建备份文件时,有些文件需要加密保存,这时使用命令加密文件就显得必不可少,当使用的时候运行脚本过程再解压,但是要求输入密码,而密码是掌握在作者手中的,所以确保了隐私安全。

使用ZIP压缩和解压

  1. 命令中直接输入密码

    1
    zip -rP yourpassword package.zip package

  2. 交互分步输入密码

    1
    zip -re package.zip package

  3. ZIP解压缩

    1
    unzip package.zip 

使用TAR压缩和解压

  1. TAR加密压缩

    1
    tar -zcvf - ./package | openssl des3 -salt -k yourpassword | dd of=meiyou.tar.gz

  2. TAR解压缩

    1
    dd if=meiyou.tar.gz | openssl des3 -d -k yourpassword |tar zxf -

Zsh(Z-shell)是一款用于交互式使用的shell,也可以作为脚本解释器来使用。它包含了bash,ksh,tcsh等其他shell中许多优秀功能,也拥有诸多自身特色。

zsh有一款语法高亮插件zsh-syntax-highlighting, 它可以为zsh添加色彩高亮,是一款必备插件,但是今天我又发现一款比它更优秀的插件fast-syntax-highlighting, 其自带有多款高亮主题,且可以自由切换。

安装插件

fast-syntax-highlighting
1
paru -S fast-syntax-highlighting-git

启用插件

~/.zshrc
1
2
# source /usr/share/zsh/plugins/zsh-syntax-highlighting/zsh-syntax-highlighting.zsh
source /usr/share/zsh/plugins/fast-syntax-highlighting/fast-syntax-highlighting.plugin.zsh

配置插件

  • 列出可用的主题

    1
    fast-theme -l

  • 切换主题

    1
    fast-theme -t theme-name

插件zsh-syntax-highlightingfast-syntax-highlighting可以同时安装,并不冲突,但是在.zshrc配置文件中应当选择其中一个.

在写博客的时候需要引用一些网络文章,但是发现每次复制Firefox地址栏的链接时都会被自动编码, 于是当链接中包含中文时就会乱码。虽然粘贴到博客中一样使用,但是不方便识别。解决方法为:Firefox地址栏输入about:config 打开浏览器参数配置界面,提示小心之类的确定。

  • 老版本搜索: network.standard-url.escape-utf8 配置为
  • 新版本搜索: browser.urlbar.decodeURLsOnCopy 配置为

在Linux下打开或解压从Windows系统拷贝的zip文件,中文部分乱码,这个问题的根本原因是,windows下默认gb2312与linux中默认utf-8不兼容。

Ark 是KDE默认的解压缩软件,出现乱码的直接原因是Ark中用于zip打开和解压的插件不支持gb2312, 解决方案为:

  1. 安装p7zip-natspec(cn源里面有此软件)

    1
    2
    sudo pacman -S ark
    sudo pacman -S p7zip-natspec unarchiver lzop lrzip arj

  2. 在Ark中禁用libzip插件(该插件优先级高于p7zip): Ark菜单→设置→配置Ark→插件→取消Libzip插件对应的复选框→应用。同时应当确保p7zip插件使用中。

  3. 其他选择,使用unzip-natspecunzip-iconv.

  1. 安装p7zip-natspec(cn源里面有此软件)

    1
    2
    sudo pacman -S file-roller
    sudo pacman -S p7zip-natspec unarchiver lzop lrzip arj

  2. 在环境变量中,指定unzip参数,总是以指定的字符集显示和解压文件, 即在/etc/environment中加入

    /etc/environment
    1
    2
    UNZIP="-O CP936"
    ZIPINFO="-O CP936"

这样Gnome桌面的归档文件管理器(file-roller)可以正常使用unzip解压中文,但是file-roller本身并不能设置编码传递给unzip。

如果您习惯于使用命令,由于已经安装了unarchiver, 所以直接使用命令unar解压zip文件也是可以解决文件名乱码问题的,这在所有Linux中都是一个通用的方案。

2023-12-27 在安装完新系统后配置中文环境时,根据Locale-ArchWiki的描述,对于KDE Plasma 则删除 后发现各项翻译包括SDDM增均顺利转换成了英文。如果SDDM没有转成中文,请再按下述方法配置。


新配置的ArchLinux解决完一些重要的问题后,还剩下SDDM的语言一直显示为英文,需要将语言修改为中文。方法为: 修改文件/usr/lib/systemd/system/sddm.service, 在[Service]下添加Environment=LANG=zh_CN.UTF-8, 即

/usr/lib/systemd/system/sddm.service
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
[Unit]
Description=Simple Desktop Display Manager
Documentation=man:sddm(1) man:sddm.conf(5)
Conflicts=getty@tty1.service
After=systemd-user-sessions.service getty@tty1.service plymouth-quit.service systemd-logind.service
PartOf=graphical.target
StartLimitIntervalSec=30
StartLimitBurst=2

[Service]
ExecStart=/usr/bin/sddm
Restart=always
Environment=LANG=zh_CN.UTF-8

[Install]
Alias=display-manager.service

注意:按ArchLinuxWiki简体中文本地化,不推荐在/etc/locale.conf里把全局的LANG locale设置成中文LANG=zh_CN.UTF-8,因为TTY下没有CJK字体,这样设置会导致TTY中显示豆腐块(除非你使用的内核打了cjktty补丁能绘制中文字体,比如linux-lilyCNRepo)。

ArchLinux执行更新时,如果内核有更新则会出现如下警告:

While doing a 'sudo pacman -Syu' pacman warns
1
2
3
==> WARNING: Possibly missing firmware for module: wd719x
==> WARNING: Possibly missing firmware for module: aic94xx
==> WARNING: Possibly missing firmware for module: xhci_pci

解决方法安装mkinitcpio-firmware

1
paru --skipreview -S mkinitcpio-firmware

or

1
paru --skipreview -S wd719x-firmware aic94xx-firmware upd72020x-fw

查看警告是否消失

1
sudo mkinitcpio -p linux

还有一个warning是关于consolefont的,根据arch社区的回答,把/etc/mkinitcpio.conf文件中的HOOKS中的consolefont删掉就行。 参考文章: