Note that there are some explanatory texts on larger screens.

plurals
  1. PO
    primarykey
    data
    text
    <p>I wrote and have been using the following code snippet in my vimrc for copy-pasting my Vim windows.</p> <p>This defines for example the following shortcuts:</p> <ul> <li><code>&lt;c-w&gt;y</code>: "Yanks the window", i.e. stores the number of the buffer in the current window in a global variable.</li> <li><code>&lt;c-w&gt;pp</code>: "Puts the window in Place of the current window", i.e. it reads the buffer number stored previously and opens that buffer in the current window. It also stores the number of the buffer that used to be in the current window.</li> </ul> <p>If by "swapping those windows in places", you mean "opening the buffer in window A in window B, and vice versa, without changing the position of the windows", you can use the following keyboard sequence to swap the windows:</p> <ol> <li>Select window A (either with mouse or with keyboard commands)</li> <li>Press <code>&lt;c-w&gt;y</code> (yanking the buffer number)</li> <li>Select window B</li> <li>Press <code>&lt;c-w&gt;pp</code> (pasting the buffer)</li> <li>Select window A</li> <li>Press <code>&lt;c-w&gt;pp</code> (pasting the buffer again)</li> </ol> <p>It works only in Vim >= 7.0.</p> <pre><code>if version &gt;= 700 function! HOpen(dir,what_to_open) let [type,name] = a:what_to_open if a:dir=='left' || a:dir=='right' vsplit elseif a:dir=='up' || a:dir=='down' split end if a:dir=='down' || a:dir=='right' exec "normal! \&lt;c-w&gt;\&lt;c-w&gt;" end if type=='buffer' exec 'buffer '.name else exec 'edit '.name end endfunction function! HYankWindow() let g:window = winnr() let g:buffer = bufnr('%') let g:bufhidden = &amp;bufhidden endfunction function! HDeleteWindow() call HYankWindow() set bufhidden=hide close endfunction function! HPasteWindow(direction) let old_buffer = bufnr('%') call HOpen(a:direction,['buffer',g:buffer]) let g:buffer = old_buffer let &amp;bufhidden = g:bufhidden endfunction noremap &lt;c-w&gt;d :call HDeleteWindow()&lt;cr&gt; noremap &lt;c-w&gt;y :call HYankWindow()&lt;cr&gt; noremap &lt;c-w&gt;p&lt;up&gt; :call HPasteWindow('up')&lt;cr&gt; noremap &lt;c-w&gt;p&lt;down&gt; :call HPasteWindow('down')&lt;cr&gt; noremap &lt;c-w&gt;p&lt;left&gt; :call HPasteWindow('left')&lt;cr&gt; noremap &lt;c-w&gt;p&lt;right&gt; :call HPasteWindow('right')&lt;cr&gt; noremap &lt;c-w&gt;pk :call HPasteWindow('up')&lt;cr&gt; noremap &lt;c-w&gt;pj :call HPasteWindow('down')&lt;cr&gt; noremap &lt;c-w&gt;ph :call HPasteWindow('left')&lt;cr&gt; noremap &lt;c-w&gt;pl :call HPasteWindow('right')&lt;cr&gt; noremap &lt;c-w&gt;pp :call HPasteWindow('here')&lt;cr&gt; noremap &lt;c-w&gt;P :call HPasteWindow('here')&lt;cr&gt; endif </code></pre>
    singulars
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    plurals
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. VO
      singulars
      1. This table or related slice is empty.
    2. VO
      singulars
      1. This table or related slice is empty.
    3. VO
      singulars
      1. This table or related slice is empty.
    1. This table or related slice is empty.
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload