The easiest is to just use the quit command, :q, or you can use Ctrl-w q. You can close a window in one of several ways. To do it vertically, use :vert sview filename. To do this, use the :sview filename command. It’s also worth mentioning that you can open a file in a viewport just to view the file, without opening it to edit. To move to the viewport to the right, for example, you’d use Ctrl-w l. Ctrl-w Ctrl-w works, and instead of using the j and k movement keys, use the h and l movement keys to move back and forth between viewports. Movement between vertical viewports is similar to moving between horizontal viewports. To do this, just use :vsp, or :vsplit if you prefer to spell it out. If horizontal viewports just don’t do it for you, Vim also supports splitting viewports vertically. For instance, to add 13 lines, use Ctrl-w 13+. If one line at a time isn’t sufficient, add a modifier before the + or. Use Ctrl-w + to increase the active viewport, and Ctrl-w - to decrease its size by one line. You can increase or decrease a viewport’s size after it’s been created. You can also cycle between viewports by using Ctrl-w Ctrl-w. This should prove easy to remember - Ctrl-w for “window” commands, and the normal vi movement commands j for down and k for up. To move between the viewports while working, use Ctrl-w j to move down, and Ctrl-w k to move up. Ctrl-w = tells Vim to assign an equal number of lines to each viewport. Instead of going into command mode, you can use a normal keybinding to accomplish this. Now you have a viewport with 10 lines, but what if you’ve decided that you’d like to give both viewports equal real estate? That’s easy enough too. Just prepend a number to the sp command, and the new viewport will fill that number of lines: What if you don’t want to have equal viewports? For example, let’s say you want to open a reference file in the top viewport, but want the majority of the viewport available for the file you’re actually editing. You can even add a search string to that to move directly to the first instance of a keyword, like so:Įasy as falling off a log. That will open filename in the new viewport. If you’d like to work on two files simultaneously, no problem - just follow the command with the filename you’d like to use, like this: The :sp command will divvy up the viewport into two equal viewports for the file that you have open. Remember the Ctrl-w part, though, because it will come in handy for most operations with windows. If you want to use this feature for something other than viewing Vim’s help files, you can split the viewport by using :sp, :split, or Ctrl-w n - they do the same thing, but just typing :sp will save you a few characters, and it’s easier to use with arguments, such as filenames. Can be written out as :vsplit.Ĭtrl-w Ctrl-w moves between Vim viewports.Ĭtrl-w l moves one viewport to the right.Ĭtrl-w = tells Vim to resize viewports to be of equal size.Ĭtrl-w - reduce active viewport by one line.Ĭtrl-w + increase active viewport by one line.Ĭtrl-w r will rotate windows to the right.Ĭtrl-w R will rotate windows to the left. :vsp will split the Vim window vertically. :sp will split the Vim window horizontally. When you enter help, Vim splits the viewport and opens the help documentation in the top viewport, leaving your document open in the bottom viewport. You may already be familiar with this feature if you’ve ever used Vim’s help feature by using :help topic or pressing the F1 key. The Vim documentation refers to this as a viewport or window, interchangeably. If you’re confident using Vim to edit configuration files or make short edits in text files, but maybe not too comfortable with undertaking major writing or coding in Vim, then these articles should be for you.Ī really useful feature in Vim is the ability to split the viewable area between one or more files, or just to split the window to view two bits of the same file more easily. In this and future articles, I’m going to cover Vim features that you may not be familiar with if you’re a casual Vim user. Sure, you might know how to do the basics in Vim, but what about using more advanced features such as folding, split windows, and marks? With a little practice, you can really boost your productivity with Vim. A lot of folks use Vim, but many exploit only a small percentage of the editor’s features.
0 Comments
Leave a Reply. |
AuthorWrite something about yourself. No need to be fancy, just an overview. ArchivesCategories |