Giter Club home page Giter Club logo

undoquit.vim's Introduction

Build Status

This plugin attempts to solve the issue of quitting a window, and then realizing you actually need it moments later. It simply lets you "undo" the quit, similar to the "Restore Tab" functionality of a browser.

For a visual demo, there's a screencast on youtube

Requirements

Requires Vim at version 7.4 or above.

Download and Install

The easiest way to install the plugin is with a plugin manager:

If you use one, just follow the instructions in its documentation.

You can install the plugin yourself using Vim's packages functionality by cloning the project (or adding it as a submodule) under ~/.vim/pack/<any-name>/start/. For example:

mkdir -p ~/.vim/pack/andrewradev/start
cd ~/.vim/pack/andrewradev/start
git clone https://github.com/andrewradev/undoquit.vim.git

# to generate documentation tags:
vim -u NONE -c "helptags undoquit.vim/doc" -c q

This should automatically load the plugin for you when Vim starts. Alternatively, you can add it to ~/.vim/pack/<any-name>/opt/ instead and load it in your .vimrc manually with:

packadd undoquit

If you'd rather not use git, you can download the files from the "releases" tab and unzip them in the relevant directory: https://github.com/AndrewRadev/undoquit.vim/releases.

Usage

Whenever you execute a :quit on a window, that window's position is stored in a stack. Pressing <c-w>u (or executing the :Undoquit command) is going to "undo" that quit, restoring the window to its original position.

Note that this only works on buffers that are "listed", so it won't restore the quickfix window or the NERDTree, but it's assumed that you don't really need this functionality for these kinds of buffers.

Working with tabs

The <c-w>u mapping will restore windows you've closed one by one, regardless if they're in the current tab, or in a different one. To restore a full tab's worth of windows, you can use <c-w>U. That mapping will:

  • Restore all windows that you've previously closed in the current tab, if there are any
  • Restore all windows in a previously-closed tab

However, it's important to note that the plugin only keeps track of windows closed with :quit or ZZ. It uses the QuitPre event to store a window's information before it's closed, and there is no similar event for other methods of closing windows.

This means that the :tabclose command will not save the closed windows in history. In case this is a command that's part of your workflow, the plugin provides the :UndoableTabclose command that should be usable in the same way as the built-in :tabclose:

:UndoableTabclose[!]
:{count}UndoableTabclose[!]
:UndoableTabclose[!] {count}

The plugin also doesn't work for <c-w>c, since that mapping doesn't throw a QuitPre autocommand either. If you use it, you could make it work by calling the undoquit "save history" function manually:

nnoremap <c-w>c :call undoquit#SaveWindowQuitHistory()<cr><c-w>c

Settings

Use the g:undoquit_mapping variable to set the mapping for the window restore action. Example:

" default: <c-w>u
let g:undoquit_mapping = '_u'

Use g:undoquit_tab_mapping for the keybinding that restores a full tab of windows:

" default: <c-w>U
let g:undoquit_tab_mapping = '_U'

Set any of these variables to an empty string to avoid defining a mapping at all. You could still use the plugin via its commands, :Undoquit and :UndoquitTab.

Contributing

Pull requests are welcome, but take a look at CONTRIBUTING.md first for some guidelines.

undoquit.vim's People

Contributors

andrewradev avatar maniac-en 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

Watchers

 avatar  avatar  avatar  avatar

undoquit.vim's Issues

Files in directories containing spaces cannot be re-opened.

The error message reads:

Only one file name allowed: leftabove vsplit /Path/to/directory with spaces/someFile.txt

Looks like it should be an easy fix.

Thank you for being so responsive on issues for undoquit and all your other plugins - they definitely help me to be more productive.

Undo quit when restart vim

Good plugin!

I want this plugin could support a new feature:
Persist the opened files when :qa and restore all windows when restart vim and press c-w U

Thanks!

Restore cursor position

The position of the cursor could restored to the position before the buffer was closed. That would add an extra level of awesomeness to this script.

Thanks for making this btw. This should exist as a vim feature!

windows closed by commands such as `<c-w>c`

The undoclosewin.vim plugin also restores windows closed by commands such as <c-w>c or ZZ. Is it outside of the scope of undo_quit_.vim or is it impossible to implement this reliably ?

If not, how about allowing undoquit to undo closes of windows by such commands as well (perhaps by taking a look at undoclosewin.vim's implementation) ?

Split restores to wrong side

The plugin partially works for me, but windows are not getting restored to the same positions. This seems to be independent of the splitright setting.

STR

  1. Open a file nvim a.txt
  2. Split :vsp
  3. Open another file in the split :e b.txt
  4. Close the window :q
  5. Restore the window :Undoquit

Expected: window restores as it was

Actual: window restore, but swapped with the other split

I'm also seeing issues such as: :vsp, then :sp, if I close the original window (the one that wasn't split by :sp) and then restore, it re-splits horizontally instead of vertically.

In Terminal Vim, receiving error:

Error detected while processing /Users/myUsername/.vim/bundle/undoquit.vim/plugin/undoquit.vim:
line 13:
E216: No such group or event: QuitPre * call undoquit#SaveWindowQuitHistory()

Do you use MacVim/gvim? It works perfectly in MacVim for me, but not terminal vim.

remap <c-w>p

How about overwriting optionally p to let it act correspondingly to <c-^> for buffers in case the previous window now happens to be closed?

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.