Skip to content

Commit

Permalink
Added counts to tTfF; selection with v
Browse files Browse the repository at this point in the history
  • Loading branch information
Chris White committed Apr 24, 2018
1 parent 311b44c commit 938f601
Show file tree
Hide file tree
Showing 4 changed files with 40 additions and 16 deletions.
Binary file modified VimWord.dotm
Binary file not shown.
9 changes: 5 additions & 4 deletions frmGrabKeys.frm
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,7 @@ Attribute VB_Exposed = False
' Copyright (c) 2018 Chris White. All rights reserved.
' 2018-04-06 chrisw Initial version
' 2018-04-20 chrisw Major expansion/rewrite
' 2018-04-24 chrisw Change "s" to "v" (visual selection)

Option Explicit
Option Base 0
Expand Down Expand Up @@ -121,6 +122,8 @@ Public Enum VimOperator
voChange ' c
voDelete ' d
voYank ' y
voSelect ' v Select <motion>.

'voSwitchCase ' ~/g~ unimpl
' TODO Maybe a custom titlecase on g~?
'voLowercase ' gu unimpl
Expand All @@ -136,8 +139,6 @@ Public Enum VimOperator
'voDefineFold ' zf No plans to implement this.
'voCallFunc ' g@ No plans to implement this.

' Custom (not in Vim)
voSelect ' s Select <motion>. Mostly for use as a debugging aid.
End Enum 'VimOperator

'Public Enum VimForce ' adverb - No plans to implement this
Expand Down Expand Up @@ -286,7 +287,7 @@ Private Sub UserForm_Initialize()
PC_INTRANS = 2

PAT_TRANS = _
"([cdys])?([1-9][0-9]*)?([ai]([wWsp])|[fFtT](.)|[hjklGwebWEB\)\(\}\{])"
"([cdyv])?([1-9][0-9]*)?([ai]([wWsp])|[fFtT](.)|[hjklGwebWEB\)\(\}\{])"
' | | | | |
RESM_TVERB = 0 '-^ | | | |
RESM_COUNT2 = 1 ' --------' | | |
Expand Down Expand Up @@ -379,7 +380,7 @@ Private Function ProcessHit_(hit As VBScript_RegExp_55.Match) As Boolean
Case "c": VOperator = voChange
Case "d": VOperator = voDelete
Case "y": VOperator = voYank
Case "s": VOperator = voSelect
Case "v": VOperator = voSelect ' V, i.e., visual selection - just like in Vim.
Case Else: Exit Function
End Select

Expand Down
Binary file modified frmGrabKeys.frx
Binary file not shown.
47 changes: 35 additions & 12 deletions mVimWord.bas
Original file line number Diff line number Diff line change
Expand Up @@ -5,12 +5,13 @@ Attribute VB_Name = "mVimWord"
' Thanks to https://glts.github.io/2013/04/28/vim-normal-mode-grammar.html
' 2018-04-06 chrisw Initial version
' 2018-04-20 chrisw Split vimRunCommand off VimDoCommand
' 2018-04-24 chrisw Added counts to tTfF

Option Explicit
Option Base 0

Public Sub VimDoCommand_About()
MsgBox "VimWord version 0.2.1, 2018-04-20. Copyright (c) 2018 Christopher White. " & _
MsgBox "VimWord version 0.2.2, 2018-04-24. 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
Expand Down Expand Up @@ -94,7 +95,7 @@ Public Sub vimRunCommand( _
Dim colldir As WdCollapseDirection
colldir = wdCollapseEnd ' by default

Dim idx As Long
Dim idx As Long, result As Long

Select Case motion
Case vmLeft: proczone.MoveStart wdCharacter, -count: colldir = wdCollapseStart
Expand All @@ -119,26 +120,48 @@ Public Sub vimRunCommand( _

Case vmCharForward:
colldir = wdCollapseEnd
If proczone.MoveEndUntil(arg, wdForward) <> 0 Then
For idx = 1 To count
If proczone.MoveEndUntil(arg, wdForward) = 0 Then Exit For
proczone.MoveEnd wdCharacter, 1 ' f => to and including
End If
Next idx

Case vmCharBackward:
colldir = wdCollapseStart
If proczone.MoveEndUntil(arg, wdBackward) <> 0 Then
proczone.MoveStart wdCharacter, -1 ' F => to and including
End If

Case vmTilForward: proczone.MoveEndUntil arg, wdForward: colldir = wdCollapseEnd
Case vmTilBackward: proczone.MoveStartUntil arg, wdBackward: colldir = wdCollapseStart
For idx = 1 To count
If proczone.MoveStartUntil(arg, wdBackward) = 0 Then Exit For
proczone.MoveStart wdCharacter, -1 ' F => to and including
Next idx

Case vmTilForward:
colldir = wdCollapseEnd
result = proczone.MoveEndUntil(arg, wdForward)
For idx = 2 To count
If result = 0 Then Exit For
proczone.MoveEnd wdCharacter, 1
result = proczone.MoveEndUntil(arg, wdForward)
Next idx

Case vmTilBackward:
colldir = wdCollapseStart
result = proczone.MoveStartUntil(arg, wdBackward)
For idx = 2 To count
If result = 0 Then Exit For
proczone.MoveStart wdCharacter, -1
result = proczone.MoveStartUntil(arg, wdBackward)
Next idx

Case vmWordForward: proczone.MoveEnd wdWord, count: colldir = wdCollapseEnd
Case vmWordForward:
colldir = wdCollapseEnd
proczone.MoveEnd wdWord, count

Case vmEOWordForward:
colldir = wdCollapseEnd
proczone.MoveEnd wdWord, count
proczone.MoveEndWhile CSET_WS, wdBackward

Case vmWordBackward: proczone.MoveStart wdWord, -count: colldir = wdCollapseStart
Case vmWordBackward:
colldir = wdCollapseStart
proczone.MoveStart wdWord, -count

Case vmNonblankForward:
colldir = wdCollapseEnd
Expand Down

0 comments on commit 938f601

Please sign in to comment.