diff --git a/VimWord.dotm b/VimWord.dotm index 15a183a..af052fe 100755 Binary files a/VimWord.dotm and b/VimWord.dotm differ diff --git a/frmGrabKeys.frm b/frmGrabKeys.frm index 9786908..0f306d6 100755 --- a/frmGrabKeys.frm +++ b/frmGrabKeys.frm @@ -27,6 +27,8 @@ Attribute VB_Exposed = False ' Len>0 checks. I had a situation in which a non-match ' returned "" rather than Empty. ' Added special-case code for 0 after nonempty count2. +' 2018-06-29 chrisw Changed X from `dh` to voDrop. +' `dh` is still available if you need it. ' NOTE: the consolidated reference is in :help normal-index @@ -155,6 +157,7 @@ Public Enum VimOperator voDelete ' d voYank ' y voSelect ' v Select . + voDrop ' X (Not in Vim): delete without yanking 'voSwitchCase ' ~/g~ unimpl ' TODO Maybe a custom titlecase on g~? @@ -349,11 +352,12 @@ Private Sub UserForm_Initialize() ' DO NOT MODIFY HERE. If you need to change it, modify vim-regex.txt ' and re-run re2vba.pl. + RE_PAT = _ "^(([ ]?)([1-9][0-9]*)?(([ ]?)(([HMLGhjklwbWB\x28\x29\x7b\x7d" & _ - "]|g?[eE0\^\$]|[fFtT](.))|(gW)?g?[\*#]|g?[pP])|([cdyv])([1-9]" & _ - "[0-9]*)?(([\[\]])?([ai])([wWsp])|[fFtT](.)|[HMLGhjklwbWB\x28" & _ - "\x29\x7b\x7d]|g?[eE0\^\$])|([xX\.])))$" & _ + "]|g?[eE0\^\$]|[fFtT](.))|(gW)?g?[\*#]|g?[pP])|([cdyvX])([1-9" & _ + "][0-9]*)?(([\[\]])?([ai])([wWsp])|[fFtT](.)|[HMLGhjklwbWB\x2" & _ + "8\x29\x7b\x7d]|g?[eE0\^\$])|([x\.])))$" & _ "" RESM_SPACEONE = 1 RESM_COUNT1 = 2 @@ -503,9 +507,6 @@ Private Function ProcessHit_(hit As VBScript_RegExp_55.Match) As Boolean ' `x`: alias to `dl` Case "x": tverb = "d": target = "l" - ' `X`: alias to `dh` - Case "X": tverb = "d": target = "h" - Case Else: Exit Function End Select End If @@ -516,8 +517,8 @@ Private Function ProcessHit_(hit As VBScript_RegExp_55.Match) As Boolean If Len(hit.SubMatches(RESM_IVERB)) > 0 Then ' intransitive - Debug.Print "Intransit.", IIf(Len(hit.SubMatches(RESM_IMOTION)) = 0, "-", hit.SubMatches(RESM_IMOTION)), _ - hit.SubMatches(RESM_IVERB), hit.SubMatches(RESM_ITEXT) + 'Debug.Print "Intransit.", IIf(Len(hit.SubMatches(RESM_IMOTION)) = 0, "-", hit.SubMatches(RESM_IMOTION)), _ + ' hit.SubMatches(RESM_IVERB), hit.SubMatches(RESM_ITEXT) If Len(hit.SubMatches(RESM_IMOTION)) > 0 Then If ProcessMotion_(hit.SubMatches(RESM_IMOTION)) Then @@ -558,7 +559,7 @@ Private Function ProcessHit_(hit As VBScript_RegExp_55.Match) As Boolean ElseIf Len(tverb) > 0 Then ' transitive - Debug.Print "Transitive", tverb, hit.SubMatches(RESM_COUNT2), Left(target, 1), hit.SubMatches(RESM_OBJTYPE), hit.SubMatches(RESM_TTEXT) + 'Debug.Print "Transitive", tverb, hit.SubMatches(RESM_COUNT2), Left(target, 1), hit.SubMatches(RESM_OBJTYPE), hit.SubMatches(RESM_TTEXT) ' Operator Select Case tverb @@ -566,6 +567,7 @@ Private Function ProcessHit_(hit As VBScript_RegExp_55.Match) As Boolean Case "d": VOperator = voDelete Case "y": VOperator = voYank Case "v": VOperator = voSelect ' V, i.e., visual selection - just like in Vim. + Case "X": VOperator = voDrop ' X, repurposed from Vim. Case Else: Exit Function End Select @@ -642,7 +644,7 @@ Private Sub Update() DotCount_ = 1 ' In case we have a . this time Do - Debug.Print "Checking -" & CStr(Keys) & "-" + 'Debug.Print "Checking -" & CStr(Keys) & "-" times_through = times_through + 1 Set matches = RE_ACT.Execute(Keys) @@ -650,7 +652,7 @@ Private Sub Update() Set hit = matches.Item(0) If hit.SubMatches.count < 1 Then Exit Do - Debug.Print "Matched:", hit.Value + 'Debug.Print "Matched:", hit.Value done = ProcessHit_(hit) ' Assigns DotCount_ on a `.` 'If done Then Debug.Print "", "operator count:", VOperatorCount diff --git a/frmGrabKeys.frx b/frmGrabKeys.frx index 9265c14..bbab492 100755 Binary files a/frmGrabKeys.frx and b/frmGrabKeys.frx differ diff --git a/mVimWord.bas b/mVimWord.bas index 36534c8..df35ed0 100755 --- a/mVimWord.bas +++ b/mVimWord.bas @@ -12,6 +12,9 @@ Attribute VB_Name = "mVimWord" ' 2018-05-07 chrisw gp/gP now paste unformatted text; added ninja-feet ' 2018-05-10 chrisw Fixed whitespace classes used for text objects ' 2018-06-07 chrisw Hack in voDelete/voChange for strange Word behaviour. +' 2018-06-26 chrisw ip: don't select whole table cell. It still doesn't +' work with a count, though, and I'm not sure why. E.g., 2vip +' 2018-06-29 chrisw Added voDrop; bugfix in ip ' General comment: Word puts the cursor between characters; Vim puts the ' cursor on characters. This makes quite a difference. I may need @@ -20,14 +23,15 @@ Attribute VB_Name = "mVimWord" Option Explicit Option Base 0 -' Storage for the last command, to support `.`. This only lasts until +' Storage for the last command, to support `.`. NOTE: This only lasts until ' the next time the VBA project is reset. -' Public since it's used by frmGrabKeys; here so that it will stick around. +' Public since it's used by frmGrabKeys; here so that it will stick around +' after a frmGrabKeys instance is unloaded. Public VimLastCommand_ As String ' Public Sub VimDoCommand_About() - MsgBox "VimWord version 0.2.12, 2018-06-07. Copyright (c) 2018 Christopher White. " & _ + MsgBox "VimWord version 0.2.14, 2018-06-29. Copyright (c) 2018 Christopher White. " & _ "All Rights Reserved. Licensed CC-BY-NC-SA 4.0 (or later).", _ vbOKOnly + vbInformation, "About VimWord" End Sub 'VimDoCommand_About @@ -378,6 +382,17 @@ Private Sub vimRunCommand( _ Case vmIPara proczone.Expand wdParagraph If count > 1 Then proczone.MoveEnd wdParagraph, count - 1 + + ' If we were in a table, the end marker is now selected. + ' The marker is a Chr(13) & Chr(7), but MoveEndWhile won't move + ' over it. Therefore, test for it and skip it manually. + If proczone.Tables.count >= 1 Then + If proczone.Cells.count >= 1 Then + If Right(proczone.Text, 1) = ChrW(7) Then + proczone.MoveEnd wdCharacter, -1 + End If + End If + End If proczone.MoveEndWhile Chr(13), -1 ' Only the last Chr(13) coll = False @@ -411,7 +426,7 @@ Private Sub vimRunCommand( _ If proczone.Start <> proczone.End Then proczone.Copy GoTo VRC_Finally - Case voDelete, voChange: + Case voDelete, voChange, voDrop: If proczone.Start <> proczone.End Then ' Word doesn't always delete the whole selection! Dim endr As Range @@ -419,7 +434,11 @@ Private Sub vimRunCommand( _ endr.Collapse wdCollapseEnd endr.MoveEnd wdCharacter, 1 - proczone.Cut + If oper = voDrop Then + proczone.Delete + Else + proczone.Cut + End If If endr.Characters.count > 1 Then ' something strange happened If endr.Characters.First = ChrW(13) Then diff --git a/vim-regex.txt b/vim-regex.txt index 5fcca65..d9bb909 100755 --- a/vim-regex.txt +++ b/vim-regex.txt @@ -60,7 +60,7 @@ textobj (?[\[\]])? (?# Ninja-feet marker) (?[wWsp]) (?# Type of text object) # Transitive: verb, count, object, object type, text -trans (?[cdyv]) (?# TVERB: what to do) +trans (?[cdyvX]) (?# TVERB: what to do) (?[1-9][0-9]*)? (?# Count after the operator) (? (?# What to work on) (?<=textobj)| (?# Text objects) @@ -70,6 +70,8 @@ trans (?[cdyv]) (?# TVERB: what to do) # Transitive abbreviations: x, ., ... . These are the end of the entry --- # nothing comes after them. -trans-abbr (?[xX\.]) +# Note: I have repurposed `X` as delete-without-yank, so it is no longer +# a synonym for `dh`. +trans-abbr (?[x\.]) # vi: set ts=4 sts=4 sw=4 et ai ff=unix ft=sh: #