Movatterモバイル変換


[0]ホーム

URL:


Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Sign up
Appearance settings

A neovim plugin that makes it easy to move, swap, and resize windows

License

NotificationsYou must be signed in to change notification settings

MisanthropicBit/winmove.nvim

Repository files navigation


Easily move, swap, and resize windows


moving-around-windows.mov

Requirements

  • Neovim 0.9.0+

Installing

Plug'MisanthropicBit/winmove.nvim'
use'MisanthropicBit/winmove.nvim'

Configuration

If you are content with the defaults that are shown below, you don't need tocall theconfigure function. No default keymaps are set other than thoseactive during modes.

Note

For mode highlight groups that only have a foreground color,winmove willautomatically use the foreground color as a background color for the givenmode so you do not have to create a custom highlight group yourself.

require('winmove').configure({keymaps= {help="?",-- Open floating window with help for the current modehelp_close="q",-- Close the floating help windowquit="q",-- Quit current modetoggle_mode="<tab>",-- Toggle between modes when in a mode    },modes= {move= {highlight="Visual",-- Highlight group for move modeat_edge= {horizontal=at_edge.AtEdge.None,-- Behaviour at horizontal edgesvertical=at_edge.AtEdge.None,-- Behaviour at vertical edges            },keymaps= {left="h",-- Move window leftdown="j",-- Move window downup="k",-- Move window upright="l",-- Move window rightfar_left="H",-- Move window far left and maximize itfar_down="J",-- Move window down and maximize itfar_up="K",-- Move window up and maximize itfar_right="L",-- Move window right and maximize itsplit_left="sh",-- Create a split with the window on the leftsplit_down="sj",-- Create a split with the window belowsplit_up="sk",-- Create a split with the window abovesplit_right="sl",-- Create a split with the window on the right            },        },swap= {highlight="Substitute",-- Highlight group for swap modeat_edge= {horizontal=at_edge.AtEdge.None,-- Behaviour at horizontal edgesvertical=at_edge.AtEdge.None,-- Behaviour at vertical edges            },keymaps= {left="h",-- Swap leftdown="j",-- Swap downup="k",-- Swap upright="l",-- Swap right            },        },resize= {highlight="Todo",-- Highlight group for resize modedefault_resize_count=3,-- Default amount to resize windowskeymaps= {-- When resizing, the anchor is in the top-left corner of the window by defaultleft="h",-- Resize to the leftdown="j",-- Resize downup="k",-- Resize upright="l",-- Resize to the rightleft_botright="<c-h>",-- Resize left with bottom-right anchordown_botright="<c-j>",-- Resize down with bottom-right anchorup_botright="<c-k>",-- Resize up with bottom-right anchorright_botright="<c-l>",-- Resize right with bottom-right anchor            },        },    },})

There are three behaviour when moving or swapping towards an edge of the editor:

  • winmove.AtEdge.None: Do nothing.
  • winmove.AtEdge.Wrap: Wrap around to the opposite edge.
  • winmove.AtEdge.MoveToTab: Move to the previous/next tab if possible.

Autocommands

You can define autocommands that trigger when a mode starts and ends.

vim.api.nvim_create_autocmd("WinmoveModeStart", {callback=function(event)vim.print("Started"..event.data.mode.." mode")end,})vim.api.nvim_create_autocmd("WinmoveModeEnd", {callback=function(event)vim.print("Ended"..event.data.mode.." mode")end,})

Public API

Warning

Consider only the functions below part of the public API. All other functionsare subject to change.

winmove.configure

Configurewinmove. Also seeConfiguration.

winmove.version

Get the current version ofwinmove.

winmove.current_mode

Check which mode is currently active. Returns"move" (winmove.Mode.Move),"swap" (winmove.Mode.Swap),"resize" (winmove.Mode.Resize), ornil.

winmove.start_mode

Start a mode.

