If you’ve moved to Vim from an editor like Notepad++ or TextMate, you’ll be used to working with the idea of tabs in a text editor in a certain way. Specifically, a tab represents an open file; while the tab’s there, you’ve got an open file, as soon as you close it, it goes away. This one-to-one correspondence is pretty straightforward and is analogous to using tabs in a web browser; while the page is open, there’s a tab there, and you have one page per tab, and one tab per page.

Vim has a system for tabs as well, but it works in a completely different way from how text editors and browsers do. Beginners with Vim are often frustrated by this because the model for tabs is used so consistently in pretty much every other program they’re accustomed to, and they might end up spending a lot of fruitless time trying to force Vim to follow the same model through its configuration.

I think a good way to understand the differences in concept and usage between Vim’s three levels of view abstraction — bufferswindows, and tabs – is to learn how to use each from the ground up. So let’s start with buffers.

Buffers

buffer in Vim is probably best thought of for most users as an open instance of a file, that may not necessarily be visible on the current screen. There’s probably a more accurate technical definition as a buffer need not actually correspond to a file on your disk, but it’ll work for our purposes.

When you open a single file in Vim, that file gets put into a buffer, and it’s the only buffer there on startup. If this buffer is unmodified (or if you’re using hidden), and you open another file with :edit, that buffer goes into the background and you start working with the new file. The previous buffer only goes away when you explicitly delete it with a call to :quit or :bdelete, and even then it’s still recoverable unless you do :bwipe.

By default, a buffer can only be in the background like this if it’s unmodified. You can remove this restriction if you like with the :set hidden option.

You can get a quick list of the buffers open in a Vim session with :ls. This all means that when most people think of tabs in more familiar text editors, the idea of a buffer in Vim is actually closest to what they’re thinking.

Windows

window in Vim is a viewport onto a single buffer. When you open a new window with :split or:vsplit, you can include a filename in the call. This opens the file in a new buffer, and then opens a new window as a view onto it. A buffer can be viewed in multiple windows within a single Vim session; you could have a hundred windows editing the same buffer if you wanted to.

Vim Session with multiple windows open, both horizontally and vertically.

Tabs

Finally, a tab in Vim is a collection of one or more windows. The best way to think of tabs, therefore, is as enabling you to group windows usefully. For example, if you were working on code for both a client program and a server program, you could have the files for the client program open in the first tab, perhaps in three or four windows, and the files for the server program open in another, which could be, say, seven windows. You can then flick back and forth between the tabs using :tabn and:tabp.

Two tabs open in Vim, each with multiple windows. Move between two tabs with :tabn and :tabp.

This model of buffers, windows, and tabs is quite a bit more intricate than in other editors, and the terms are sometimes confusing. However, if you know a bit about how they’re supposed to work, you get a great deal more control over the layout of your editing sessions as a result. Personally, I find I rarely need tabs as with a monitor of sufficient size it suffices to keep two or three windows open at a time when working on sets of files, but on the odd occasion I do need tabs, I do find them tremendously useful.

Thanks to Hacker News users anonymous and m0shen for pointing out potential confusion with the :set hidden option and the :bdelete command.

Related Posts

  • Start Vim with splits
  • Unix as IDE: Editing

转载于:https://www.cnblogs.com/threef/p/3355369.html

