[英]Problems with Vim while switching between open files
I have multiple file open in Vim. 我在Vim中打开了多个文件。 When i want to switch from one file to another Vim does not allow me to switch unless I save the file or quit.
当我想从一个文件切换到另一个文件时,Vim不允许我切换,除非我保存文件或退出。 Is there a way such that I do not have to save everytime when I want to switch?
有没有一种方法可以让我在每次切换时都不必每次都保存? Is this a problem with Vim or am I making a mistake?
这是Vim的问题还是我做错了? If that's the way Vim works can anyone tell me the logical reason?
如果这就是Vim的工作方式,那么有人可以告诉我逻辑上的原因吗?
Just add 只需添加
set hidden
to your ~/.vimrc
. 到你的
~/.vimrc
。 It makes it possible to have multiple unsaved files open at all times. 这样就可以始终打开多个未保存的文件。
While you are at it, you should add this line as well: 在执行此操作时,还应添加以下行:
set switchbuf=useopen,usetab
It forces Vim to jump to an already open buffer where it is (right there, in another split-window, in another tab) instead of "hiding" the current buffer to replace it with the target buffer. 它迫使Vim跳转到一个已经打开的缓冲区( 在此 ,在另一个拆分窗口的另一个选项卡中),而不是“隐藏”当前缓冲区以将其替换为目标缓冲区。 This is useful for quickfix-related jumps but also for
:sb
. 这对于与quickfix相关的跳转非常有用,但对于
:sb
也很有用。
These two lines are the key to use Vim's buffers efficiently. 这两行是有效使用Vim缓冲区的关键。
Use :n!
使用
:n!
. 。 This will move to the next file, ignoring the changes and not saving them.
这将移至下一个文件,忽略更改而不保存更改。
You can also use tabs in vim; 您也可以在vim中使用制表符。 use
:tabnew file.txt
to open a new tab with file.txt
loaded. 使用
:tabnew file.txt
打开一个加载了file.txt
的新选项卡。 Then you can use gt
and gT
to navigate forward and backwards through your open tabs. 然后,您可以使用
gt
和gT
在打开的选项卡中前后导航。 I find this easier than dealing with buffers, but I'm a fairly new vim user. 我发现这比处理缓冲区更容易,但是我是一个相当新的vim用户。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.