官术网_书友最值得收藏!

Moving windows

Windows can also be moved, swapped, and resized. Since there's no drag-and-drop functionality in Vim, there are some commands you will have to remember.

You don't have to remember all of these commands, as long as you know what window operations are supported. :help window-moving and :help window-resize will take you to the corresponding entries in the Vim manual when you inevitably forget the shortcuts.

As with the rest of the window commands, these are prefixed by Ctrl + w.

Ctrl + followed, by an uppercase movement key (H, J, K, or L) will move the current window to the corresponding position:

  • Ctrl + w, H moves the current window to the leftmost part of the screen
  • Ctrl + w, J moves the current window to the bottom of the screen
  • Ctrl + w, K moves the current window to the top of the screen
  • Ctrl + w, L moves the current window to the rightmost part of the screen

For example, let's start with the following window layout (which was achieved by opening animal_farm.py and running :sp animals/cat.py, followed by :vs farm.py):

Note the cursor position (in animals/cat.py). Here's what happens when we try to move the window containing the animals/cat.py buffer in each direction:

  • Ctrl + w, H migrates animals/cat.py all the way to the left:

  • Ctrl + w, J moves animals/cat.py to the bottom of the screen, turning a vertical split into a horizontal split:

  • Ctrl + w, K moves animals/cat.py to the top of the screen:

  • Ctrl + w, L moves animals/cat.py to the right of the screen:

You can change the contents of each window by simply navigating to it and selecting the desired buffer using the :b command. There are, however, options for swapping window contents:

  • Ctrl + w, r moves every window within the row or the column (whichever is available—rows are given preference over columns) to the right or downward. Ctrl + w, R performs the same operation in reverse.
  • Ctrl + w, x exchanges the contents of a window with the next one (or a previous one if it's considered a last window).
Internally, Vim refers to windows by number. However, unlike with buffers, the numbers change as your window layout adjusts, and there is no straightforward way to surface window numbers. Some window management commands take the window number as an argument, but this book will not be covering these. For reference, windows are numbered top to bottom, left to right.
主站蜘蛛池模板: 海南省| 金堂县| 宜宾县| 肥西县| 龙岩市| 阜南县| 忻州市| 陵川县| 桃园县| 巴中市| 遂平县| 洛扎县| 洱源县| 通山县| 通化市| 北辰区| 汕尾市| 喀喇| 陆川县| 德清县| 塔城市| 拉孜县| 西青区| 山阴县| 锡林浩特市| 杭锦后旗| 苏尼特左旗| 乌兰察布市| 蕲春县| 岐山县| 台中县| 洱源县| 保山市| 观塘区| 康保县| 长丰县| 武川县| 绩溪县| 阿荣旗| 永年县| 黄龙县|