Wikia

Vim Tips Wiki

Changes: Refresh screen while typing a command

Edit

Back to page

(Change <tt> to <code>, perhaps also minor tweak.)
m (GetVimCmdOutput() from genutils.vim: +comments, shorthand Exe())
 
(5 intermediate revisions by 2 users not shown)
Line 12: Line 12:
 
|category2=
 
|category2=
 
}}
 
}}
If you are using command line completion while showing matches (^D etc), often, the display scrolls in such a way that at least part of the text in the buffers is not visible anymore. If you want to redraw the screen, you have the option of switching to the command-window, which will refresh the screen anyway, but the following shows a way to redraw the screen without needing to do that.
+
If you are using command line completion while showing matches (<kbd>^D</kbd> etc.), often the display scrolls in such a way that at least part of the text in the buffers is not visible anymore. If you want to redraw the screen, you have the option of switching to the command-window, which will refresh the screen anyway, but the following shows a way to redraw the screen without needing to do that.
   
Install the genutils.vim {{script|id=1062}} plugin or just copy paste the GetVimCmdOutput() function into your vimrc, and create the following cmap:
+
Install the genutils.vim {{script|id=197}} plugin or just copy paste the <code>GetVimCmdOutput()</code> function into your vimrc, and create the following cmap:
<pre>
+
<source lang="vim">
 
cnoremap <C-X><C-L> <C-R>=GetVimCmdOutput('redraw')<CR>
 
cnoremap <C-X><C-L> <C-R>=GetVimCmdOutput('redraw')<CR>
</pre>
+
</source>
   
You can now type <code>^X^L</code> anytime on the command-line even in the middle of typing a new command. In normal mode you can always use <code>^L</code> directly so this is not needed, if you enter Ex mode through <code>gQ</code> command ({{help|gQ}}), you can use this to quickly redraw the screen.
+
You can now type <kbd>^X^L</kbd> anytime on the command-line even in the middle of typing a new command. In normal mode you can always use <kbd>^L</kbd> directly so this is not needed, if you enter Ex mode through <kbd>gQ</kbd> command ({{help|gQ}}), you can use this to quickly redraw the screen.
  +
  +
==GetVimCmdOutput() from genutils.vim==
  +
<small><small>(This function was minimally adapted from version 2.5 of genutils.vim, released 2009-09-17, still most current as of 2014-01-08)</small></small>
  +
<source lang="vim">
  +
" function wrapper for :execute (an Ex command that runs Ex commands)
  +
" adapted from genutils.vim 2.5 ( http://www.vim.org/scripts/script.php?script_id=197 )
  +
function! GetVimCmdOutput(cmd)
  +
let v:errmsg = ''
  +
let output = ''
  +
let _shortmess = &shortmess
  +
try
  +
set shortmess=
  +
redir => output
  +
silent exec a:cmd
  +
catch /.*/
  +
let v:errmsg = substitute(v:exception, '^[^:]\+:', '', '')
  +
finally
  +
redir END
  +
let &shortmess = _shortmess
  +
if v:errmsg != ''
  +
let output = ''
  +
endif
  +
endtry
  +
return output
  +
endfunction
  +
" shorthand Exe()
  +
let Exe=function('GetVimCmdOutput')
  +
</source>
   
 
==Comments==
 
==Comments==

Latest revision as of 15:25, January 18, 2014

Tip 952 Printable Monobook Previous Next

created 2005 · complexity basic · author hari_vim · version 6.0


If you are using command line completion while showing matches (^D etc.), often the display scrolls in such a way that at least part of the text in the buffers is not visible anymore. If you want to redraw the screen, you have the option of switching to the command-window, which will refresh the screen anyway, but the following shows a way to redraw the screen without needing to do that.

Install the genutils.vim script#197 plugin or just copy paste the GetVimCmdOutput() function into your vimrc, and create the following cmap:

cnoremap <C-X><C-L> <C-R>=GetVimCmdOutput('redraw')<CR>

You can now type ^X^L anytime on the command-line even in the middle of typing a new command. In normal mode you can always use ^L directly so this is not needed, if you enter Ex mode through gQ command (:help gQ), you can use this to quickly redraw the screen.

GetVimCmdOutput() from genutils.vimEdit

(This function was minimally adapted from version 2.5 of genutils.vim, released 2009-09-17, still most current as of 2014-01-08)

" function wrapper for :execute (an Ex command that runs Ex commands)
" adapted from genutils.vim 2.5 ( http://www.vim.org/scripts/script.php?script_id=197 )
function! GetVimCmdOutput(cmd)
  let v:errmsg = ''
  let output = ''
  let _shortmess = &shortmess
  try
    set shortmess=
    redir => output
    silent exec a:cmd
  catch /.*/
    let v:errmsg = substitute(v:exception, '^[^:]\+:', '', '')
  finally
    redir END
    let &shortmess = _shortmess
    if v:errmsg != ''
      let output = ''
    endif
  endtry
  return output
endfunction
" shorthand Exe()
let Exe=function('GetVimCmdOutput')

CommentsEdit

Around Wikia's network

Random Wiki