Sublime Forum

Get and modify entire contents of a view

#1

Hi,

How do I get and modify (replace) the entire contents of a view?

Thanks in advance!

0 Likes

#2

Never mind, I got it. Here is is for anyone else that might be interested (assuming your’re using a WindowCommand):

[code]# get the current contents of the file
body = self.window.active_view().substr(sublime.Region(0, self.window.active_view().size()))

begin edit

edit = self.window.active_view().begin_edit()

deleted the contents of the file

self.window.active_view().erase(edit, sublime.Region(0, self.window.active_view().size()))

insert new html

self.window.active_view().insert(edit, 0, html)

end edit

self.window.active_view().end_edit(edit)[/code]

0 Likes