---@parammodewinmove.Modewinmove.start_mode(mode)-- Example:winmove.start_mode(winmove.Mode.Move)winmove.start_mode("swap")winmove.start_mode("move")winmove.start_mode(winmove.Mode.Resize)

winmove.stop_mode

Stop the current mode. Fails if no mode is currently active.

winmove.move_window

Move a window (does not need to be the current window). Seethisshowcase. This takes the cursor position in the windowinto account when moving.

---@paramwin_idinteger---@paramdirwinmove.Directionwinmove.move_window(win_id,dir)-- Example:winmove.move_window(1000,"k")

winmove.split_into

Split into a window (does not need to be the current window). Seethis showcase. This takes the cursor position in the windowinto account when splitting into.

---@paramwin_idinteger---@paramdirwinmove.Directionwinmove.split_into(win_id,dir)-- Example:winmove.split_into(1000,"l")

winmove.move_window_far

Move a window as far as possible in a direction (does not need to be the currentwindow). Seethis showcase.

---@paramwin_idinteger---@paramdirwinmove.Directionwinmove.move_window_far(win_id,dir)-- Example:winmove.move_window_far(1000,"h")

winmove.swap_window_in_direction

Swap a window in a given direction (does not need to be the current window). This takes the cursor position in the windowinto account when swapping.

---@paramwin_idinteger---@paramdirwinmove.Directionwinmove.swap_window_in_direction(win_id,dir)-- Example:winmove.swap_window_in_direction(1000,"j")winmove.swap_window_in_direction(1000,"l")

winmove.swap_window

Swap a window (does not need to be the current window). When called the firsttime, highlights the selected window for swapping. When called the second timewith another window will swap the two selected windows.

---@paramwin_idinteger---@paramdirwinmove.Directionwinmove.swap_window(win_id,dir)-- Example:winmove.swap_window(1000)winmove.swap_window(1000)

winmove.resize_window

Resize a window (does not need to be the current window). The window can beresized relative to an anchor in the top-left or bottom-right corner of thewindow.

Resizing respects the globalwinwidth/winminwidth andwinheight/winminheight options respectively, with the largest value takingpriority. If a window being resized would shrink another window's size beyondthe values of those options, the whole row/column of windows are adjusted exceptif all windows in the direction of resizing are as small as they can get.

Seethis showcase.

---@paramwin_idinteger---@paramdirwinmove.Direction---@paramcountinteger---@paramanchorwinmove.ResizeAnchor?winmove.resize_window(win_id,dir,count,anchor)-- Example:winmove.resize_window(1000,"j",3,winmove.ResizeAnchor.TopLeft)winmove.resize_window(1000,"l",1,winmove.ResizeAnchor.BottomRight)

Contributing

Seehere.

FAQ

Q: Why create this project?

A: There arealready a few projects for moving windowsbut none of them felt intuitive to me so I did the only rational thing adeveloper would do in this situation and created my own plugin. If any of theothers suit your needs then by all means use them.

Showcase

Important

Moving and swapping windows takes into account the cursor position of thecurrent window relative to the target window in the direction you are movingor swapping.

For example, if your cursor position is closest to the bottom of one window inthe target direction, the window will be moved below that window. Seethis example for a visual explanation.

Moving around windows

moving-around-windows.mov

Moving using relative cursor position

relative-cursor-position.mov

Splitting into windows

As opposed to moving windows, which will squeeze a window in between otherwindows, splitting into a window will move it next to a target window.

splitting-into-windows.mov

Swapping windows

swapping-windows.mov
swap-two-windows.mov

Resizing windows

resizing-windows.mov
resizing-and-pushing-windows.mov

Moving as far as possible in a direction

moving-as-far-as-possible-in-a-direction.mov

Move between tabs

moving-between-tabs.mov

Works with asynchronous output

async-output.mov

Similar projects

About

A neovim plugin that makes it easy to move, swap, and resize windows

Topics

Resources

License

Stars

Watchers

Forks

Packages

No packages published

[8]ページ先頭

©2009-2025 Movatter.jp