-
-
Notifications
You must be signed in to change notification settings - Fork 27
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Fixed behavior of h, l and I, gg commands added #15
Changes from 1 commit
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -12,7 +12,7 @@ | |
|
||
|
||
VIM_COMMAND_PREFIX = ":!/?" | ||
VIM_PREFIX = "cdfFmrtTyzZ@'`\"<>" | ||
VIM_PREFIX = "cdfFgmrtTyzZ@'`\"<>" | ||
RE_VIM_PREFIX_STR = r"^(\d*)([{prefixes}].|[^{prefixes}0123456789])(.*)$" | ||
RE_VIM_PREFIX = re.compile(RE_VIM_PREFIX_STR.format(prefixes=VIM_PREFIX)) | ||
SYMBOLS_REPLACEMENT = { | ||
|
@@ -52,10 +52,18 @@ def _move_cursor(self, movement, repeat=1): | |
editor.setTextCursor(cursor) | ||
self._widget.update_vim_cursor() | ||
|
||
def _editor_cursor(self): | ||
"""returns editor's cursor object""" | ||
editor = self._widget.editor() | ||
cursor = editor.textCursor() | ||
return cursor | ||
|
||
# %% Movement | ||
def h(self, repeat=1): | ||
# TODO: stop at start of line | ||
self._move_cursor(QTextCursor.Left, repeat) | ||
cursor = self._editor_cursor() | ||
if not cursor.atBlockStart(): | ||
self._move_cursor(QTextCursor.Left) | ||
if repeat > 1: self.h(repeat-1) | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Please put the code block in a new line, even if it's small it will be more clear. (same below) |
||
|
||
def j(self, repeat=1): | ||
self._move_cursor(QTextCursor.Down, repeat) | ||
|
@@ -64,8 +72,10 @@ def k(self, repeat=1): | |
self._move_cursor(QTextCursor.Up, repeat) | ||
|
||
def l(self, repeat=1): | ||
# TODO: stop at end of line | ||
self._move_cursor(QTextCursor.Right, repeat) | ||
cursor = self._editor_cursor() | ||
if not cursor.atBlockEnd(): | ||
self._move_cursor(QTextCursor.Right) | ||
if repeat > 1: self.l(repeat-1) | ||
|
||
def w(self, repeat=1): | ||
self._move_cursor(QTextCursor.NextWord, repeat) | ||
|
@@ -79,14 +89,19 @@ def DOLLAR(self, repeat=1): | |
def ZERO(self, repeat=1): | ||
self._move_cursor(QTextCursor.StartOfLine) | ||
|
||
def G(self, repeat): | ||
editor = self._widget.editor() | ||
editor.go_to_line(repeat) | ||
self._widget.update_vim_cursor() | ||
|
||
def G(self, repeat=1): | ||
self._move_cursor(QTextCursor.Start) | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more.
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I actually wasn't aware that you could jump lines that way! I thought G and gg were different because I only used their default uses: G goes to last line, gg goes to first line. And actually I mixed their default uses too! Whoops, I'll get on it |
||
|
||
def gg(self, repeat=1): | ||
self._move_cursor(QTextCursor.End) | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Is is the same as |
||
|
||
# %% Insertion | ||
def i(self, repeat): | ||
self._widget.editor().setFocus() | ||
|
||
def I(self, repeat): | ||
self._move_cursor(QTextCursor.StartOfLine) | ||
self._widget.editor().setFocus() | ||
|
||
def a(self, repeat): | ||
self.l() | ||
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Useful helper, thanks. Could you use it in
_move_cursor()
above too ?