Skip to content

Instantly share code, notes, and snippets.

@t9md
Created May 30, 2015 18:03
Show Gist options
  • Star 1 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save t9md/736291fd22260b5c7de0 to your computer and use it in GitHub Desktop.
Save t9md/736291fd22260b5c7de0 to your computer and use it in GitHub Desktop.
Dirty hack to emulate visual-block mode using multi cursor feature.

Limitation

  • You only can extend selection area for up/down direction.
  • When escaped from visual-mode, multi-cursor not cleared.
class VimVisualBlock
constructor: ->
atom.commands.add 'atom-text-editor',
'user:visual-blockwise-j': (event) => @blockOperation(event, 'j')
'user:visual-blockwise-k': (event) => @blockOperation(event, 'k')
getVimService: ->
@vimService ?= atom.packages
.getActivePackage('vim-mode')
.mainModule.provideVimMode()
isVisualBlockMode: (editor) ->
{mode, submode} = @getVimService().getEditorState(editor)
(mode is 'visual') and (submode is 'blockwise')
blockOperation: (event, direction) ->
editor = atom.workspace.getActiveTextEditor()
if @isVisualBlockMode editor
switch direction
when 'j' then editor.addSelectionBelow()
when 'k' then editor.addSelectionAbove()
else
event.abortKeyBinding()
new VimVisualBlock()
'atom-text-editor.vim-mode.visual-mode':
'j': 'user:visual-blockwise-j'
'k': 'user:visual-blockwise-k'
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment