Multi-Window Working Environment in Emacs tmux and VIM environment-Second Quarter window Rotation

Source: Internet
Author: User

 

In the first season, I introduced how to cut the window into what I needed. This season we will discuss how to rotate the window layout after cutting. Why do we need to rotate the window layout? The simplest answer is: any window layout will always make you feel unable to meet your current needs at some time. What should we do at this time? Changing the window is always better than changing yourself. Now that you have chosen to change the window layout, how to change it becomes the next question. If there is a portal, let us directly reach the desired place, of course, it is much more convenient to first return to the original single window mode and then re-cut the layout. A revolving window is such a portal.

 

Let's start with the common multi-window mode. The multi-window mode is usually used in the form of two, three, and four windows. On the one hand, the environment of the four or more windows is relatively less useful (compared with the limited screen space, too many windows are cut, and each window can use a limited area). On the other hand, if such a complicated window layout is selected, it should also be carefully selected. It is designed for a specific requirement, and there are usually not many opportunities for re-layout.

 

So here we will only discuss the two windows, three windows, and four windows. The four window modes (that is, the dashboard) have the characteristics of axial symmetry and center symmetry at the same time, so there is no need to rotate. In this way, we need to discuss only two windows and three windows.

 

Two-window Rotation

The rotation of the second window is easy to understand. It is nothing more than converting from horizontal to vertical, and then from vertical to horizontal. However, there is a bad message and a good news. Bad news is that Emacs's native code does not provide direct support. In Native Emacs, you can only use ctrl-x 0 or Ctrl-x 1 to return to single window mode, and then use ctrl-x 2 or Ctrl-x 3 to re-cut. In tmux and Vim, such rotation is supported by native. The good news is that I wrote an Emacs Extension function change-Split-type to fill this gap. When using this function, you can bind it to Ctrl-x 4 C. And because this function is adaptive, you only need this function and one button to bind, whether from horizontal to vertical or from vertical to horizontal.

 

The following example still follows the conventions in the first quarter. The command/Operation example shows emacs-tmux-Vim in the following order.

 

#+BEGIN_EXAMPLE


+--------------------------------+ +----------------+----------------+
| | change-split-type | | |
| a | Ctrl-b Alt-1 | | a |
| | Ctrl-w L | | |
+--------------------------------+ ----------------> | | |
| | | | |
| | | | |
| | | | |
+--------------------------------+ +----------------+----------------+

+---------------+----------------+ +--------------------------------+
| | | change-split-type | |
| a | | Ctrl-b Alt-2 | a |
| | | Ctrl-w K | |
| | | ----------------> +--------------------------------+
| | | | |
| | | | |
| | | | |
+---------------+----------------+ +--------------------------------+


#+END_EXAMPLE

 

Three-window Rotation

In addition, due to the complicated problem involved in window rotation, we need to separate eamcs, tmux and VIM this time. First, emacs

 

Emacs three-window Rotation

As you may have guessed, the rotation of three windows in Emacs does not provide native support. The good news is that I also wrote an Emacs Extension function change-Split-type-3 to solve this problem. This function is also an adaptive function that rotates the window clockwise regardless of the Mode shown in the current window layout. In this way, you do not need to carefully identify different scenarios and then select the correct function. This function is bound to Ctrl-x 4 C in my Emacs. Note that C is in uppercase to distinguish it from the previous function.

 

#+BEGIN_EXAMPLE

+--------------------------------+ +----------------+---------------+
| | change-split-type-3 | | |
| a | Ctrl-x 4 C | | a |
| | | | |
+---------------+----------------+ ----------------> +----------------+ |
| | | | | |
| | | | | |
| | | | | |
+---------------+----------------+ +----------------+---------------+
^ |
| change-split-type-3 | change-split-type-3
| Ctrl-x 4 C | Ctrl-x 4 C
| |
| v
+---------------+----------------+ +----------------+---------------+
| | | change-split-type-3 | | |
| a | | Ctrl-x 4 C | | |
| | | | | |
| +----------------+ <---------------- +----------------+---------------+
| | | | |
| | | | a |
| | | | |
+---------------+----------------+ +--------------------------------+


#+END_EXAMPLE

In fact, there is good news in Emacs. Now that I want to write a function myself, I simply write another one and solve the problem of rotating the buffer. The so-called rotation buffer is to keep the current window mode unchanged, the edit buffer of the three windows in the clockwise direction, exchange each other. The name of this function is roll-v-3. It is bound to the Ctrl-x 4 r key combination in my Emacs.

 

