Skip to content
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

Merged
merged 4 commits into from
Dec 6, 2016
Merged
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
35 changes: 25 additions & 10 deletions spyder_vim/vim_widget.py
Original file line number Diff line number Diff line change
Expand Up @@ -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 = {
Expand Down Expand Up @@ -52,10 +52,18 @@ def _move_cursor(self, movement, repeat=1):
editor.setTextCursor(cursor)
self._widget.update_vim_cursor()

def _editor_cursor(self):
Copy link
Contributor

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 ?

"""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)
Copy link
Contributor

Choose a reason for hiding this comment

The 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)
Expand All @@ -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)
Expand All @@ -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)
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

number+G is supposed to send the cursor to a specific line number, your version doesn't do that anymore ?
G puts the cursor to the top inly if no number was entered, i.e. repeat == 1

Copy link
Collaborator Author

Choose a reason for hiding this comment

The 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)
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Is is the same as G, where entering a number before gg does something different ?


# %% 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()
Expand Down