Petr Skocik
Petr Skocik

Reputation: 60117

Making a new, modified buffer closable with just bd

In Get the output of `:map` into a buffer I learned I can use

  redir @a | silent map | redir END | new | silent put a

to view the output of map in a buffer, which is convenient because it's long and I want to be able to navigate it vim-style.

However, the new buffer requires :bd! for closing, because it's modified. Is it possible to set it so it's closable with just :bd?

(I know it's just one character but I'd rather be careful with :bd! because I don't want to accidentally lose actual data (map output is disposable))

Upvotes: 2

Views: 42

Answers (2)

romainl
romainl

Reputation: 196789

This command opens a new scratch buffer in a new vertical window and populates it with the output of the given Ex command:

function! Redir(cmd)
    redir => output
    execute a:cmd
    redir END
    vnew
    setlocal nobuflisted buftype=nofile bufhidden=wipe noswapfile
    call setline(1, split(output, "\n"))
endfunction

command! -nargs=1 Redir silent call Redir(<f-args>)

You can close the window or delete the buffer however you want.

Usage:

:Redir map

Upvotes: 2

Ganesh
Ganesh

Reputation: 3456

Add this one line to

set hidden

your vimrc.

Upvotes: -1

Related Questions