#+BEGIN_EXAMPLE

+--------------------------------+ +--------------------------------+
| | roll-v-3 | |
| A | Ctrl-x 4 r | B |
| | | |
+---------------+----------------+ ----------------> +---------------+----------------|
| | | | | |
| B | C | | C | A |
| | | | | |
+---------------+----------------+ +---------------+----------------+
^ |
| roll-v-3 roll-v-3 |
| Ctrl-x 4 r Ctrl-x 4 r |
| |
| +-------------------------------+ |
| | | |
+------------- | C | <------------+
| |
+---------------+---------------+
| | |
| A | B |
| | |
+---------------+---------------+


#+END_EXAMPLE
Three-window rotation of tmux

Tmux provides native support for the three-window mode, so it is most convenient to rotate three windows in tmux. However, such support is also limited. We can see that tmux is less of a layout than Emacs here.

Note: In the following example, m represents the meta key, which corresponds to the Alt key on the modern keyboard.

#+BEGIN_EXAMPLE

+----------------+----------------+
Ctrl-b M-3 | | |
+-------------------------------------- | | b |
| | | |
| +---------------------------------> | a +----------------+
| | Ctrl-b M-4 | | |
| | | | c |
v | | | |
+--------------------------------+ +----------------+----------------+
| | ^ |
| a | | |
| | | |
+---------------+----------------+ Ctrl-b M-4 | | Ctrl-b M-5
| | | | |
| b | c | | |
| | | | v
+---------------+----------------+ +----------------+----------------+
| ^ | | |
| | | a | b |
| | Ctrl-b M-3 | | |
| +---------------------------------- +----------------+----------------+
| | |
+-------------------------------------> | c |
Ctrl-b M-5 | |
+---------------------------------+
#+END_EXAMPLE
Vim's three-window Rotation

Vim's window rotation is the most complex here. Vim also provides native support for window rotation. With native support, you can achieve a variety of rotation support, and all of these methods have rich Vim colors.

 

The three-window rotation of VIM is divided into two parts. The first is the simplest method. Strictly speaking, this method cannot be called "rotation". It should be called "Reconciliation", but it is also an operation that can be used in three-window mode, so I will introduce it here.

#+BEGIN_EXAMPLE

+--------------------------------+ +----------------+----------------+
| | | | |
| a | Ctrl-w J | b | c |
| | -----------------> | | |
+---------------+----------------+ +----------------+----------------+
| | | <----------------- | |
| b | c | Ctrl-w K | a |
| | | | |
+---------------+----------------+ +---------------------------------+

#+END_EXAMPLE

The following describes the real rotation. Although Vim native provides rich multi-window operation support, some of these operations are not very direct. As shown in the following example, an intermediate state is required for transition.

 

NOTE 1: In the following example, the window marked with a represents the current window, that is, the window where the cursor is located.

NOTE 2: In the rotation example in the lower right corner, the window marked with letter B represents the current window.

#+BEGIN_EXAMPLE

+-----------------+ +-----+-----+-----+ +--------+--------+
| a | Ctrl-w H | | | | Ctrl-w J | b | c |
| | --------------> | | | | --------------> | | |
+--------+--------+ | a | b | c | +--------+--------+
| b | c | <-------------- | | | | <-------------- | a |
| | | Ctrl-w K | | | | Ctrl-w H | |
+--------+--------+ +-----+-----+-----+ +-----------------+



+--------+--------+ +-----------------+ +--------+--------+
| | b | Ctrl-w K | a | Ctrl-w L | b | |
| | | --------------> +-----------------+ -------------> | | |
| a +--------+ | b | +--------+ a |
| | | <-------------- +-----------------+ <------------- | | |
| | c | Ctrl-w H | c | Ctrl-w K | c | |
+--------+--------+ +-----------------+ +--------+--------+
      ^                                                                        |
      |  Ctrl-w H                                                              |  Ctrl-w H
      |                                                                        v
  +-----------------+                                                     +--------+--------+
  |                 |                                                     |        |        |
  |                 |                                                     |        |        |
  +--------+--------+                                                     +--------+--------+
  |        |        |                                                     |                 |
  |        |   a    |                                                     |        b        |
  +--------+--------+                                                     +-----------------+


#+END_EXAMPLE

Note: For Emacs extension functions mentioned in this season, visit emacswiki.

 

 

 

 

 

 

Related Article

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.