If you're using an version of Vim older than 7.0, you won't have access to this feature. By now, though, most distros have moved to Vim 7.0, so if you're using a recent release you should be OK.
Opening a tab
Let's start by opening a new tab in Vim. There are a few ways to do this. Probably the easiest to remember is to run the :tabnew command while in normal mode. This will open a new tab with an empty buffer. If you want to edit a file in the new tab, you can run :tabnew filename and Vim will load the file in the new tab.
Another way to do this is to open more than one file at startup using the -p option. If you want to open three files in separate tabs, you'd use this syntax:
vim -p file1 file2 file3
This will start a Vim session with file1 in the first tab, file2 in the second tab, and file3 in the third.
Vim will open up as many tabs as you like on startup, up to the maximum number of tabs set in the .vimrc file. The default maximum is 10 tabs, but you can change this by setting the tabpagemax option in your .vimrc, like so:
set tabpagemax=15
If you exceed the number of tabs allowed by tabpagemax Vim will simply open the maximum number of tabs, and the other files will be open but not displayed. You can edit the remaining files by using the :next or :last command to move to the files that are not displayed in a tab. Note that this setting only applies to the maximum number of tabs Vim will open on startup -- you can still open more tabs during your Vim session.
The :tabf command allows you to search for a file in your current path and open it in a new tab. For instance, if you want to open a file called inventory.txt that's in your current path, you could run:
:tabf inven*
That will search for a file that matches the string inven and any number of characters after it. If only one file is found, Vim will open it in a new tab. If you have several files that match, Vim will complain that too many files match, and you'll have to narrow the search a little. The :tabn command will do autocompletion of file names in your path, so you can just type the first few characters of a filename and hit Tab to find the right file.
| |
| Figure 1 |
Moving between tabs
You can switch between tabs using :tabn and :tabp, or you can use gt while you're in normal mode. Of course, if you're using Vim's GUI, GVim, you can also use the mouse to switch between tabs or use keyboard shortcuts. In GVim, you can also access a context menu for tabs by right-clicking on the tab bar. Here you can open new tabs with a new buffer or an existing file, or close the current tab.
If you have a lot of tabs open, you can use :tabfirst, or just :tabfir, to jump to the first tab, and :tablast to jump to the last tab that's open.
By default, the tab labels are shown at the top of the Vim window only when tabs are open. If you want to see the tab bar all the time, you can modify the showtabline option in your .vimrc. To set this to display all of the time, use:
set showtabline=2
If you want to turn it off altogether, use 0 instead of 2.
Note that the tabs are still there, even if the tab bar isn't displayed. If you have the tabline option set to 0, you can still see what tabs are open by using the :tabs command, which will provide a summary of open tabs, as you can see in the figure.
Speaking of setting options, if you don't like the existing shortcuts for the tab commands, you can add your own. For instance, if you want to make it easy to open a new tab, you might insert this into your .vimrc:
imap ,t <Esc>:tabnew<CR>
This tells Vim to set up a keymap for ,t in insert mode, to run Esc to put Vim into normal mode, then :tabnew and a carriage return to run the command. You can set up mappings for all of the tab commands that you use regularly. For more on setting up mappings, see our article Using Vim mappings and abbreviations.
Rearranging tabs
If you're really meticulous and want to position tabs just so in Vim, you can move the tabs to a specific spot in the tab order using :tabm n , where n is the position number that you want to use. If you don't give the :tabm command an argument, then the current tab will be moved to the last spot.
Vim starts tab numbering from 0, so if you have six tabs open, you'll have tab 0 through tab 5. So, if you're in the first tab and want to move it to the fourth position, you'd run :tab 3.
Note that you can still use viewports normally within tabbed windows, and tabs are useful for doing a quick edit in a file when you have a main Vim window set up with a couple of viewports arranged just right.
Running commands in tabs
Let's say you're editing six or seven files in Vim and realize that you need to replace a variable name with a new one. Using the :tabdo command, you can run a search and replace through all of the tabs at once rather than changing each file individually. For instance, if you want to replace foo with bar, you'd run this:
:tabdo %s/foo/bar/g
That will run through each open tab and run the search and replace command (%s/foo/bar/g) in each one.
Tabs can be extremely useful, and it only takes a short while to become proficient with them. For more on working with tabs in Vim, run :help tab-page-intro within Vim.
Note: Comments are owned by the poster. We are not responsible for their content.
So, vim just made tabs? Tabs in text editors existed for over 5 years at least on the various editors I've been using on Windows. And why do I need to type all those ':tabXXX' kind of commands to just move in and out of tab and run a search?
What I do on Windows, I press 'Ctrl+h' and open search/replace window, directly type the strings in there without the '%s<nobr> <wbr></nobr>/' etc annoying symbols with quite many extra keystrokes with Ctrl and sounds more intuitive by just pressing a single sequence of shortcut to start typing the word you want to replace.
Also, I haven't felt either that with or without mouse is better for text editing, as I'd like to take some time to actually start typing my code after looking through at the various part of my code with my mouse wheel scrolling, instead of having the necessity to keep my hand on keyboard all the time for endless typing. I can help to have my hands to relax off keyboard from time to time.
All I wanted to say is... why is Vim so cheered? I've been editing code for nearly 8 years or so (and using Unix for about 5 years) while using vim here and there (I finally had a 2 weeks project entirely typed by vim recently) for a couple of years, but never ever really liked it, except that when editing config files on Unix, that's the best there is probably, because shell text editing won't allow a decent use of mouse through putty.
Ok. I'm only 25 years old and grew up starting from Windows while still using Windows as main machine, but I just find it odd that I never can like vim (or emacs for that matter) that if it's any better than Windows text editing with mouse.
vim does have excellent mouse support (both gvim & console vim). Try it--you can even use your mousewheel. Just because a lot of people who use vim find they are more productive with their fingers on the homerow doesn't mean that you need to keep them there to use the editor.Also, I haven't felt either that with or without mouse is better for text editing, as I'd like to take some time to actually start typing my code after looking through at the various part of my code with my mouse wheel scrolling, instead of having the necessity to keep my hand on keyboard all the time for endless typing. I can help to have my hands to relax off keyboard from time to time.
But, the first argument can be done via a regular expression itself.
Then again, I find it hard to use regular expression on vim on, say,
10 specific lines I choose from.
I read it somewhere you have to tell the line numbers to execute the
regular expression,
Then the first 4 of the lists are possible by default on my Windows
text editor (not notepad...) as for the rest I never felt the need,
so never using it, but EmEditor had a macro scripting function in
perl/php/ruby/js or some such languages last time I read about it
not in just 'ex' line editing command we never use day to day.
Secondly, I'm not interested in getting into a feature-for-feature
comparison with you. I thought you were asking for a sample of
features, so I gave you a sample. If you're not interested in those
features, well, that's your business. If you're interested in all the
features, read the documentation.
Unfortunately, now you're starting to sound like a troll.
The list is endless, I know, and how you can customize vim is also
endless, I know, but the complexity of it is also endless, making me
rather not use it anyway.
I just find it, until you customize vim so it doesn't even look like
vim anymore to your best taste, it only has features that is capable
in Windows text editors but with uglier(= harder to use)
desgin.
J
Now, what Windows editors offer, where Vim doesn't are.
Display split? Seriously, seeing only 1% of the whole code makes a real sloppy coding and is prone to serious coding problems as you have less code revealed to yourself, I never split screen.
Just to troll (with a good reason) a slightly bit to fire up vim lovers =) but why do 95% of vim themes look super ugly? Do you think people would even code good with 'blue' color scheme? It hurts my eyes from the first second.
Display split? Seriously, seeing only 1% of the whole code makes a real sloppy coding and is prone to serious coding problems as you have less code revealed to yourself, I never split screen.
Visually pleasing layout, you can definately see what files are open in tabs (now that vim finally caught up).
You know if the file is at the last saved state by looking at if the 'Save' button is greyed out or not.
You see the encoding method and total line numbers and all (though latter is visible in vim too).
And with a explorer extension, you can even have a list of files displayed on your left or right edge to figure out a good strucutre of your project and easy file opening, instead of in vim, you start out with<nobr> <wbr></nobr>:tabnew and blindly typing in folder and file names and keep pressing 'tab' to find out the file name matches and open file, and if you want to open yet another file in yet another folder, you have to dig through again, until you do a 'cd' first, which is completely reluctant to do than simply visually looking through the whole project file structure and clicking through it while maintaining visible information on the parent folders.
Both of this are configurable. The defaults are sane for newbs.The search and replace uses some weird windows default dialog without regular expression capability. And if you use the cream search/replace dialog, it asks for confirmation on every step which is way too silly.
Why discount gvim, except to troll (as you are apparently more comfortable in a GUI environment)? The nice thing about vim is that you have a choice.Btw, I'm all talking about console vim, not gvim
You can still see A LOT of code. Your concern seems to be use of vertical real estate (with<nobr> <wbr></nobr>:split). At home, I also have only about 50 lines of text in 16 point font at 1600x1200 (I sit about 6' back, as it is primarily used for media. At work, I fit about 80 lines of text at 11 pt. This can make for horizontal splits of about 40 lines each, or a 50 line primary & a 30 line secondary if you prefer.As for display split... yes, I have 1680x1050 screen, which can be big, but I'd like to see at the least 50 lines (my current situation is prolly 60 or so lines visible) vertically
That is slower. Especially if one of the files must be referenced extensively. Some people use transparent terms so that they can see the text in a web browser underneath for the same reason. Ctrl-Tabing may be more intuitive for some people & you can still do that in vim.Besides, I don't know why I want to look at 2 files at once, when I can just 'Ctrl+Tab' to go back and forth files with full width/height.
And vim supports all 16M colors (assuming your window manager or terminal do). vim ships with PLENTY of color schemes (I like 'desert'), others can be downloaded, and you can make a custom one. How are you limited by the colors?!And the colors... come on... it's 21st century, we got million color display.
I'm 25. Is that old?I'm starting to put this as a conclusion that vim is for the old people.
Developers are motivated by different things. Some freeware developers might hope to build an audience & eventually create something they think they could get a lot of money for.Free products better keep source open or once the guy in charge feel like quitting because he got bored, the product is gone forever.
There have been plenty of commercial apps which have been abandoned for one reason or another.Otoh, commercial app at least has a motivation to keep it going as long as it's a good product with good amount of followers.
Why not? evim is used in place of other editors at my work by newbs. It highlights most syntax you can encounter, which is quite useful. You can install new syntax highlighting in most programmers editors, but vim already has even esoteric highlighting by default. And you can know that you'll never "outgrow" your editor.So, you can say that vim isn't for people who just want to get the editor to work and get the thing done with minimal gui configuration
':e<nobr> <wbr></nobr>.' will open a directory browser for the current working directory. (And<nobr> <wbr></nobr>:e with any directory after it will start the browser in that directory.) Plus, as you mention, you have tab-completion.With 'e:' don't you forget the directory structure?
Didn't you say "real programmers" recall their function names/variables/etc.? Do they additionally forget their filenames?And it's annoying when there are many similarly named files when you have to keep pressing tab tab tab and figure out the right name you want to edit.
If you can install any other editor, I'd imagine that you can install vim with mouse support!And mouse is not always supported
I've used a lot of editors on windows. I used UltraEdit for many years.Someone just tell me, are people who love vim, just never used a serious Windows mouse-enabled text editor
Tools are a personal choice. If you don't like or don't get vim, then don't use it. What is the point of trolling in vim related articles?to know what is best or they have a good reason to ditch any other editor to tell it is practically the best??? I'm way confused over the years.
But you choose the weirdness & the colors. You can make a customized, idiosyncratic environment which will work for you almost anywhere.but all I see about vim is about weirdness and ugly color theme and no idea how this can improve my coding.
You did look at the date of the article you're commenting on now, didn't you. Or do you think you are you from the year 2014?And a page that looks to be on advanced vim topic is usually 7 years old.
You have yet to say how gvim is less productive than your GUI editor of choice or given the name of a superior console editor.but I just can't find what's so better, or even as productive as some other editors out there about vim, which is too bad.
Yeah, some plugins are cool like that miniExplorer thing, but that doens't still solve my mystery how people think vim is the best (or 2nd best<nobr> <wbr></nobr>;) ) editor.
You've been informed that vim supports windows text editing with a mouse. If you wanted to make a sincere comparison, you'd therefore compare your current windows editor with GVIM on windows. It'd be apples:apples.Also, I haven't felt either that with or without mouse is better for text editing, as I'd like to take some time to actually start typing my code after looking through at the various part of my code with my mouse wheel scrolling<nobr> <wbr></nobr>....
I never can like vim (or emacs for that matter) that if it's any better than Windows text editing with mouse.
Indeed, this is the only way I've used the tab feature. I normally have very related files open in a few viewports & will only open a tab if I need to quickly scan another file or jot down an unrelated note.Note that you can still use viewports normally within tabbed windows, and tabs are useful for doing a quick edit in a file when you have a main Vim window set up with a couple of viewports arranged just right.
There's <a href="http://cream.sourceforge.net/" title="sourceforge.net">cream</a sourceforge.net> or 'easy vim' ('evim') for those who want to get up-and-running quickly.And to add some, until you read through vim documentation thoroughly, you have no idea how to use vim, which puts me (and plenty other people) away fast too.
As you point out, you can map these to key combinations or easier to remember commands. You can also frequently use your mouse and the GUI if you're into that sort of thing.And not only you have to read the doc, you have to actually remember the commands
Folding is usually based on scope, so it is hard for me to see when this would be a problem. (You can fold a whole function, for instance. Any variable unique to that function probably won't collie outside the function.)Say, foldings... why do you hide your code? You might forget about a variable at certain place and make a new bug thinking it's not used.
Function name auto completion? If you're a serious programmer, you really do already remember most of the function names that you usually use along with the parameter requirements, but if you do get stuck in that, you should refer the actual language doc.In many cases, you do know. But having completion can save A LOT of typing. In the cases you've forgotten, completion is often faster than checking the docs. "Intellisense" completion was one of the most-requested features of all time!Moonitors are BIG these days. Why not use the space effectively? You advocated for splitting big files into small ones when you said folding was useless. Well, splits will allow you to have multiple small files open. You could use the other files just for reference or can change anything that needs to be refactored.Display split?The old WordPerfect was white-on-blue by default & it was quite popular.Just to troll (with a good reason) a slightly bit to fire up vim lovers =) but why do 95% of vim themes look super ugly? Do you think people would even code good with 'blue' color scheme? It hurts my eyes from the first second.
The bottom-line is that you don't need to use every feature in vim (and there are a lot). Being comfortable with a few of the features CAN make some people more productive (which is why people choose it). Don't belittle other people's choices--just be comfortable with your own.
sweet
Posted by: Anonymous Coward on January 25, 2007 01:49 AM#