1package ui23import (4 tea "charm.land/bubbletea/v2"56 "src.rest/cat/012/internal/config"7)89// SetVimKeys turns vim keys on or off, as the setting does, for callers10// that know the user's choice at startup.11func (m *Model) SetVimKeys(on bool) {12 if m.prefs.vim != on {13 m.vim = vimState{}14 }15 m.prefs.vim = on16}1718func init() {19 register(&command{id: "settings.vim", macro: macroNever, title: "Vim keys",20 desc: "Move with hjkl, counts and operators (dd, yy, p), visual selection with v and V, and : commands",21 run: func(m *Model) tea.Cmd {22 m.SetVimKeys(!m.prefs.vim)23 m.note = "Vim keys off: typing replaces the cell, as in Sheets"24 if m.prefs.vim {25 m.note = "Vim keys on: i or Enter edits, : runs a command, F1 lists the keys"26 }27 m.saveKeymap()28 return nil29 },30 checked: func(m *Model) bool { return m.prefs.vim },31 })32}3334// saveKeymap writes the keymap option to the config file, so vim keys35// stay as chosen next time.36func (m *Model) saveKeymap() {37 value := "default"38 if m.prefs.vim {39 value = "vim"40 }41 c := m.prefs.Config42 if c == nil || c.Path == "" {43 return44 }45 c.Override("keymap", value, "File > Settings > Vim keys")46 if err := config.SetInFile(c.Path, "keymap", value); err != nil {47 m.fail("Couldn't save the keymap: " + err.Error())48 }49}