+func DefaultCommands() map[string]StrCommand {
+ return map[string]StrCommand{
+ "set": StrCommand{"Set", []Completion{OptionCompletion, NoCompletion}},
+ "bind": StrCommand{"Bind", []Completion{NoCompletion}},
+ "run": StrCommand{"Run", []Completion{NoCompletion}},
+ "quit": StrCommand{"Quit", []Completion{NoCompletion}},
+ "save": StrCommand{"Save", []Completion{NoCompletion}},
+ "replace": StrCommand{"Replace", []Completion{NoCompletion}},
+ "vsplit": StrCommand{"VSplit", []Completion{FileCompletion, NoCompletion}},
+ "hsplit": StrCommand{"HSplit", []Completion{FileCompletion, NoCompletion}},
+ "tab": StrCommand{"Tab", []Completion{FileCompletion, NoCompletion}},
+ "help": StrCommand{"Help", []Completion{HelpCompletion, NoCompletion}},
+ }
+}
+
+// Help tries to open the given help page in a horizontal split
+func Help(args []string) {
+ if len(args) < 1 {
+ // Open the default help if the user just typed "> help"
+ CurView().openHelp("help")
+ } else {
+ helpPage := args[0]
+ if _, ok := helpPages[helpPage]; ok {
+ CurView().openHelp(helpPage)
+ } else {
+ messenger.Error("Sorry, no help for ", helpPage)
+ }
+ }
+}
+
+// VSplit opens a vertical split with file given in the first argument
+// If no file is given, it opens an empty buffer in a new split
+func VSplit(args []string) {
+ if len(args) == 0 {
+ CurView().VSplit(NewBuffer([]byte{}, ""))
+ } else {
+ filename := args[0]
+ home, _ := homedir.Dir()
+ filename = strings.Replace(filename, "~", home, 1)
+ file, err := ioutil.ReadFile(filename)
+
+ var buf *Buffer
+ if err != nil {
+ // File does not exist -- create an empty buffer with that name
+ buf = NewBuffer([]byte{}, filename)
+ } else {
+ buf = NewBuffer(file, filename)
+ }
+ CurView().VSplit(buf)
+ }
+}
+
+// HSplit opens a horizontal split with file given in the first argument
+// If no file is given, it opens an empty buffer in a new split
+func HSplit(args []string) {
+ if len(args) == 0 {
+ CurView().HSplit(NewBuffer([]byte{}, ""))
+ } else {
+ filename := args[0]
+ home, _ := homedir.Dir()
+ filename = strings.Replace(filename, "~", home, 1)
+ file, err := ioutil.ReadFile(filename)
+
+ var buf *Buffer
+ if err != nil {
+ // File does not exist -- create an empty buffer with that name
+ buf = NewBuffer([]byte{}, filename)
+ } else {
+ buf = NewBuffer(file, filename)
+ }
+ CurView().HSplit(buf)
+ }
+}
+
+// NewTab opens the given file in a new tab
+func NewTab(args []string) {
+ if len(args) == 0 {
+ CurView().AddTab(true)
+ } else {
+ filename := args[0]
+ home, _ := homedir.Dir()
+ filename = strings.Replace(filename, "~", home, 1)
+ file, _ := ioutil.ReadFile(filename)
+
+ tab := NewTabFromView(NewView(NewBuffer(file, filename)))
+ tab.SetNum(len(tabs))
+ tabs = append(tabs, tab)
+ curTab++
+ if len(tabs) == 2 {
+ for _, t := range tabs {
+ for _, v := range t.views {
+ v.ToggleTabbar()
+ }
+ }
+ }