Vim Tip #1: Basic Tabs

2018-11-12(Mon)

tags: Vim

Vim Tips

Vim works on the concept of 'buffers,' each of which holds a Linux file - but generally only one of these buffers are visible to you at one time and you have to save file changes before you can switch buffers (by default - it can of course be changed). I much prefer tabs, so let's talk about tabs.

To open a new tab, use :tabnew <filename> .

In Normal mode, gt will Go to (next) Tab, and gT (note capitalization) will go to previous tab. If you want to investigate, there are a variety of commands for jumping between tabs - I found I didn't use them enough to remember them. With NeoVim, you can click on the tabs to go to the file, even in the terminal.

If you find yourself using a lot of tabs, you may want to stop using :tabnew ... and instead use :tab drop <filename> . This command will hunt through your existing tabs, and take you to the file if it's already open. If it's not already open, it will open it in a new tab. NOTE: :tab drop ... in Debian and Fedora requires a huge passel of packages that you may or may not have installed. It's available by default with NeoVim.

And finally, if you'd like to open more than one file in tabs from the command line, use vim -p <file1> <file2> ... .

Advanced reading: my replacement for :tab drop before I found NeoVim