星期一, 六月 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<上一篇 | 目录 下一篇>