星期一, 六月 16, 2025

VIM学习笔记 工具箱-PDF查看器zathura

zathura是一款高度可定制的简约文档查看器,适用于大多数Linux发行版。zathura是由PWMT社区开发的开源软件,它有以下两大特点:

  • 以键盘为中心,使用vim习惯的键位绑定,类似vim的命令行模式,沉浸式的vim操作体验;
  • 以文档为中心,极简的用户界面将最大化的屏幕空间留给文档本身,提供更专注的阅读体验。

zathura提供以下主要特性:

  • 支持PDF、Djvu、PostScript、Comic Book等多种文件格式;
  • 支持书签(bookmark);
  • 类似vim的命令行/搜索行/状态栏;
  • 使用鼠标双击进行链接跳转;
  • 使用鼠标选择文本将自动拷贝至剪贴板;
  • 支持SyncTeX技术,允许输入和输出同步,便于编辑LaTex文档

安装

以Debian为例,使用以下命令安装zathura:

$ sudo apt install zathura zathura-pdf-poppler zathura-djvu zathura-ps

针对其它平台的安装,请参阅官方文档

使用

在操作系统命令行环境下,使用以下命令即可查看文件:

$ zathura filename.pdf

zathura main window

在默认阅读模式下,使用F11键切换至全屏幕模式;使用F5键切换至演示模式;使用Tab键切换至目录模式。

zathura mode index

配置

通过编辑~/.config/zathura/zathurarc配置文件,可以自定义系统选项:

# show status bar and vertical scrollbar
set guioptions sv
# allowing to change the colors
set recolor true
set recolor-lightcolor "#000000"
set recolor-darkcolor "#E0E0E0"
set recolor-keephue true
# zoom and scroll step size
set zoom-step 20
set scroll-step 80
# copy selection to system clipboardset
set selection-clipboard clipboard
# enable incremental search
set incremental-search true
# shortcut - zoom
map <C-i> zoom in
map <C-o> zoom out

更多配置选项,请参阅官方文档

快捷键

Document Navigation文档导航
J向下移动一行 Move the document display window one line down.
K向上移动一行 Move the document display window one line up.
L向右移动一列 Move the document display window one column to the right.
H向左移动一列 Move the document display window one column to the left.
Ctrl + D向下移动半页 Move the document display window half a page down.
Ctrl + U向上移动半页 Move the document display window half a page up.
Ctrl + Y向右移动半页 Move the document display window half a page to the right.
Ctrl + T向左移动半页 Move the document display window half a page to the left.
Ctrl + B向下移动一页 Move the document display window a full page down.
Ctrl + F向上移动一页 Move the document display window a full page up.
Y向右移动一页 Move the document display window a full page to the right.
T向左移动一页 Move the document display window a full page to the left.
GG移动到第一页 Go to the first page of the current document.
Shift + G移动到最后一页 Go to the last page of the current document.
5, then Shift + G移动到第5页 Go to the fifth page of the current document.
Shift + H移动到当前页首 Go to the top of the currently selected page.
Shift + L移动到当前页尾 Go to the bottom of the currently selected page.
/向前搜索 Open forward search prompt.
?向后搜索 Open reverse search prompt.
N移动到下一匹配处 Go to the next occurrence of the current search term.
Shift + N移动到上一匹配处 Go back to the previous occurrence of the current search term.
Interface Navigation界面导航
A适合窗口高度 Fit the height of the current page to the display window.
S适合窗口宽度 Fit the width of the current page to the display window.
R顺时针旋转90度 Rotate the current document by 90 degrees clockwise.
Ctrl + N显示/隐藏 状态栏 Toggle status bar.
+放大 Zoom in
-缩小 Zoom out
=恢复缩放比例 Revert the zoom level of the document at the currently selected page.
60 + =缩放至指定比例 Set the current zoom level of the document to 60%.
Ctrl + R反转显示颜色 Invert the colors.
Shift + R重画屏幕 Refresh and redraw.
F5演示模式 presentation mode.
F11全屏幕模式 fullscreen mode.
Q退出/结束当前进程 Terminate the current Zathura session.
Linking and Indexing链接和目录
Shift + F高亮显示链接 Show all link hints.
F跳转到指定链接 Load a link hint’s page to the document viewer.
C复制链接地址 Copy a link hint’s page to the system clipboard.
Tab进入目录模式 Display the document’s content index.
J下一目录项 Scroll one item down in the document’s content index.
K上一目录项 Scroll one item up in the document’s content index.
L展开当前目录 Display the current index item’s subitems.
H折叠当前目录 Hide the current index item’s subitems.
Shift + L展开所有目录 Display all the subitems in the document’s content index.
Shift + H折叠所有目录 Hide all the subitems in the document’s content index.
Enter跳转到目录指引的页 Load the page of the currently selected index entry.
Presentation Mode演示模式
Space下一页 Go to the next document slide.
Shift + Space上一页 Go back to the previous document slide.
F5退出演示模式 Go back to the default Zathura mode.
Fullscreen Mode全屏幕模式
Shift + J下一页 Move the document display window a full page down.
Shift + K上一页 Move the document display window a full page up.
ZI放大 Zoom in
ZO缩小 Zoom out
Z0恢复缩放 Reset the current zoom level.
60 + =缩放至指定比例 Set the zoom level of the document to 60%.
F11退出全屏幕模式 Go back to the default Zathura mode.
Command Mode命令模式
:进入命令行 Open Zathura’s command prompt.
:close关闭当前文档 Exit the current document without exiting Zathura.
:open {filename}打开指定文档 Open a new document on the current Zathura window.
:blist列示书签 List all the available bookmarks for the current session.
:bmark {name}新增书签 Add the current page to the session’s bookmark index.
:bjump {name}跳转至指定书签 Jump to a bookmark.
:bdelete {name}删除书签 Delete bookmark
:exec执行外部命令 Run an external shell command on the current document.
:info显示文档信息 Print the document’s internal properties.
:print打印文档 Send the current document to the machine’s print spool.

