Is there a way to save the value of a setting to a buffer or a file? For example, when I type

:set guifont

It displays the setting I want to use but as soon as I start typing in the buffer it disappears. I'm trying to do this using gvim on Windows but I suspect the answer will be generic.


There are too(?) many ways to do this.

1) :mkexrc

:mkexrc [file]

writes all mappings and changed options to a file (.exrc by default)

2) Option window


opens a buffer with extra UI to change options (the code is in $VIMRUNTIME/optwin.vim); of course, the buffer is accessible by standard Vim commands too

3) Expression register


will insert the value of option guifont into the current buffer

4) execute()

nnoremap <silent><leader>x :-1put=trim(execute(input(\":\")))<CR>

press <leader>x and then input any Vim command (e.g. set); the output will be inserted into the current buffer

Anything else I forgot?

  • 1
    Wow. Very comprehensive. Feb 21 '20 at 22:58
  • 2
    3) can be put "=&guifont<CR>p or :put =&guifont
    – D. Ben Knoble
    Feb 22 '20 at 1:13

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.