Buffers, windows, and tabs相关推荐

  1. VIM(Neovim)基本概念与高效使用方法

    操作符和动作 Vim两个基本概念:操作符operator和动作motion.operator看作动词,motion看做名词. 操作符是用于对文本内容进行操作的命令,比如修改c.删除d.y复制到寄存器. ...

  2. linux 强制刷新文件,vim 如何刷新或重载reload 已打开的文件

    Ref:vim 如何刷新或重载reload 已打开的文件 Just use :e to reload the file.  I believe, if you've made changes to t ...

  3. MFC界面库BCGControlBar v25.3新版亮点:Dialogs和Forms

    2019独角兽企业重金招聘Python工程师标准>>> 亲爱的BCGSoft用户,我们非常高兴地宣布BCGControlBar Professional for MFC和BCGSui ...

  4. a或b search vim_vim入门,进阶与折腾

    做为编辑器之神,vim一直是我编辑文本的不二选择,哪怕其坎坷的学习曲线让人头疼不已.末学总结一下经验教训,以作备忘. 入门 个人习惯编译选项 ./configure -with-features=hu ...

  5. Chrome插件开发先看这篇:如何实现一键上班赖皮

    今天看有人发文章专门介绍Chrome插件,我必须要说,插件开发就是一个摆弄一个小玩具,第一要素是实用,其次是好玩. 单纯罗列各种功能是非常无趣的. 所以把一篇旧文拿出来与大家分享. 人,活着就是为了赖 ...

  6. Chrome插件开发入门:如何实现一键上班赖皮

    很多人介绍过Chrome插件,但必须要说,插件开发就是摆弄一个小玩具,第一要素是实用,其次是好玩. 单纯罗列各种功能是非常无趣的. 所以把一篇旧文拿出来与大家分享. 人,活着就是为了赖皮. 作为一个合 ...

  7. (四)UE4编辑器菜单按钮

    1. 主菜单的按钮 参考https://alanwalk.github.io/2018/04/17/how-to-add-ue4-editor-menu/ 2. Tab上的按钮 3. Tab上的菜单怎 ...

  8. Linux文档编辑命令大全

    1.col命令 Linux col命令用于过滤控制字符. 在许多UNIX说明文件里,都有RLF控制字符.当我们运用shell特殊字符">"和">>&qu ...

  9. MacOS Terminal 常用快捷键大全

    文章目录 常用功能键 控制窗体和页 | Work with Terminal windows and tabs 编辑命令行 | Edit a command line 选择操作 | Select an ...

最新文章

  1. 什么是三层架构?简单的介绍三层架构!
  2. linux下访问windows的共享
  3. 阿里云 MSE 云原生网关助力斯凯奇轻松应对双 11 大促
  4. jquery中Live方法不可用,Jquery中Live方法失效
  5. web安全---XSS漏洞之标签使用2
  6. 解决Office系列安装不上的办法
  7. 广东科技学院计算机原理组成,201120122操作系统原理期中试卷edited广东科技学院付博士(4页)-原创力文档...
  8. windows下利用批处理命令生成maven项目(java、javaWeb)
  9. OpenCV-图像处理(18、Laplance算子)
  10. java jdk下载_jdk1.7下载|Java Development Kit (JDK) 下载「64位」-太平洋下载中心
  11. python 基础代谢率计算_【Python 19】BMR计算器3.0(字符串分割与格式化输出)
  12. stm32最小系统原理图
  13. ##24点游戏程序实现算法(文末源代码)
  14. 手把手教你用JAVA调用Websocket实现“声音转换”功能(变声)标贝科技
  15. wps excel 表格粘贴到 word 删除首行缩进
  16. 【JAVA】(vip)蓝桥杯试题 基础练习 阶乘计算 BASIC-30 JAVA
  17. 宝塔面板建立的网站为什么访问不了
  18. ERP/MIS开发 LLBL Gen多表操作
  19. 华为nova7se能云闪付吗_vivoS7和华为nova7se哪个好?自拍手机该如何抉择!
  20. (转)[教你开启冻酸奶的app2sd] android2.2的APP TO SD功能启动方法

热门文章

  1. .NETCore_生成实体
  2. host 'xx' is not allowed to connect to this MySql server
  3. phalcon无限重定向
  4. Tomcat服务器的安装及配置
  5. 浏览器获取正确的scrollTop值
  6. 解决未知的服务器标记“asp:ListView”。
  7. C# 繁体,简体 互转
  8. fastapi vue socket 从其他文件调用 socket 方法
  9. consul删除无效服务
  10. Mysql 休眠连接过多,有可能导致“Too many connections”的错误