@@ -53,6 +53,7 @@ document.addEventListener("DOMContentLoaded", function () {
5353 vimModeElement . classList . add ( "unknown" ) ;
5454 }
5555 }
56+
5657 // Function to show relative line numbers
5758 function showRelativeLines ( cm ) {
5859 const lineNum = cm . getCursor ( ) . line + 1 ;
@@ -65,25 +66,8 @@ document.addEventListener("DOMContentLoaded", function () {
6566 ) ;
6667 }
6768
68- var editor = CodeMirror . fromTextArea ( document . getElementById ( "code" ) , {
69- lineNumbers : true ,
70- mode : "text/x-csrc" ,
71- keyMap : "vim" ,
72- matchBrackets : true ,
73- showCursorWhenSelecting : true ,
74- theme : getPreferredTheme ( ) ,
75- lineWrapping : true , // Optional: enable line wrapping if desired
76- } ) ;
77-
78- editor . on ( "cursorActivity" , showRelativeLines ) ;
79- editor . focus ( ) ;
80-
81- var vimMode = document . getElementById ( "vim-mode" ) ;
82- CodeMirror . on ( editor , "vim-mode-change" , function ( e ) {
83- updateVimMode ( e , vimMode ) ;
84- } ) ;
85-
86- CodeMirror . commands . save = async function ( ) {
69+ // Function to save the content
70+ async function saveContent ( ) {
8771 let status = "No changes were made." ;
8872
8973 try {
@@ -120,7 +104,32 @@ document.addEventListener("DOMContentLoaded", function () {
120104 status = "Error saving: " + error . message ;
121105 }
122106 document . getElementById ( "status" ) . innerText = status ;
123- } ;
107+ }
108+
109+ var editor = CodeMirror . fromTextArea ( document . getElementById ( "code" ) , {
110+ lineNumbers : true ,
111+ mode : "text/x-csrc" ,
112+ keyMap : "vim" ,
113+ matchBrackets : true ,
114+ showCursorWhenSelecting : true ,
115+ theme : getPreferredTheme ( ) ,
116+ lineWrapping : true , // Optional: enable line wrapping if desired
117+ } ) ;
118+
119+ editor . on ( "cursorActivity" , showRelativeLines ) ;
120+ editor . focus ( ) ;
121+
122+ // Custom vim Ex commands
123+ CodeMirror . Vim . defineEx ( "x" , "" , function ( ) {
124+ saveContent ( ) ;
125+ } ) ;
126+
127+ var vimMode = document . getElementById ( "vim-mode" ) ;
128+ CodeMirror . on ( editor , "vim-mode-change" , function ( e ) {
129+ updateVimMode ( e , vimMode ) ;
130+ } ) ;
131+
132+ CodeMirror . commands . save = saveContent ;
124133
125134 // Listen for changes in the prefers-color-scheme media query
126135 window . matchMedia ( "(prefers-color-scheme: dark)" ) . addListener ( ( e ) => {
0 commit comments