我正在运行一个监听键盘按下的脚本,这样每当我按下“t”键时,一个新的终端窗口就会打开,并且 nvim 进程已经在运行。我通过以下方式做到这一点:
# open_vim is called when the t key is pressed
def open_vim(self, compile_latex):
f = tempfile.NamedTemporaryFile(mode='w+', delete=False, suffix='.tex')
f.write('$$')
f.close()
config['open_editor'](f.name)
[more code ...]
其中 open_editor 是一个函数所以预期的行为是当按下 t 键时,运行 open_vim,创建一个具有写权限的临时文件 f,并在文件中写入“$$”。接下来,将打开一个新的终端窗口,其中 nvim 打开已经存在的文件(请注意,f.name 类似于 /tmp/tmpfilename.tex)。但是 nvim 打开一个与 f 同名的文件,但将其视为新文件,即它是一个空文件。
最奇怪的是,如果我运行我单独提到的代码块
(open_vim)
,它会按预期运行。但是,如果我在 open_editor 函数中运行它,我会通过使用 config.['open_editor'](f.name)
延迟执行 time.sleep()
来观察到以下行为:创建 tmp 文件,如果我进入 /tmp
并在其上使用 cat 我可以看到它的内容是 $$。但是一旦执行 open_editor,文件就会从/tmp
中消失。所以我倾向于认为 nvim 会以某种方式删除文件并在其上创建一个新文件,但我知道这不太可能。
另一件事是如果我将
open_editor
更改为:
def open_editor(filename):
subprocess.run([
'urxvt',
'-geometry', '60x5',
'-name', 'popup-bottom-center',
'-e', "vim",
f"{filename}",
])
也就是说,我将 tty 更改为 urxvt,它按
open_vim
中的预期工作。
我正在使用带有 zsh shell 和 NVIM 版本的 Ubuntu 22.04 v0.10.0-dev
在 config.py 中定义
def open_editor(filename):
subprocess.run([
'gnome-terminal',
'--geometry', '60x5',
'--name', 'popup-bottom-center',
'--', "nvim",
f"{filename}",
])
所以预期的行为是当按下 t 键时,运行 open_vim,创建一个具有写权限的临时文件 f,并在文件中写入“$$”。接下来,将打开一个新的终端窗口,其中 nvim 打开已经存在的文件(请注意,f.name 类似于 /tmp/tmpfilename.tex)。但是 nvim 打开一个与 f 同名的文件,但将其视为新文件,即它是一个空文件。
最奇怪的是,如果我运行我单独提到的代码块
(open_vim)
,它会按预期运行。但是,如果我在 open_editor 函数中运行它,我会通过使用 config.['open_editor'](f.name)
延迟执行 time.sleep()
来观察到以下行为:创建 tmp 文件,如果我 cd 到 /tmp
并在其上使用 cat 我可以看到它的内容是 $$。但是一旦执行 open_editor,文件就会从/tmp
中消失。所以我倾向于认为 nvim 会以某种方式删除文件并在其上创建一个新文件,但我知道这不太可能。
另一件事是如果我将
open_editor
更改为:
def open_editor(filename):
subprocess.run([
'urxvt',
'-geometry', '60x5',
'-name', 'popup-bottom-center',
'-e', "vim",
f"{filename}",
])
也就是说,我将 tty 更改为 urxvt,它按
open_vim
中的预期工作。
我正在使用带有 zsh shell 和 NVIM 版本的 Ubuntu 22.04 v0.10.0-dev