VimGraph

8 hours ago 2

Basic Examples (2) 

Vim graph for the movements: up, right, and to the beginning of the next word, respectively:

In[1]:=

ResourceFunction["VimGraph"]["How do\nI exit Vim?", "IncludedVimMovements" -> {"k", "l", "w"}]

Out[1]=

The same, with nicer formatting:

In[2]:=

ResourceFunction["VimGraph"]["How do\nI exit Vim?", "IncludedVimMovements" -> {"k", "l", "w"}, VertexSize -> Large, VertexStyle -> LightYellow, VertexLabelStyle -> Directive[Bold, Large], EdgeLabels -> "EdgeTag", EdgeLabelStyle -> Directive[Bold, Orange, Medium]]

Out[2]=

Scope (3) 

Returns a minimal sequence of keystrokes needed to move from one letter to another:

In[3]:=

With[{g = ResourceFunction["VimGraph"][
    "Chuck Norris\nwrites 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]=


Illustrates the relationship between the maximum keystroke distance required to navigate between two letters in a text and the number of randomly inserted newlines:

In[4]:=

BarChart[
 Table[Mean[
   Table[GraphDiameter[
     ResourceFunction["VimGraph"][
      StringInsert[#, "\n", RandomSample[Range[StringLength[#]], n]] & @
       StringTake[ExampleData[{"Text", "DeclarationOfIndependence"}], 200]]], {m, 1, 10}]], {n, 1, 20}]]

Out[4]=


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:

In[5]:=

ResourceFunction[
 "VimGraph"]["How is your\n mode today?\nNormal mode\nInsert mode\nNormal mode\nVisual mode\nInsert mode", "IncludedVimMovements" -> {}, "CustomPatterns" -> {
   <|"StringPattern" -> "Normal", "Forward" -> "n", "Backward" -> "N"|>,
   <|"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]=

Read Entire Article