Sublime Forum

How can I make a helloworld that takes a parameter?

#1

Suppose I have a plugin

import sublime, sublime_plugin

class ExampleCommand(sublime_plugin.TextCommand):
def run(self, edit):
self.view.insert(edit, self.view.sel()[0].begin(), “Hello, World!”)
#self.view.insert(edit, 0, “Hello, World!”)

I can run view.run_command(“example”)

But suppose I want to pass a parameter , a string, and display that, or hello world followed by that.

How would I do that?

Thanks

0 Likes

#2
import sublime, sublime_plugin

class ExampleCommand(sublime_plugin.TextCommand):
	def run(self, edit, text=''):
		self.view.insert(edit, self.view.sel()[0].begin(), "Hello, World! " + text )

Then call with view.run_command('example',args={'text':'test'})

1 Like