www.williamhiggsbarrister.com.au

   
     Call Clerk on (02) 9336 5399
Tap To Call

Vibe Coding for lawyers

I want to tell my fellow lawyer coders about this new thing called Vibe Coding.

So, what is it? Vibe coding is an AI-powered development approach where a human communicates with an AI agent in natural language to generate functional code, focusing on high-level ideas and outcomes rather than intricate coding details. Popularised by OpenAI co-founder Andrej Karpathy in early 2025, this method allows users to describe desired app functionality and rely on the AI to handle implementation, accelerating development and making it accessible to those with limited programming experience.

Vibe coding allows you as a developer to concentrate on the creative aspects of app building, like user experience and functionality, instead of getting bogged down in technical specifics. Technical specifics always slowed down my coding and left me frustrated.

You essentially prompt your way to producing beautiful code.

Here is an example. Using your favourite AI product such as ChatGPT or Claude use the prompt

"create me a VBA macro that searches through a word document to find Capitalised terms." 

You will receive something like the visual basic code below, as your output from the prompt
Option Explicit

' =========================
' CAPITALISED TERMS FINDER
' =========================
' Scans the main body of the active document for Title-Case terms (1–5 words),
' skips first word of each sentence, deduplicates, counts, and reports:
' Term | Count | First Page | First Context.
'
' Run: FindCapitalisedTerms_Report
' -------------------------

Sub FindCapitalisedTerms_Report()
Dim results As Object: Set results = CreateObject("Scripting.Dictionary")
Dim stopList As Object: Set stopList = BuildStopList()

' ---- Regex setup (safe pattern) ----
Dim rx As Object: Set rx = CreateObject("VBScript.RegExp")
rx.Global = True
rx.IgnoreCase = False
rx.Multiline = True
' 1–5 Title-Case words; allow internal hyphen or apostrophe (straight or curly)
' NOTE: hyphen is first in the char class to avoid "invalid range" errors.
rx.Pattern = "\b(?:[A-Z][a-z]{2,}(?:[-’'][A-Za-z]{2,})?)(?:\s+(?:[A-Z][a-z]{2,}(?:[-’'][A-Za-z]{2,})?)){0,4}\b"

Dim doc As Document: Set doc = ActiveDocument

' Work only in the main story (avoids header/footer/textbox surprises)
Dim bodyRng As Range
Set bodyRng = doc.StoryRanges(wdMainTextStory)

Dim s As Range, scanRng As Range
Dim m As Object, matches As Object
Dim term As String
Dim startInDoc As Long, lengthInDoc As Long, pg As Long
Dim ctx As String

For Each s In bodyRng.Sentences
If s.words.Count > 1 Then
Set scanRng = s.Duplicate
' Skip the first word (most common false positive)
On Error Resume Next
scanRng.Start = s.words(2).Start
If Err.Number <> 0 Then
Err.Clear
On Error GoTo 0
GoTo NextSentence
End If
On Error GoTo 0

' Guard Execute with Test (avoids odd range errors)
If rx.Test(scanRng.Text) Then
Set matches = rx.Execute(scanRng.Text)
For Each m In matches
term = Trim$(m.Value)
If ShouldKeepTerm(term, stopList) Then
startInDoc = scanRng.Start + m.FirstIndex
lengthInDoc = m.Length

Dim hitRng As Range
Set hitRng = doc.Range(startInDoc, startInDoc + lengthInDoc)

' Page lookup can fail in unusual views/objects; guard it.
On Error Resume Next
pg = hitRng.Information(wdActiveEndAdjustedPageNumber)
If Err.Number <> 0 Then
Err.Clear: pg = 0
End If
On Error GoTo 0

ctx = GetContextSnippet(doc, startInDoc, lengthInDoc, 45)

If results.Exists(term) Then
Dim parts() As String
parts = Split(results(term), "|", 3)
parts(0) = CStr(CLng(parts(0)) + 1)
results(term) = Join(parts, "|")
Else
results.Add term, "1|" & CStr(pg) & "|" & ctx
End If
End If
Next m
End If
End If
NextSentence:
Next s

RenderReport results
MsgBox "Capitalised-terms report created.", vbInformation
End Sub

' -------------------------
' Filtering
' -------------------------
Private Function ShouldKeepTerm(ByVal term As String, ByVal stopList As Object) As Boolean
Dim t As String: t = Trim$(term)

' Exclude ALL-CAPS tokens outright
If t = UCase$(t) Then ShouldKeepTerm = False: Exit Function

' Single word?
If InStr(t, " ") = 0 Then
If Len(t) < 3 Then ShouldKeepTerm = False: Exit Function
If stopList.Exists(t) Then ShouldKeepTerm = False: Exit Function
Else
' For multi-word terms, keep if at least one word isn't on the stop list
Dim words() As String, i As Long, ok As Boolean
words = Split(t, " ")
ok = False
For i = LBound(words) To UBound(words)
If Not stopList.Exists(words(i)) Then ok = True: Exit For
Next i
If Not ok Then ShouldKeepTerm = False: Exit Function
End If

ShouldKeepTerm = True
End Function

