Coder Social home page Coder Social logo

scratch.vim's Introduction

Scratch.vim

Unobtrusive scratch window. Inspired by scratch.vim, enhanced.

doc/scratch.png

Features

  • Scratch window automatically hides when inactive.
  • Mappings allow easy note taking and selection pasting directly into the scratch buffer.
  • Optional persistence across sessions.

Quickstart

  • :Scratch opens a scratch buffer in a new window (by default using the top 20% of the screen, configurable via g:scratch_height and g:scratch_top). The window automatically closes when inactive (and its contents will be available the next time it is opened).
  • gs in normal mode opens the scratch window and enters insert mode. The scratch window closes when you leave insert mode. This is especially useful for quick notes.
  • gs in visual mode pastes the current selection (character-wise, line-wise or block-wise) into the scratch buffer.

Both above mappings have a gS variant that clears the scratch buffer before opening it. Note also that the auto-closing features require hidden to be set (and can be disabled via the g:scratch_autohide option).

By default the contents of the scratch window are lost when leaving Vim. To enable cross-session persistence, set the g:scratch_persistence_file option to a valid file path.

See :help Scratch for the full list of configuration options and more details on each.

Installation

With Pathogen.vim:

git clone https://github.com/mtth/scratch.vim ~/.vim/bundle/scratch

With Vundle.vim:

Plugin 'mtth/scratch.vim'

With NeoBundle.vim:

NeoBundle 'mtth/scratch.vim'

Otherwise simply copy the folders into your .vim directory.

scratch.vim's People

Contributors

b- avatar jakebasile avatar mattn avatar mtth avatar sagarjauhari 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  avatar

scratch.vim's Issues

Window switching oddities

I'm new to Vim, so maybe I'm doing this wrong, but...

When I try to switch from the Scratch window to the window I was on, I get weird behavior.

  1. Open code file for editing. vim hello.cpp
  2. Open scratch window. :Scratch
  3. Switch back to code file: Ctrl+w Ctrl+w
  4. Switch back to scratch window: Ctrl+w Ctrl+w

Step 4 does nothing, and step 3 does a strange thing: The scratch window visibly disappears, but the resulting hello.cpp window is mistakenly labelled "Scratch" [New File].

I come from Emacs, where the *scratch* buffer is builtin, designed to be more persistent (by default, open until Emacs quits) and it's natural for users to switch back and forth between scratch and the code file they're editing.

Is there a way we can make Vim Scratch switch back and forth more naturally like in Emacs?

Relative height setting (50%, 100%), not just absolute units

When I launch :Scratch, I would like for it to open a new window using the top half of the current window height (50%), not "10 lines", which may be too few on large monitors, and too many on tiny monitors.

I would really like to have an option to launch :Scratch at 100% height, which would be an awesome replacement for the default Vim splash screen!

Feature Request: Ability to source scratch file

Not quite sure how this would look, but sometimes it would be nice to write a lil vim script in a scratch buffer and source it.

Perhaps a command like :ScratchSource which would write to the persistence file and immediately source it?

Feature Request - Floating Window Support

NeoVim has introduced floating windows a while ago. It would be awesome if this plugin would offer a configuration option to make use of this? The height and width options could then be reused for this window and must not be exclusive anymore. What do you think?

Add an option to open the scratch in normal mode

I'm using scratch.vim as a buffer for to-do items, so I find myself opening it and going straight to normal mode to navigate the items and mark them as done or move them around.

It would be nice to be able to configure scratch to use normal mode by default instead of insert mode.

I'm willing to send a PR if you think this would be a useful feature.

Thanks!

Toggle Scratch Window?

Is it possible to toggle the scratch window?

What I mean by this is:

  • I'm typing away and I want to open the scratch window but not have my cursor move to the scratch window. I look at the scratch window, a few moments pass, then I want to close it without moving my cursor to the window and hitting :q.

Is there a way I can achieve this?

Thanks

Scratch without opening window

Curious your thoughts on this idea:

The ability to save to the scratchpad without ever showing the window.
It could just automatically append to the end, sort of like how scratch-selection-reuse does now, but everything would happen in the background.

Along with that could be word motions.

For example: gsap could scratch the paragraph)

Would be glad to help with a PR.

Persist buffer

When close the current vim process and create another one by open other file, buffer should not be cleared unless gS entered.

Wrong repository location in Readme

The Readme has a wrong repo location in installation section.

$ cd ~/.vim/bundle
$ git clone https://github.com/mtth/locate.vim

Should be:

$ cd ~/.vim/bundle
$ git clone https://github.com/mtth/scratch.vim

Support setting file type in scratch window

Support setting/detecting the file type in the scratch window, so if for example I set g:scratch_persistence_file to ~/.scratch.md, it would be nice to have markdown syntax enabled in the scratch window. Or alternatively introduce a variable like g:scratch_syntax so I can set the syntax manually in my .vimrc.

Vim closes when switching to scratch buffer

Thanks for the plugin!

After opening and closing the scratch buffer, the scratch buffer is still in the buffer list. When returning to the scratch buffer, e.g. with :b __Scratch__, vim closes. This is especially annoying when cycling through buffers, only to have vim exit when you hit the scratch buffer.

Does not read persistent file

I've set the persistent file in my vimrc:

