(self, motion, count, searchChar=None, select=False)
Move cursor.
        Used by Normal and Visual mode
Move cursor.
        Used by Normal and Visual mode
Move cursor . Used by Normal and Visual mode
def _moveCursor(self, motion, count, searchChar=None, select=False):
        """ Move cursor.
        Used by Normal and Visual mode
        """
        cursor = self._qpart.textCursor()

        effectiveCount = count or 1

        moveMode = QTextCursor.KeepAnchor if select else QTextCursor.MoveAnchor

        moveOperation = {_b: QTextCursor.WordLeft,
                         _j: QTextCursor.Down,
                         _Down: QTextCursor.Down,
                         _k: QTextCursor.Up,
                         _Up: QTextCursor.Up,
                         _h: QTextCursor.Left,
                         _Left: QTextCursor.Left,
                         _BackSpace: QTextCursor.Left,
                         _l: QTextCursor.Right,
                         _Right: QTextCursor.Right,
                         _Space: QTextCursor.Right,
                         _w: QTextCursor.WordRight,
                         _Dollar: QTextCursor.EndOfBlock,
                         _End: QTextCursor.EndOfBlock,
                         _0: QTextCursor.StartOfBlock,
                         _Home: QTextCursor.StartOfBlock,
                         'gg': QTextCursor.Start,
                         _G: QTextCursor.End
                         }

        if motion == _G:
            if count == 0:  # default - go to the end
                cursor.movePosition(QTextCursor.End, moveMode)
            else:  # if count is set - move to line
                block = self._qpart.document().findBlockByNumber(count - 1)
                if not block.isValid():
                    return
                cursor.setPosition(block.position(), moveMode)
            self.moveToFirstNonSpace(cursor, moveMode)
        elif motion in moveOperation:
            for _ in range(effectiveCount):
                cursor.movePosition(moveOperation[motion], moveMode)
        elif motion in (_e, _E):
            for _ in range(effectiveCount):
                # skip spaces
                text = cursor.block().text()
                pos = cursor.positionInBlock()
                for char in text[pos:]:
                    if char.isspace():
                        cursor.movePosition(QTextCursor.NextCharacter, moveMode)
                    else:
                        break

                if cursor.positionInBlock() == len(text):  # at the end of line
                    # move to the next line
                    cursor.movePosition(QTextCursor.NextCharacter, moveMode)

                    # now move to the end of word
                if motion == _e:
                    cursor.movePosition(QTextCursor.EndOfWord, moveMode)
                else:
                    text = cursor.block().text()
                    pos = cursor.positionInBlock()
                    for char in text[pos:]:
                        if not char.isspace():
                            cursor.movePosition(QTextCursor.NextCharacter, moveMode)
                        else:
                            break
        elif motion == _B:
            cursor.movePosition(QTextCursor.WordLeft, moveMode)
            while cursor.positionInBlock() != 0 and \
                    (not cursor.block().text()[cursor.positionInBlock() - 1].isspace()):
                cursor.movePosition(QTextCursor.WordLeft, moveMode)
        elif motion == _W:
            cursor.movePosition(QTextCursor.WordRight, moveMode)
            while cursor.positionInBlock() != 0 and \
                    (not cursor.block().text()[cursor.positionInBlock() - 1].isspace()):
                cursor.movePosition(QTextCursor.WordRight, moveMode)
        elif motion == _Percent:
            # Percent move is done only once
            if self._qpart._bracketHighlighter.currentMatchedBrackets is not None:
                ((startBlock, startCol), (endBlock, endCol)) = \
                    self._qpart._bracketHighlighter.currentMatchedBrackets
                startPos = startBlock.position() + startCol
                endPos = endBlock.position() + endCol
                if select and \
                        (endPos > startPos):
                    endPos += 1  # to select the bracket, not only chars before it
                cursor.setPosition(endPos, moveMode)
        elif motion == _Caret:
            # Caret move is done only once
            self.moveToFirstNonSpace(cursor, moveMode)
        elif motion in (_f, _F, _t, _T):
            if motion in (_f, _t):
                iterator = self._iterateDocumentCharsForward(cursor.block(), cursor.columnNumber())
                stepForward = QTextCursor.Right
                stepBack = QTextCursor.Left
            else:
                iterator = self._iterateDocumentCharsBackward(cursor.block(), cursor.columnNumber())
                stepForward = QTextCursor.Left
                stepBack = QTextCursor.Right

            for block, columnIndex, char in iterator:
                if char == searchChar:
                    cursor.setPosition(block.position() + columnIndex, moveMode)
                    if motion in (_t, _T):
                        cursor.movePosition(stepBack, moveMode)
                    if select:
                        cursor.movePosition(stepForward, moveMode)
                    break
        elif motion in (_PageDown, _PageUp):
            cursorHeight = self._qpart.cursorRect().height()
            qpartHeight = self._qpart.height()
            visibleLineCount = qpartHeight / cursorHeight
            direction = QTextCursor.Down if motion == _PageDown else QTextCursor.Up
            for _ in range(int(visibleLineCount)):
                cursor.movePosition(direction, moveMode)
        elif motion in (_Enter, _Return):
            if cursor.block().next().isValid():  # not the last line
                for _ in range(effectiveCount):
                    cursor.movePosition(QTextCursor.NextBlock, moveMode)
                    self.moveToFirstNonSpace(cursor, moveMode)
        else:
            assert 0, 'Not expected motion ' + str(motion)

        self._qpart.setTextCursor(cursor)
