Skip to content
This repository was archived by the owner on Apr 6, 2018. It is now read-only.
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 2 additions & 0 deletions keymaps/vim-mode.cson
Original file line number Diff line number Diff line change
Expand Up @@ -85,10 +85,12 @@
'down': 'vim-mode:move-down'

'w': 'vim-mode:move-to-next-word'
'alt-w': 'vim-mode:move-to-next-alt-word'
'W': 'vim-mode:move-to-next-whole-word'
'e': 'vim-mode:move-to-end-of-word'
'E': 'vim-mode:move-to-end-of-whole-word'
'b': 'vim-mode:move-to-previous-word'
'alt-b': 'vim-mode:move-to-previous-alt-word'
'B': 'vim-mode:move-to-previous-whole-word'
'}': 'vim-mode:move-to-next-paragraph'
'{': 'vim-mode:move-to-previous-paragraph'
Expand Down
50 changes: 45 additions & 5 deletions lib/motions/general-motions.coffee
Original file line number Diff line number Diff line change
Expand Up @@ -183,9 +183,27 @@ class MoveToPreviousWord extends Motion
operatesInclusively: false

moveCursor: (cursor, count=1) ->
if settings.defaultWordIsCamelCaseSensitive()
@moveCursorToPreviousSubword(cursor, count)
else
@moveCursorToPreviousWord(cursor, count)

moveCursorToPreviousSubword: (cursor, count) ->
_.times count, ->
# XXX: Doesn't actually work as it also moves to the ending of the previous subword
cursor.moveToPreviousSubwordBoundary()

moveCursorToPreviousWord: (cursor, count) ->
_.times count, ->
cursor.moveToBeginningOfWord()

class MoveToPreviousAltWord extends MoveToPreviousWord
moveCursor: (cursor, count=1) ->
if settings.defaultWordIsCamelCaseSensitive()
@moveCursorToPreviousWord(cursor, count)
else
@moveCursorToPreviousSubword(cursor, count)

class MoveToPreviousWholeWord extends Motion
operatesInclusively: false

Expand All @@ -204,17 +222,31 @@ class MoveToPreviousWholeWord extends Motion
not cur.row and not cur.column

class MoveToNextWord extends Motion
wordRegex: null
subwordRegex: null
operatesInclusively: false

moveCursor: (cursor, count=1, options) ->
if settings.defaultWordIsCamelCaseSensitive()
@moveCursorToNextSubword(cursor, count, options)
else
@moveCursorToNextWord(cursor, count, options)

moveCursorToNextWord: (cursor, count, options) ->
@moveCursorByRegex(cursor, count, options, null)

moveCursorToNextSubword: (cursor, count, options) ->
@subwordRegex ?= cursor.subwordRegExp()
# HACK: expected behavior got changed with https://github.com/atom/atom/commit/ba3ab41
@moveCursorByRegex(cursor, count, options, new RegExp("^[\t ]*$|"[email protected](14), "g"))

moveCursorByRegex: (cursor, count, options, wordRegex) ->
_.times count, =>
current = cursor.getBufferPosition()

next = if options?.excludeWhitespace
cursor.getEndOfCurrentWordBufferPosition(wordRegex: @wordRegex)
cursor.getEndOfCurrentWordBufferPosition(wordRegex: wordRegex)
else
cursor.getBeginningOfNextWordBufferPosition(wordRegex: @wordRegex)
cursor.getBeginningOfNextWordBufferPosition(wordRegex: wordRegex)

return if @isEndOfFile(cursor)

Expand All @@ -232,8 +264,16 @@ class MoveToNextWord extends Motion
eof = @editor.getEofBufferPosition()
cur.row is eof.row and cur.column is eof.column

class MoveToNextAltWord extends MoveToNextWord
moveCursor: (cursor, count=1, options) ->
if settings.defaultWordIsCamelCaseSensitive()
@moveCursorToNextWord(cursor, count, options)
else
@moveCursorToNextSubword(cursor, count, options)

class MoveToNextWholeWord extends MoveToNextWord
wordRegex: WholeWordOrEmptyLineRegex
moveCursor: (cursor, count=1, options) ->
@moveCursorByRegex(cursor, count, options, WholeWordOrEmptyLineRegex)

class MoveToEndOfWord extends Motion
wordRegex: null
Expand Down Expand Up @@ -455,7 +495,7 @@ class ScrollFullDownKeepCursor extends ScrollKeepingCursor

module.exports = {
Motion, MotionWithInput, CurrentSelection, MoveLeft, MoveRight, MoveUp, MoveDown,
MoveToPreviousWord, MoveToPreviousWholeWord, MoveToNextWord, MoveToNextWholeWord,
MoveToPreviousWord, MoveToPreviousAltWord, MoveToPreviousWholeWord, MoveToNextWord, MoveToNextAltWord, MoveToNextWholeWord,
MoveToEndOfWord, MoveToNextParagraph, MoveToPreviousParagraph, MoveToAbsoluteLine, MoveToRelativeLine, MoveToBeginningOfLine,
MoveToFirstCharacterOfLineUp, MoveToFirstCharacterOfLineDown,
MoveToFirstCharacterOfLine, MoveToFirstCharacterOfLineAndDown, MoveToLastCharacterOfLine,
Expand Down
4 changes: 4 additions & 0 deletions lib/settings.coffee
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,10 @@ settings =
type: 'string'
default: '-?[0-9]+'
description: 'Use this to control how Ctrl-A/Ctrl-X finds numbers; use "(?:\\B-)?[0-9]+" to treat numbers as positive if the minus is preceded by a character, e.g. in "identifier-1".'
defaultWordIsCamelCaseSensitive:
type: 'boolean'
default: true
description: 'If set to true, the w and similar motions and text objects will be camel-case sensitive. The alt modifier key can be used to access the camel-case insensitive behaviour. Setting to false reverses the bindings.'

Object.keys(settings.config).forEach (k) ->
settings[k] = ->
Expand Down
2 changes: 2 additions & 0 deletions lib/vim-state.coffee
Original file line number Diff line number Diff line change
Expand Up @@ -105,10 +105,12 @@ class VimState
'move-down': => new Motions.MoveDown(@editor, this)
'move-right': => new Motions.MoveRight(@editor, this)
'move-to-next-word': => new Motions.MoveToNextWord(@editor, this)
'move-to-next-alt-word': => new Motions.MoveToNextAltWord(@editor, this)
'move-to-next-whole-word': => new Motions.MoveToNextWholeWord(@editor, this)
'move-to-end-of-word': => new Motions.MoveToEndOfWord(@editor, this)
'move-to-end-of-whole-word': => new Motions.MoveToEndOfWholeWord(@editor, this)
'move-to-previous-word': => new Motions.MoveToPreviousWord(@editor, this)
'move-to-previous-alt-word': => new Motions.MoveToPreviousAltWord(@editor, this)
'move-to-previous-whole-word': => new Motions.MoveToPreviousWholeWord(@editor, this)
'move-to-next-paragraph': => new Motions.MoveToNextParagraph(@editor, this)
'move-to-previous-paragraph': => new Motions.MoveToPreviousParagraph(@editor, this)
Expand Down
Loading