Git Product home page Git Product logo

visual-split.vim's Introduction

visual-split.vim

Vim plugin to control splits with visual selections or text objects

Motivation

Ever found yourself scrolling back up to the same overview comment while reading some complicated function? Or while referring to a similar implementation while writing a new function?

This is a good use for Vim splits: You have one split for reference and another one where you jump around and get work done.

But setting up the splits in the first place can be tiresome, especially if you want to make the reference split as small as possible to not waste any precious space.

Features

This plugin adds some convenient commands and mappings to resize an existing split or create a new split showing exactly what you need to see.

Commands

Resize

If you already have multiple splits open and want to resize one of them to only show a certain range of lines, follow these steps:

  1. Visually select the lines you want to see
  2. Type :VSResize to execute the VSResize ex command on the selected range
  3. The split will now only show those lines

Split

If you want to create a new split to show a certain range you could create a split and then resize it as described above. But there is a quicker way:

  1. Visually select the lines you want to split out
  2. Type :VSSplit, :VSSplitAbove or :VSSplitBelow to create the split
  3. A new split will be created showing the selected lines

Notes on the different commands:

  • :VSSplit will respect your 'splitbelow' setting
  • :VSSplitAbove will always create a new split above the current window
  • :VSSplitBelow will always create a new split below the current window

As with all commands that work on ranges, invoking them on a visual selection is only one way of many:

  • Resize split to show everything between marks a and b with :'a,'bVSResize
  • Split out range between line above cursor containing foo and line below cursor containing bar with :?foo?,/bar/VSSplit

Mappings

Mappings will not overwrite your existing mappings.

For the most common use case of working on visual selections there are some visual mode mappings provided:

  • <C-W>gr - resize split to visual selection (similar to :VSResize)
  • <C-W>gss - split out visual selection (similar to :VSSplit)
  • <C-W>gsa - split out visual selection above (similar to :VSSplitAbove)
  • <C-W>gsb - split out visual selection below (similar to :VSSplitBelow)

Note: <C-W> means press and hold the Control key while pressing W (similar to other window related commands)

For example, to split out to the paragraph around the cursor, just type:

vip<C-W>gss

To work on text objects directly, the same mappings are provided in operator pending mode. So this also works:

<C-W>gssip

Remapping

For easier remapping, <Plug> mappings are provided. Change the key sequences below and put them into your vimrc:

Visual-mode:

xmap <C-W>gr  <Plug>(Visual-Split-VSResize)
xmap <C-W>gss <Plug>(Visual-Split-VSSplit)
xmap <C-W>gsa <Plug>(Visual-Split-VSSplitAbove)
xmap <C-W>gsb <Plug>(Visual-Split-VSSplitBelow)

Operator-pending mode:

nmap <C-W>gr  <Plug>(Visual-Split-Resize)
nmap <C-W>gss <Plug>(Visual-Split-Split)
nmap <C-W>gsa <Plug>(Visual-Split-SplitAbove)
nmap <C-W>gsb <Plug>(Visual-Split-SplitBelow)

Installation

Use your favorite plugin manager.

  • NeoBundle

    NeoBundle 'wellle/visual-split.vim'
  • Vundle

    Bundle 'wellle/visual-split.vim'
  • Vim-plug

    Plug 'wellle/visual-split.vim'
  • Pathogen

    git clone git://github.com/wellle/visual-split.vim.git ~/.vim/bundle/visual-split.vim

What's next?

This plugin was written in an afternoon to fill a personal need. I might add related functionality in the future that I consider useful and related additions. If you like this plugin and want more of it, please open an issue and let me know what you would like to see.

Especially suggestions for better command names or more concise mappings would be very appreciated.

visual-split.vim's People

Contributors

bobwhitelock avatar rendom avatar wellle 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

visual-split.vim's Issues

Does not take into account the scroll offset

I have my scrolloff set to 3, so when I select an area visually and do <C-W>gsa it shows three lines above where I wanted the split to start.

Is there some way the plugin could account for this and scroll itself into the proper position?

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.