I have multiple vim global variables declared in .vimrc file like

let g:wiki_list = {some dictionary ...}

I am able to echo its output in vim exec window using :echo wiki_list BUT

How do I read/insert the echoed output in vim text window?

I want to print the output of :echo some_vim_global_variable in vim text window under my cursor position?


There are two different ways I can think of to do this.

  1. You can use the "= register. This is like a mini vim calculator that evaluates a string as vimscript code, and returns it in a register. This register can be accessed in normal or insert mode.

    In normal:


    In insert:


    <expr> can be any string of vimscript that evaluates to a string. So in order to get your dictionary variable to evaluate to a string, your <expr> should be

  2. You can use the redir command. This basically captures all command line output and stores it into a specified register. Here is sample usage:

    :redir @a
    :echo g:wiki_list

    I'm not a huge fan of this approach because 1) you'll end up with a bunch of extra newlines, and 2) You have to remember to call :redir end afterwards, otherwise your register will get cluttered with a bunch of extra output you don't necessarily want.

  • Excellent answer! Thankyou so much :) 1st approach came as total new surprise to me. Thx a ton. Is there a way I can take a look at your .vimrc file in-case you might have published it somewhere? – Avi Mehenwal May 6 '18 at 17:53
  • @avi Glad I could help! My dotfiles are here – DJMcMayhem May 6 '18 at 19:09

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.