Private Function BuildStopList() As Object
Dim d As Object: Set d = CreateObject("Scripting.Dictionary")
Dim arr As Variant
arr = Array( _
"The", "A", "An", "And", "Or", "Of", "For", "To", "In", "On", "At", "By", _
"I", "You", "We", "He", "She", "They", _
"Monday", "Tuesday", "Wednesday", "Thursday", "Friday", "Saturday", "Sunday", _
"January", "February", "March", "April", "May", "June", "July", "August", "September", "October", "November", "December", _
"Section", "Schedule", "Figure", "Table")
Dim i As Long
For i = LBound(arr) To UBound(arr): d(arr(i)) = True: Next i
Set BuildStopList = d
End Function

' -------------------------
' Context & utilities
' -------------------------
Private Function GetContextSnippet(doc As Document, ByVal startInDoc As Long, ByVal lengthInDoc As Long, ByVal wing As Long) As String
Dim L As Long, R As Long
L = MaxLng(0, startInDoc - wing)
R = MinLng(doc.Content.End, startInDoc + lengthInDoc + wing)

Dim leftR As Range, rightR As Range, hitR As Range
Set hitR = doc.Range(startInDoc, startInDoc + lengthInDoc)
Set leftR = doc.Range(L, startInDoc)
Set rightR = doc.Range(startInDoc + lengthInDoc, R)

GetContextSnippet = "…" & CleanOneLine(leftR.Text) & "[" & _
CleanOneLine(hitR.Text) & "]" & _
CleanOneLine(rightR.Text) & "…"
End Function

Private Function CleanOneLine(ByVal s As String) As String
s = Replace$(s, vbCr, " ")
s = Replace$(s, vbLf, " ")
s = Replace$(s, Chr$(160), " ")
Do While InStr(s, " ") > 0
s = Replace$(s, " ", " ")
Loop
CleanOneLine = Trim$(s)
End Function

Private Function MinLng(a As Long, b As Long) As Long
If a < b Then MinLng = a Else MinLng = b
End Function

Private Function MaxLng(a As Long, b As Long) As Long
If a > b Then MaxLng = a Else MaxLng = b
End Function

' -------------------------
' Report rendering
' -------------------------
Private Sub RenderReport(results As Object)
Dim outDoc As Document: Set outDoc = Documents.Add
outDoc.Activate

Selection.Style = wdStyleHeading1
Selection.TypeText "Capitalised Terms"
Selection.TypeParagraph
Selection.Style = wdStyleNormal
Selection.TypeText "Generated: " & Format(Now, "yyyy-mm-dd hh:nn")
Selection.TypeParagraph: Selection.TypeParagraph

Dim n As Long: n = results.Count
If n = 0 Then
Selection.TypeText "No capitalised terms found (given current heuristics)."
Exit Sub
End If

Dim tbl As Table
Set tbl = outDoc.Tables.Add(Selection.Range, n + 1, 4)
With tbl
.Style = "Table Grid"
.Cell(1, 1).Range.Text = "Term"
.Cell(1, 2).Range.Text = "Count"
.Cell(1, 3).Range.Text = "First Page"
.Cell(1, 4).Range.Text = "First Context"
.Rows(1).Range.Bold = True
End With

' Alphabetical sort for a traditional, predictable report
Dim keys() As String, i As Long, row As Long, k As Variant, parts() As String
ReDim keys(0 To n - 1)
i = 0
For Each k In results.keys: keys(i) = CStr(k): i = i + 1: Next k
QuickSort keys, LBound(keys), UBound(keys)

row = 2
For i = LBound(keys) To UBound(keys)
parts = Split(results(keys(i)), "|", 3)
tbl.Cell(row, 1).Range.Text = keys(i)
tbl.Cell(row, 2).Range.Text = parts(0)
tbl.Cell(row, 3).Range.Text = parts(1)
tbl.Cell(row, 4).Range.Text = parts(2)
row = row + 1
Next i

tbl.Columns(1).PreferredWidthType = wdPreferredWidthPercent: tbl.Columns(1).PreferredWidth = 25
tbl.Columns(2).PreferredWidthType = wdPreferredWidthPercent: tbl.Columns(2).PreferredWidth = 10
tbl.Columns(3).PreferredWidthType = wdPreferredWidthPercent: tbl.Columns(3).PreferredWidth = 10
tbl.Columns(4).PreferredWidthType = wdPreferredWidthPercent: tbl.Columns(4).PreferredWidth = 55
End Sub

' Simple case-insensitive quicksort for string arrays
Private Sub QuickSort(arr() As String, ByVal first As Long, ByVal last As Long)
Dim i As Long, j As Long, pivot As String, temp As String
i = first: j = last
pivot = arr((first + last) \ 2)
Do While i <= j
Do While StrComp(arr(i), pivot, vbTextCompare) < 0: i = i + 1: Loop
Do While StrComp(arr(j), pivot, vbTextCompare) > 0: j = j - 1: Loop
If i <= j Then
temp = arr(i): arr(i) = arr(j): arr(j) = temp
i = i + 1: j = j - 1
End If
Loop
If first < j Then QuickSort arr, first, j
If i < last Then QuickSort arr, i, last
End Sub




How to use

-Open your Word doc which includes the contract (which includes Defined Terms).

-Press Alt+F11 → Insert → Module → paste the code from the AI product you used.

-Close the editor and run View → Macros → FindCapitalisedTerms_Report. A new document appears with a table: Term | Count | First Page | First Context.
with the
  • Amazing. This would have taken weeks without Vibe coding!