let g:scratch_persistence_file = "~/.vim/scratch.vim"

After writing to the scratch (gs, write, <Esc>), and after closing vim, the scratch file has the correct content. When I restart vim, my scratch file is still correct. When starting a scratch with gs the scratch window is empty. But the scratch file is still correct. The scratch file becomes different is just when the scratch window is closed, i.e. escaping insert mode.

Do you know what's going on?

No license

There doesn't seem to be a license mentioned anywhere.

autohide doesn't work

20151204_1539

.vimrc

" Scratch
let g:scratch_autohide = 1
nmap <F2> :ScratchPreview<CR>

I just open Scratch by "gs", enter text and ESC โ€“ it goes back to my document and trying to close (hide) scratch, but I get error

scratch window doesnot close on leaving InsertMode

Hello,
I have configured g:scratch_persistence_file option and set the g:scratch_autohide and g:scratch_insert_autohide to 1. When I open vim for the first time and triggered the scratch buffer by pressing 'gs' the scratch window open but when I press the scratch window doesnot close. Because the bufwinnr(bufnr('#')) will return -1. But if I close the scratch window manually and open it agian and then press , it will close automatically.

image
The above screenshot shows the piece of code where the problem is there.

Thank you.

Strange error on closing scratch

I have the odd problem, that if I have open NERDTree, then edit the scratch buffer and go back I can't. I get the following error and I can't do anything so I have to close the whole session. But is not occur always. It seems like only if I have a file open in a buffer (not with Startify and NERDTree reproducable.
I checked the close_window function and this occurs directly after this line. By my debugging messages, no further instruction is executed, not even the if-condition blocks is leaved. So it seems to be cause by writing the persistent file. But the configured file ("~/.local/share/nvim/scratch.md") exists and it can write as stated in the log below. But then there is file mysterious FileUpdate function I can't neither in this repo, nor at NERDTree's. An also I've no idea where the stated invalid path comes from. This is the project folder, but... I was also not able to find any missing endif by linting. Unfortunately my knowledge is not enough to know how I can display the loaded functions by Vim through the SNR's.
Any idea why this happens?

"~/.local/share/nvim/scratch.md" 3L, 10C written
Error detected while processing function <SNR>318_FileUpdate[13]..99[3]..102:
line   18:
E605: Exception not caught: NERDTree.InvalidArgumentsError: Invalid path = /home/thore/brainbot/projects/trustlines-network/blockchain/__Scratch__
Error detected while processing function <SNR>272_close_window:
line    5:
E171: Missing :endif

Add `ScratchToggle` Command

I wanted to set up a scratch buffer that is toggle-able (like :ScratchPreview) and automatically focuses my cursor on the buffer when opening it. I was expecting a :ScratchToggle command, but did not find one.

Here's my current config for scratch in lazy.nvim:

return {
  "mtth/scratch.vim",

  keys = {
    { "<leader>sp", ":ScratchPreview<CR>", mode = "n", noremap = true, silent = true },
    { "<leader>sp", ":ScratchSelection<CR>", mode = "v", noremap = true, silent = true },
  },

  init = function()
    vim.g.scratch_no_mappings = 1
    vim.g.scratch_persistence_file = "~/scratchpad/vim-scratchpad.txt"
    vim.g.scratch_autohide = 0
  end,
}

When I want to open a scratch window, I use <leader>sp. This opens a scratch buffer, but I have to manually move the cursor there.

Any chance this could be added to the plugin?

Open the scratch window into a system command

I've set my filetype to javascript and tried to load execute the scratch window with node, like this: !node %. It tried to open the __Scratch__ file. Is there a way to make it open the file specified in g:scratch_persistence_file?

Let me know if I can help with a pull request, I don't know where to look for a solution.

Error on first exit

error-screenshot

It errors on exiting out for first time, from the next time on it works without any errors

My config

nnoremap <silent><leader>s :ScratchPreview<cr>
let g:scratch_height = 20
let g:scratch_top = 1
let g:scratch_persistence_file = '/tmp/scratch.vim'
let g:scratch_autohide = &hidden
let g:scratch_filetype = 'markdown'

Weird scratch_persistence_file behavior

Hi,

I clearly must be doing something wrong, or I don't understand how persistence is supposed to work.

Given this vimrc:

set runtimepath^=~/.vim/plugged/scratch.vim
set nocompatible
filetype plugin indent on

let g:scratch_persistence_file=$HOME . '/scratch_test'

I can't get anything to show up in ~/scratch_test.

$ vim -u ~/.minimal_vimrc

Open scratch buffer with 'gs'
Enter text / esc / c-w o / :q

~/scratch_test remains empty.

I've confirmed g:scratch_persistence_file is getting correctly set to scratch_test in my home directory (as an absolute path).

What am I doing wrong?

Thanks,
Lance

Allowing for custom name of the scratch buffer

For now, the scratch buffer is named __Scratch__
I would like to change that to gain support for the vim-markdown plugin by renaming it scratch.md for example.
I've seen in the code that it might be easily implementable if the name of a scratch buffer doesn't always have to be equal to __Scratch__
I will try to do a pull request as soon as possible.
Also, I might help you on other issues as I really like the concept of a scratch window for example for todo list perposes (which is why I wanted markdown in the first place)

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.