Giter Site home page Giter Site logo

vim-windowswap's Introduction

WindowSwap.vim

Swap windows without ruining your layout!

img

Vim's window movement commands work fine when you only have a few splits open or want to push a window over to an edge. But what happens when you have a complicated layout and you just want to swap a couple arbitrary windows?

When I was just getting started with Vim, I asked about this problem on StackOverflow and I've received a handful of responses over the years. Almost a year after after I asked, sgriffin came through with a solution. Now that I'm a little less of a newbie, I've put his idea in a handy plugin.

HowTo

  1. Navigate to the window you'd like to move
  2. Press <leader>ww
  3. Navigate to the window you'd like to swap with
  4. Press <leader>ww again

Key Bindings

Defaults:

  • Yank and paste a window with <leader>ww (for me that's ,ww)

Deprecated defaults:

  • [y]ank a [w]indow with <leader>yw
  • [p]aste that [w]indow with <leader>pw.

These mappings are deprecated. See below for instructions on how to keep them working once they are removed from the default list.

Customize the commands to your liking by dropping this in your .vimrc and changing the mappings:

let g:windowswap_map_keys = 0 "prevent default bindings
nnoremap <silent> <leader>yw :call WindowSwap#MarkWindowSwap()<CR>
nnoremap <silent> <leader>pw :call WindowSwap#DoWindowSwap()<CR>
nnoremap <silent> <leader>ww :call WindowSwap#EasyWindowSwap()<CR>

Installation

This plugin follows the standard runtime path structure, and as such it can be installed with a variety of plugin managers:

  • Vundle - Plugin 'wesQ3/vim-windowswap'
  • Pathogen - git clone https://github.com/wesQ3/vim-windowswap ~/.vim/bundle/vim-windowswap
  • NeoBundle - NeoBundle 'wesQ3/vim-windowswap'
  • VAM - call vam#ActivateAddons([ 'wesQ3/vim-windowswap' ])
  • manual - copy all of the files into your ~/.vim directory

vim-windowswap's People

Contributors

aschrab avatar autoferrit avatar nfnty avatar wesq3 avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

vim-windowswap's Issues

Swapping across tabs.

Relating to #4, I also often run :echo bufnr('') in a different tab than where I run :b N. Window swapping/cloning across tabs would be nice. E.g. ww or yw in one window of one tab, then ww, pw, or cw in a window of another tab. :D

Support swapping windows in a given direction

I wrote a tiny function utilizing WindowSwap to swap two adjacent windows with a single mapping:

function! WindowSwapInDirection(dir)
  call WindowSwap#MarkWindowSwap()
  exec 'wincmd ' . a:dir
  call WindowSwap#DoWindowSwap()
endfunction

noremap <silent> <M-S-h> :call WindowSwapInDirection('h')<cr>
noremap <silent> <M-S-j> :call WindowSwapInDirection('j')<cr>
noremap <silent> <M-S-k> :call WindowSwapInDirection('k')<cr>
noremap <silent> <M-S-l> :call WindowSwapInDirection('l')<cr>

This is super useful and I think it would be a nice addition to the WindowSwap plugin itself.

I don't have time to submit a PR right now but I thought I'd leave the snippet here in case anyone wants to do the same.

Error when loading from saved session

I'm getting the following errors when loading from a saved session:

Error detected while processing function airline#extensions#windowswap#get_status: 
line    1:
E117: Unknown function: WindowSwap#HasMarkedWindow
Press ENTER or type command to continue 
Error detected while processing function airline#extensions#windowswap#get_status:
line    1:
E15: Invalid expression: WindowSwap#HasMarkedWindow() && WindowSwap#GetMarkedWindowNum() == winnr()

Swapping windows of the same buffer?

It seems that this plugin works for windows that contain different buffers. I often keep multiple windows of the same file/buffer but scrolled to different parts of the file. Is it possible for this script to support that? or does vim not treat windows of the same buffer differently?

I'd be happy to contribute time to solve this :)

Failsafe mechanism to prevent pasting before yanking.

It would be nice to have a failsafe mechanism preventing errors from coming up accidentally. For example, g:markedNumWin could be initially set to 0 - since no windows have that number, and in DoWindowSwap there could be a check so that an informative message is displayed if the user tried to paste a window without having yanked one, without failing with an error.

In addition I believe it could be nice, after pasting, to set again g:markedNumWin to 0 to force the user to again yank a window before pasting, to prevent accidental window movings. But this part is just opinion =)

Request: Paste window, not swap.

Using yw then yp behave like using ww two times: it swaps the windows. It'd be nice to just paste a window, not swap. E.g., I was expecting yw to copy a window, then pw to paste into the chosen buffer while leaving the same buffer in the previous window. e.g. the buffer where pw is called would replace that buffer with the yw buffer, but nothing would happen to the yw buffer.

That would seem to be more intuitive since normal yy followed by a Vp doesn't swap two lines.

Phase out `yw` and `pw` default bindings

To avoid confusion like in #4 and to not clutter up people's key-space, stop adding bindings for MarkWindow and PasteWindow. I don't want to rock anyone's vimboat so a very gradual deprecation process is in order. I'll mark progress in this issue.

  • Put in some actual documentation, jeez — ec0f16e, #6
  • Deprecation notice on default bindings — 03f26cb
  • Warn on first use of binding with link to help/doc — 15db3f6
  • Remove bindings

winnr() might be affected by <leader>ww but not <leader>y/pw

Hello. When I use my statusline (built by following lightline) with windowsswap, I found that if I swap a text buffer with a doc buffer (for example by :h stl), an error occurs if I want to close the doc buffer. (See the pictures at the end. I also noticed that the conceallevel was also changed in the documents.

This error will not occur if I use <leader>yw and <leader>pw to swap the buffers. It seems that the winnr() is not 1 once I close the doc buffer, I can tell it from lightline's code or mine (and the error occurs whether I use lightline or my statusline).

So I'm wondering if <leader>ww if different from the will-be-deprecated two, and if it is something needed to be fixed. Thanks.

before
after
close

No movement but message appears ?

Hi - Thanks for writing this, it should be very useful.

I'm trying to use it on Vim 7.3 on Ubuntu.

I've installed using Pathogen but when I try to use it I have problems.

Reading the instructions I think putting the keybindings into .vimrc is optional ? I tried it as follows.

Navigate to first window and hit \ww . Error message appears "E117: Unknown function: WindowSwap#EasyWindowSwap"

So then I put the keybindings into my .vimrc and I tried it as follows.

Navigate to a window and hit \ww . Nothing visible happens at the point. I then try to navigate to the other windows involved by doing wl . That results in a message appearing saying ":call WindowsSwap#EasyWindowSwap" but the actual navigation doesn't occur. When that message appears the focus is down with the message and if you hit at that point you get another message "E107: Missing parentheses: WindowsSwap#EasyWindowSwap"

If any of that sounds familiar I'd be grateful for some guidance.

I should say that I don't actually know that is "" but I understand that is the default and the fact that I'm getting a windowswap based error suggests to me that it's correct for my environment.

Indicator when half-way through swap

Is it at all possible to have some kind of indicator on the screen when you've marked a window but haven't yet swapped it?

Occasionally I'll go to mark window B so I can swap it with window C, only to see window B and A swap

(Me having accidentally marked A earlier, or marked it then forgotten)

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.