A very tiny vim in Texmacs

(This is supposed to be a toy :grinning: )Try the following code with your TeXmacs document.

Use C-] to entor the vim mode in the text mode. Esc key does not work. You can use 0, $, h, j, k, l to move your cursor around. I left the other keys unchanged.


(define-public vim-mode? #f)
(define (zzzz) vim-mode?)
(texmacs-modes
    (in-vim% (zzzz)))

(kbd-map
  (:mode in-text?)
  ("C-]" (set! vim-mode? (not vim-mode?))))
  

(tm-define (keyboard-press key time)
  (:require vim-mode?)
  (cond 
	((== key "$") (kbd-end-line))
	((== key "0") (kbd-start-line))
	((== key "h") (kbd-left))
	((== key "l") (kbd-right))
	((== key "j") (kbd-down))
	((== key "k") (kbd-up))
	(else (former key time))))
1 Like

Why do you say it is supposed to be a toy ? To me it’s more like “It will be total world domination”
A true modal editing experience inside TeXmacs could be awesome !
Knowing all the power it brings to text editors, imagine what a command, editing and normal mode could bring to Texmacs …

We can go further and push the reflexion towards what Spacemacs has done which is realy realy nice …

1 Like
  1. I could not find API relating to visual aids of locating the cursor. The cursor movement functionality would be very limited. Found some clue set-mouse-ponter may be useful. Experimenting later: Slow so that TeXmacs would not start.

  2. It seems that the operation on character, word, search (I am not really comfortable with searching via a box dialog) is not fully implemented yet from what I see from generic/generic-kbd.scm.

  3. I think the rest of the programming should be easy if one only wants a limited set of vim.

I spent last weekends on adding a little bit more keybindings to this.

See https://github.com/chxiaoxn/texmacs-vi-experiment

More goodies … thanks :slight_smile:

Don’t know if emacs’s Evil implementation could help in finding inspiration


https://www.emacswiki.org/emacs/Evil

My God, if Texmacs could benefit in a modal editing experience …

It also makes sense to include C-[, not C-], to enter vi-mode. By the way, I don’t know whether it is possible to use OOP to encapsulate such a mode, if it does not affect the efficiency. I heard that the performance of OOP as implemented in SICP is not good.