def _moveCursor ( self , motion , count , searchChar = None , select = False ) : cursor = self . _qpart . textCursor ( ) effectiveCount = count or 1 moveMode = QTextCursor . KeepAnchor if select else QTextCursor . MoveAnchor moveOperation = { _b : QTextCursor . WordLeft , _j : QTextCursor . Down , _Down : QTextCursor . Down , _k : QTextCursor . Up , _Up : QTextCursor . Up , _h : QTextCursor . Left , _Left : QTextCursor . Left , _BackSpace : QTextCursor . Left , _l : QTextCursor . Right , _Right : QTextCursor . Right , _Space : QTextCursor . Right , _w : QTextCursor . WordRight , _Dollar : QTextCursor . EndOfBlock , _End : QTextCursor . EndOfBlock , _0 : QTextCursor . StartOfBlock , _Home : QTextCursor . StartOfBlock , 'gg' : QTextCursor . Start , _G : QTextCursor . End } if motion == _G : if count == 0 : # default - go to the end cursor . movePosition ( QTextCursor . End , moveMode ) else : # if count is set - move to line block = self . _qpart . document ( ) . findBlockByNumber ( count - 1 ) if not block . isValid ( ) : return cursor . setPosition ( block . position ( ) , moveMode ) self . moveToFirstNonSpace ( cursor , moveMode ) elif motion in moveOperation : for _ in range ( effectiveCount ) : cursor . movePosition ( moveOperation [ motion ] , moveMode ) elif motion in ( _e , _E ) : for _ in range ( effectiveCount ) : # skip spaces text = cursor . block ( ) . text ( ) pos = cursor . positionInBlock ( ) for char in text [ pos : ] : if char . isspace ( ) : cursor . movePosition ( QTextCursor . NextCharacter , moveMode ) else : break if cursor . positionInBlock ( ) == len ( text ) : # at the end of line # move to the next line cursor . movePosition ( QTextCursor . NextCharacter , moveMode ) # now move to the end of word if motion == _e : cursor . movePosition ( QTextCursor . EndOfWord , moveMode ) else : text = cursor . block ( ) . text ( ) pos = cursor . positionInBlock ( ) for char in text [ pos : ] : if not char . isspace ( ) : cursor . movePosition ( QTextCursor . NextCharacter , moveMode ) else : break elif motion == _B : cursor . movePosition ( QTextCursor . WordLeft , moveMode ) while cursor . positionInBlock ( ) != 0 and ( not cursor . block ( ) . text ( ) [ cursor . positionInBlock ( ) - 1 ] . isspace ( ) ) : cursor . movePosition ( QTextCursor . WordLeft , moveMode ) elif motion == _W : cursor . movePosition ( QTextCursor . WordRight , moveMode ) while cursor . positionInBlock ( ) != 0 and ( not cursor . block ( ) . text ( ) [ cursor . positionInBlock ( ) - 1 ] . isspace ( ) ) : cursor . movePosition ( QTextCursor . WordRight , moveMode ) elif motion == _Percent : # Percent move is done only once if self . _qpart . _bracketHighlighter . currentMatchedBrackets is not None : ( ( startBlock , startCol ) , ( endBlock , endCol ) ) = self . _qpart . _bracketHighlighter . currentMatchedBrackets startPos = startBlock . position ( ) + startCol endPos = endBlock . position ( ) + endCol if select and ( endPos > startPos ) : endPos += 1 # to select the bracket, not only chars before it cursor . setPosition ( endPos , moveMode ) elif motion == _Caret : # Caret move is done only once self . moveToFirstNonSpace ( cursor , moveMode ) elif motion in ( _f , _F , _t , _T ) : if motion in ( _f , _t ) : iterator = self . _iterateDocumentCharsForward ( cursor . block ( ) , cursor . columnNumber ( ) ) stepForward = QTextCursor . Right stepBack = QTextCursor . Left else : iterator = self . _iterateDocumentCharsBackward ( cursor . block ( ) , cursor . columnNumber ( ) ) stepForward = QTextCursor . Left stepBack = QTextCursor . Right for block , columnIndex , char in iterator : if char == searchChar : cursor . setPosition ( block . position ( ) + columnIndex , moveMode ) if motion in ( _t , _T ) : cursor . movePosition ( stepBack , moveMode ) if select : cursor . movePosition ( stepForward , moveMode ) break elif motion in ( _PageDown , _PageUp ) : cursorHeight = self . _qpart . cursorRect ( ) . height ( ) qpartHeight = self . _qpart . height ( ) visibleLineCount = qpartHeight / cursorHeight direction = QTextCursor . Down if motion == _PageDown else QTextCursor . Up for _ in range ( int ( visibleLineCount ) ) : cursor . movePosition ( direction , moveMode ) elif motion in ( _Enter , _Return ) : if cursor . block ( ) . next ( ) . isValid ( ) : # not the last line for _ in range ( effectiveCount ) : cursor . movePosition ( QTextCursor . NextBlock , moveMode ) self . moveToFirstNonSpace ( cursor , moveMode ) else : assert 0 , 'Not expected motion ' + str ( motion ) self . _qpart . setTextCursor ( cursor )