Ver: 25.06.10 | YYQ<上一篇 | 目录 下一篇>

星期六, 六月 07, 2025

VIM学习笔记 编译文档(Compiling Latex)

LaTeX是一种用于生成高印刷质量的科技和数学类文档的排版系统,可以生成包含复杂表格和数学公式的复杂文档。

LaTeX文档是一个以.tex扩展名的文本文件,可以使用任意文本编辑器(比如Vim)编辑;在编辑完成后,可以编译为更容易阅读的文档格式(比如PDF)。

TeX Live

TeX Live是一种免费的跨平台TeX文档制作系统。它包括所有与TeX相关的主要程序、宏包和字体,支持全球多种语言。许多Unix/GNU/Linux操作系统通过自己的包管理器提供TeX Live,但强烈推荐严格按照官方文档进行手动安装。(另:参考

在安装之后,增加以下PATH路径:

export PATH=$PATH:/usr/local/texlive/2025/bin/i386-linux
export INFOPATH=$INFOPATH:/usr/local/texlive/2025/texmf-dist/doc/info
export MANPATH=$MANPATH:/usr/local/texlive/2025/texmf-dist/doc/man

同理,使用以下命令为sudo增加安全路径:

$ sudo visudo

Defaults secure_path="/usr/local/sbin:/usr/local/bin:/usr/sbin:/usr/bin:/sbin:/bin:/usr/local/texlive/2025/bin/i386-linux"

使用tlmgr更新Tex Live系统以及安装的Packages:

$ sudo tlmgr update --self

$ sudo tlmgr update --all

如果在使用过程中,仍然出现类似以下缺失包的报错信息:

! LaTeX Error: File `gb4e.sty' not found.

那么可以使用以下命令,手动安装缺失的包:

$ sudo tlmgr install gb4e

编辑Latex文档

Vim内置了Latex语法高亮度,可以很方便地编辑文档。

Latex-Syntax

编译Latex文档

在Vim命令行中执行pdfTeX命令,可以将Latex源文件编译为更容易阅读的PDF文件:

:!pdflatex sample.tex

默认情况下,将显示类似以下输出信息,并等待用户按回车键以返回到Vim:

Output written on sample.pdf (1 page, 66919 bytes).
Transcript written on sample.log.
Press ENTER or type command to continue

查看Latex输出文档

命令执行成功后,将在同一目录下,生成一个同名的PDF文件。同时还会生成一些辅助文件,如sample.log,其中包含有关编译过程的详细信息。

使用以下命令,启动PDF查看器验证生成的输出结果:

:zathura sample.pdf

Latex-View-PDF

自动化Latex编译和输出

在vimrc启动文件中自定义以下命令:

:command Latex execute "silent !pdflatex % > /dev/null && zathura %:r.pdf > /dev/null 2>&1 &" | redraw!

  • silent,将避免显示诸如 “Press ENTER to continue” 等命令执行过程中的提示信息;
  • pdlatex,将编译当前文件, % > 将标准输出重定向到/dev/null而不是显示在屏幕上;
  • zathura,用于查看生成的PDF文件,即以%:r指定的当前文件名,以.pdf指定的后缀扩展名;
  • redraw,重画屏幕,以保证正常显示;

在命令行中执行以下自定义命令,将自动化使用pdflatex来编译文档,并使用Zathura来显示生成的PDF文件:

:Latex

您也可以在vimrc启动文件中自定义以下快捷键:

:map <F2> :Latex <CR>

Ver: 25.06.07 | YYQ<上一篇 | 目录 下一篇>

星期二, 四月 29, 2025

VIM学习笔记 使用Git Bash Shell环境

Git Bash是将Git版本控制系统和Bash Shell集成至单一界面的工具,允许用户在Windows系统的命令行环境中使用Git命令,为熟悉Linux系统的开发人员提供无缝体验;同时还能利用Bash强大的脚本和命令行功能。

集成Git Bash和ConEmu

如果您已经安装了GitConEmu,那么通过以下配置将可以在虚拟终端和Vim中调用Git Bash。

在ConEmu中,点击Win+Alt+P快捷键以打开设置对话框。

Git Bash

  1. 在侧边栏中,选择Startup下的Tasks
  2. 点击+按钮,新增项目;
  3. 输入"Bash::git bash"作为项目名称;
  4. Task Parameters编辑框中,指定启动目录和图标文件:
    /single /Dir "C:\" /icon "C:\Program Files\Git\mingw64\share\git\git-for-windows.ico"
  5. Commands编辑框中,指定Git Bash命令:
    "%ProgramFiles%\Git\bin\sh.exe" --login -i
  6. 点击Save Settings按钮,保存设置。

在ConEmu中,选择新建Git Bash终端窗口:

New Console

您可以在命令行环境下管理Git库:

Command

除了Git命令,Git Bash也提供一系列Linux经典命令工具,您可以使用$ help命令列出命令列表:

Help

配置Vim使用Git Bash

通过以下命令,可以查询到Vim在Windows下,默认使用命令提示符 "Command Prompt":

:set shell?

shell=C:\WINDOWS\system32\cmd.exe

vimrc配置文件中设置以下函数:

fun! ShellGitBash()
	let $CHERE_INVOKING=1
	set shell=C:\PROGRA~1\Git\bin\sh.exe
	set shellcmdflag=--login\ -c
	set shellxquote=\"
	set shellslash
	let $PATH .= ';C:\PROGRA~1\Git\bin'
endfun

通过以下命令,则可切换至Git Bash的Shell环境:

:call ShellGitBash()

在Vim中使用:terminal命令,即可打开Git Bash终端窗口:

terminal

你也可以在Vim命令行模式下,使用:!:shell命令,来执行bash命令

Ver 25.04.28  | YYQ<上一篇 | 目录 下一篇>

VIM学习笔记 插件管理器(minpac)

Vim8引入了内置的packages软件包功能。而minpac则是构建于packages软件包功能之上的轻量化插件管理器。

安装配置

首先在操作系统中,为minpac创建安装目录:

  • Linux:
    $ mkdir -p ~/.vim/pack/minpac/opt
  • Windows:
    $ mkdir -p ~/vimfiles/pack/minpac/opt

使用以下命令,将minpac作为手动载入的插件,安装在opt目录中:

$ cd ~/vimfiles/pack/minpac/opt
$ git clone https://github.com/k-takata/minpac.git

在vimrc配置文件中,添加以下命令:

packadd minpac
call minpac#init()

安装插件

minpac支持源码托管在GitHub的插件,你可以在github.com/vim-scripts/上找到vim官网里所有插件的镜像,也可以直接引用github.com的网址。

如果希望安装新插件,可以在vimrc配置文件中,添加以下minpac#add()命令:

call minpac#add('lilydjwg/colorizer')
call minpac#add('kshenoy/vim-signature')
call minpac#add('yyq123/HTML-Editor')

默认情况下,插件将被作为自动载入插件安装至start目录。

通过在函数中指定'type': 'opt'选项,将minpac自身作为手动载入插件进行注册。

call minpac#add('k-takata/minpac', {'type':'opt'})

然后使用以下命令,重新载入vimrc配置文件,并安装插件:

:source ~/.vimrc
:call minpac#update()

安装的插件将存放在pack子目录中,目录结构如下:

Directory

卸载插件

如果希望卸载插件,请先在vimrc文件中删除相关call minpac#add('')命令;然后重新载入vimrc文件,并执行以下命令:

:call minpac#clean()

更新插件

建议在vimrc文件中,增加以下命令映射以便于后续操作:

" minpac commands:
" 安装和更新插件
command! PackUpdate call minpac#update()
" 卸载插件
command! PackClean call minpac#clean()
" 查看插件状态
command! PackStatus call minpac#status()

然后就可以使用以下命令,批量更新所有已安装的插件:

:PackUpdate

帮助信息

使用以下命令,可以查看minpac的帮助信息:

:help minpac

Ver 25.4.22 | YYQ<上一篇 | 目录 下一篇>

星期日, 四月 20, 2025

VIM学习笔记 软件包(packages)

Vim8引入了内置的packages软件包功能。Vim软件包将创建一个或多个目录,用于安装和更新插件。和普通插件管理器相比,它主要有以下优点:

  • 软件包可作为归档下载,并可解压到单独的目录。这样文件就不会和其它插件的文件混杂。也方便后续更新和删除。
  • 软件包可以使用git等版本库进行更新。
  • 软件包可包含相互依赖的多个插件。
  • 软件包可包含启动时自动载入的插件和通过:packadd手动载入的插件。

任何位于~/.vim/pack之下的目录,都将被视为软件包。一个软件包,可以将插件存储在startopt子目录中:

  • ~/.vim/pack/*/start/{name}
    存储自动载入的插件
  • ~/.vim/pack/*/opt/{name}
    存储通过:packadd {name}命令手动载入的插件

其中,*可以为任意名称。

例如使用以下命令,创建以“plugins”命名的目录结构:

mkdir -p ~/.vim/pack/plugins/start

mkdir -p ~/.vim/pack/plugins/opt

安装配置

可以clone或者使用子模块(Submodules)功能,将git库同步到本地软件包目录。这也意味着,您可以在Git库里集中管理.vimrc配置文件和.vim目录结构,并同步到不同的计算机里。

Git子模块允许你将一个Git仓库作为另一个Git仓库的子目录。 它能让你将另一个仓库克隆到自己的项目中,同时还保持提交的独立。

pack目录创建git库:

cd ~/.vim/pack
git init
git add *
git commit -m "Initial commit"
git submodule init
git remote add origin https://github.com/username/reponame.git
git push -u origin master

目录结构如下,之后安装的插件将存放在~/.vim/pack子目录中:

packages Directory

安装插件

软件包支持源码托管在GitHub的插件,你可以在github.com/vim-scripts/上找到vim官网里所有插件的镜像,也可以直接引用github.com的网址。

如果希望安装新插件,可以执行以下命令安装指定的插件:

$ git submodule add https://github.com/chrisbra/unicode.vim plugins/start/unicode

packages-git-submodule-add

然后使用以下命令,来提交变更:

$ git commit -m "Added submodules"
$ git push origin master

使用以下命令,可以安装用于演示Vim8.2新功能的killersheep小游戏。

$ git submodule add https://github.com/vim/killersheep plugins/opt/killersheep
$ git commit -m "Added killersheep"
$ git push origin master

使用以下命令,手动载入插件:

:packadd killersheep

使用以下命令,启动游戏:

:Kill

packages-killersheep

卸载插件

如果希望卸载插件,请先执行以下命令来移除git submodule:

git submodule deinit -f -- ~/.vim/pack/plugins/opt/killersheep

然后使用以下命令,删除插件文件目录:

rm -rf ~/.vim/pack/plugins/opt/killersheep

最后使用以下命令,从远处Git库中删除插件:

git rm -rf ~/.vim/pack/plugins/opt/

更新插件

使用以下命令,可以更新指定插件'unicode':

$ cd ~/.vim/pack/plugins/start/unicode
$ git submodule update --remote --merge

使用以下命令,可以批量更新所有已安装的插件:

$ cd ~/.vim/pack
$ git submodule foreach git pull origin master

请注意,如果有任何插件更新,请使用以下命令提交更新至Git repository:

$ cd ~/.vim/pack
$ git commit -am "Updated plugins."

帮助信息

使用以下命令,可以查看packages的帮助信息:

:help packages

请注意,对于Vim内置的软件包功能:

  • 仅仅负责载入插件,而需要用户自行下载、安装和更新插件,用户友好度欠佳;
  • 调用git的clone和submodule,对于普通用户的门槛过高;
  • 需要自行生成帮助文档(Help tags),例如以下命令将生成指定目录下的帮助文档:
    :helptags ~/.vim/pack/plugins/start/reponame
    而以下命令则将生成所有帮助文档:
    :helptags ALL

如果您同时使用多台电脑,那么结合packages和git功能即可以实现插件配置的同步。当然,这过程中牵扯了诸多手工操作和git知识,平衡取舍还请各位自行斟酌。

$ git clone https://github.com/username/reponame.git ~/.vim
$ cd ~/.vim
$ git submodule update --init
$ git commit -am "Updated plugins."
$ git submodule foreach git pull origin master
$ git add .
$ git commit -m "update submodules"
命令小结
:packadd>安装插件

Ver 25.4.20 | YYQ<上一篇 | 目录 下一篇>