https://resources.wolframcloud.com/FunctionRepository/resources/VimGraph/ * Wolfram.com * WolframAlpha.com * WolframCloud.com Wolfram Function Repository Instant-use add-on functions for the Wolfram Language Primary Navigation [ ] * Categories + Core Language & Structure + Data Manipulation & Analysis + Visualization & Graphics + Machine Learning + Symbolic & Numeric Computation + Higher Mathematical Computation + Strings & Text + Graphs & Networks + Images + Geometry + Sound & Video + Knowledge Representation & Natural Language + Time-Related Computation + Geographic Data & Computation + Scientific and Medical Data & Computation + Engineering Data & Computation + Financial Data & Computation + Social, Cultural & Linguistic Data + Notebook Documents & Presentation + User Interface Construction + System Operation & Setup + External Interfaces & Connections + Cloud & Deployment + Repository Tools + Programming Utilities + Just For Fun + Wolfram Physics Project + Random Function + NEW Recent Functions + Alphabetical List * Submit a New Function * Learn More about Wolfram Language Function Repository Resource: VimGraph Source Notebook Construct a graph of simple Vim-style movements in text Contributed by: Pavel Hajek ResourceFunction["VimGraph"][text] returns a graph with letters as vertices and Vim-style movements as edges. Details and Options Vim is a cult-favorite text editor known for its modal editing--In Normal mode, certain keys are mapped to movements forward or backward to the nearest pattern, reducing keystroke distance and enabling fast editing without using the mouse. The following simple Vim movements are supported: Shortcut Movement Description h / l Move one character left / right on the same line k / j Move one character up / down; jumps to end of target line if shorter than current horizontal position w / b Jump to the beginning of the next / previous word, across lines e Jump to the end of the next word, across lines ^/$ Move to the beginning/end of the current line ResourceFunction["VimGraph"] allows the options "IncludedVimMovements", "StringPattern" and "CustomPatterns", it is possible to restrict to specific Vim movements or define new movements, respectively. Also supported are Graph options. Examples Example Notebook * Open in Cloud * Download Notebook Basic Examples (2) Vim graph for the movements: up, right, and to the beginning of the next word, respectively: In ResourceFunction["VimGraph"]["How do\nI exit Vim?", [1]:= "IncludedVimMovements" -> {"k", "l", "w"}] Out[1]= [4c19fa57990e9505] The same, with nicer formatting: ResourceFunction["VimGraph"]["How do\nI exit Vim?", In "IncludedVimMovements" -> {"k", "l", "w"}, VertexSize -> Large, [2]: VertexStyle -> LightYellow, VertexLabelStyle -> Directive[Bold, = Large], EdgeLabels -> "EdgeTag", EdgeLabelStyle -> Directive [Bold, Orange, Medium]] Out[2]= [65fa3286d43b120d] Scope (3) Returns a minimal sequence of keystrokes needed to move from one letter to another: In With[{g = ResourceFunction["VimGraph"][ "Chuck Norris\nwrites [3]: his DNA\n in Vim. In\nNormal mode."]}, HighlightGraph[g, = Subgraph[g, FindShortestPath[g, {1, 1}, {4, 10}]], EdgeLabels -> "EdgeTag", EdgeLabelStyle -> Directive[Bold, Large]]] Out[3]= [2c749a0811cbb83c] --------------------------------------------------------------------- Illustrates the relationship between the maximum keystroke distance required to navigate between two letters in a text and the number of randomly inserted newlines: BarChart[ Table[Mean[ Table[GraphDiameter[ ResourceFunction In ["VimGraph"][ StringInsert[#, "\n", RandomSample[Range [4]: [StringLength[#]], n]] & @ StringTake[ExampleData[{"Text", = "DeclarationOfIndependence"}], 200]]], {m, 1, 10}]], {n, 1, 20}]] Out[4]= [609ec5dd57aa542c] --------------------------------------------------------------------- Use the "CustomPatterns" option to define new movements by passing a string pattern to "StringPattern", with optional shortcuts for jumping forward or backward to the nearest match: ResourceFunction[ "VimGraph"]["How is your\n mode today?\nNormal mode\nInsert mode\nNormal mode\nVisual mode\nInsert mode", "IncludedVimMovements" -> {}, "CustomPatterns" -> { <| In "StringPattern" -> "Normal", "Forward" -> "n", "Backward" -> "N" [5]: |>, <|"StringPattern" -> "Insert", "Forward" -> "i"|>, <| = "StringPattern" -> "Visual", "Backward" -> "V"|>} , VertexSize -> Large, VertexStyle -> LightYellow, VertexLabelStyle -> Directive[Bold, Medium], EdgeLabels -> "EdgeTag", EdgeLabelStyle -> Directive[Bold, Orange, Medium]] Out[5]= [54f89788582dd1a7] Publisher Pavel Hajek Requirements Wolfram Language 13.0 (December 2021) or above Version History * 1.0.0 - 27 October 2025 Related Symbols * StringPosition License Information This work is licensed under a Creative Commons Attribution 4.0 International License * Send a message about this function * Discuss on Wolfram Community * Top (c) 2025 Wolfram. All rights reserved. * Legal & Privacy Policy * Contact Us * WolframAlpha.com * WolframCloud.com