简体   繁体   English

vim中是否有类似于“ nano -R”的选项

[英]Is there any option in vim similar to “nano -R”

nano editor has restricted mode "-R" to open a file where no other files can be opened from the editor and the user can modify only that specific file. nano编辑器具有受限模式“ -R”来打开文件,在该文件中无法从编辑器打开其他文件,并且用户只能修改该特定文件。 Is there any option similar to that in vim editor where the user will not be able to use ":edit" option and open some other file and modify it. 有没有类似于vim编辑器中的选项,用户将无法使用“:edit”选项并打开其他文件并对其进行修改。

The vim restricted mode option "vim -Z" restricts the editor to use the shell commands. vim受限模式选项“ vim -Z”限制编辑器使用shell命令。 But I need an option to restrict open any other file apart from the specified one. 但是我需要一个选项来限制打开除指定文件之外的任何其他文件。

No, there isn't such option, and it would probably be difficult to add (and mess up the source code quite a bit), because there are so many commands that potentially can open / write to different files. 不,没有这样的选项,并且可能很难添加(并使源代码混乱很多),因为有太多的命令可能会打开/写入不同的文件。

If you need this, I would recommend to rely on the underlying operating system's means for protection, and do something like sudoedit : 如果需要,建议使用底层操作系统的方法进行保护,并执行sudoedit

Write a wrapper script that temporarily copies the file to a temporary location, and then invoke Vim with a restricted user that ideally can only access that single file. 编写一个包装脚本,将文件临时复制到一个临时位置,然后以理想情况下只能访问单个文件的受限用户调用Vim。 After Vim exits, copy back the file to its original location. Vim退出后,将文件复制回其原始位置。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM