Reputation: 5901
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.
Upvotes: 27
Views: 26791
Reputation: 3101
Here is my bindings for previewing HTML documents with resolved empty screen issue:
autocmd BufRead *.html map <F5> :exe ':silent !open -a /Applications/Firefox.app %'<CR>:redr!<CR>
I prefer use autocmd
for bindings, because I can map same key for various things depending what type of file I am working in. For example with autocmd I can map F5 for previewing document in Firefox on html-files and map same key F5 on js-files for executing node.
Upvotes: 2
Reputation: 32428
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.
Upvotes: 8