Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Refresh Vim buffer

Tags:

I'm editing HTML files. I use this keymap to launch firefox to preview the page:

map <F6> :update<CR>:silent !xdg-open %:p<CR>

But after this command, the Vim window becomes completely black. I need to scroll every line to make it appear again.

So I want to write a function to fresh the buffer. Here's what i did:

function! Refresh()                                                                                                                                               
    " code
    set noconfirm
    bufdo e!
    set confirm
endfunction

nmap <F5> :call Refresh()<CR>

I got the idea from this post. But it doesn't work.

like image 869
McBear Holden Avatar asked Aug 16 '11 12:08

McBear Holden


People also ask

How do I refresh my screen in vi?

The screen of Vim can be refreshed or redrawn by pressing Ctrl+l . If that does not work, use the command :redraw .

What is Vim buffer?

Buffers in vim are the in-memory text of files. Your window is a viewport on a buffer. You can switch between open buffers, this is similar to tabs in other editors. Vim does have a concept of tabs too, but they are slightly different, read more about tabs in the Windows section.


2 Answers

Use CtrlL to redraw the screen. You can also use :redraw.

Check the help on these.

like image 196
sidyll Avatar answered Sep 28 '22 09:09

sidyll


How about adding a "redraw" do your function (which does the same as ctrl-L)

:redr[aw][!]    Redraw the screen right now.  When ! is included it is
                cleared first.
                Useful to update the screen halfway executing a script
                or function.  Also when halfway a mapping and
                'lazyredraw' is set.
like image 40
Benj Avatar answered Sep 28 '22 11:09

Benj