├── .gitignore ├── CHANGELOG.md ├── LICENSE.md ├── README.md ├── keymaps └── vim-mode-visual-block.cson ├── lib └── main.coffee └── package.json /.gitignore: -------------------------------------------------------------------------------- 1 | .DS_Store 2 | npm-debug.log 3 | node_modules 4 | -------------------------------------------------------------------------------- /CHANGELOG.md: -------------------------------------------------------------------------------- 1 | ## 0.2.16 - Add note to README 2 | - More explictly DEPRECATED. 3 | 4 | ## 0.2.15 - Add note to README 5 | - Put word *not maintained* to be stand out at top of README.md 6 | 7 | ## 0.2.14 - Add note to README 8 | - Put link to vim-mode-plus. 9 | 10 | ## 0.2.13 - Revert 11 | - Completely remove `activationCommands`. 12 | 13 | ## 0.2.12 - Improve 14 | - Now activated by `vim-mode:activate-blockwise-visual-mode`. 15 | - Delete deprecated keymap notification. 16 | 17 | ## 0.2.11 - Quick FIX for #3 18 | - Disable activationCommands to avoid `getEditorState` throw error because of `@vimModeService` is undefined. 19 | 20 | ## 0.2.10 21 | 22 | ## 0.2.9 - Follow renaming to NormalMode 23 | - Use `activateNormalMode` instead of `activateCommandMode`. 24 | 25 | ## 0.2.8 - Improve 26 | * Refactoring. 27 | * `activationCommands`. 28 | 29 | ## 0.2.7 - Improve 30 | * `ctrl-v` within visual-block now work same as escape. #1 31 | 32 | ## 0.2.6 - Fix Typo 33 | * Fix README.md typo. 34 | 35 | ## 0.2.5 - Improve 36 | * Add provide default keymap. 37 | * No longer use `vimState.resetCommandMode()`. 38 | * No longer manage explicit @active state. 39 | * Improve resetting @startRow. 40 | * [FIX] selection range got wrong in some case. 41 | 42 | ## 0.2.4 - Stability improve 43 | * Never accidentally destroy(), last cursor() 44 | 45 | ## 0.2.3 - GIF update. 46 | ## 0.2.2 - Improve `I`, `A` further 47 | ## 0.2.1 - Improve `I`, `A`. 48 | ## 0.2.0 - Rename Package name 49 | ## 0.1.1 - Doc update. 50 | ## 0.1.0 - First Release 51 | -------------------------------------------------------------------------------- /LICENSE.md: -------------------------------------------------------------------------------- 1 | Copyright (c) 2015 t9md 2 | 3 | Permission is hereby granted, free of charge, to any person obtaining 4 | a copy of this software and associated documentation files (the 5 | "Software"), to deal in the Software without restriction, including 6 | without limitation the rights to use, copy, modify, merge, publish, 7 | distribute, sublicense, and/or sell copies of the Software, and to 8 | permit persons to whom the Software is furnished to do so, subject to 9 | the following conditions: 10 | 11 | The above copyright notice and this permission notice shall be 12 | included in all copies or substantial portions of the Software. 13 | 14 | THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, 15 | EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF 16 | MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND 17 | NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE 18 | LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION 19 | OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION 20 | WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. 21 | -------------------------------------------------------------------------------- /README.md: -------------------------------------------------------------------------------- 1 | # vim-mode-visual-block 2 | 3 | # [DEPRECATED] **Not maintained** 4 | 5 | I'm no longer maintaining this package. 6 | Use [vim-mode-plus](https://atom.io/packages/vim-mode-plus) instead it's have native visual-block-mode support. 7 | 8 | If you want to fix any bug for **this** package, fork it and I'm OK you to release forked version. 9 | Please don't ask me to fix this package. 10 | 11 | It might be better to unpublish this package? 12 | Please report issue if you have strong opinion for that. 13 | 14 | Thank's for using this my package. 15 | 16 | Note added at 2016.1.13 17 | 18 | # What WAS this? 19 | 20 | Add visual-block operation to [vim-mode](https://atom.io/packages/vim-mode). 21 | 22 | ![gif](https://raw.githubusercontent.com/t9md/t9md/375d45f661b76cd8fd874dbcacf93602e7d75c99/img/vim-mode-visual-blockwise.gif) 23 | 24 | 25 | **Temporarily** workaround, until vim-mode support visual block mode natively. 26 | I'm not intended to complete solution. 27 | 28 | # Keymap 29 | 30 | From version 0.2.5, starting to provide [default keymap](https://github.com/t9md/atom-vim-mode-visual-block/blob/master/keymaps/vim-mode-visual-block.cson). 31 | 32 | For older version user 33 | * Remove explicit keymap from `keymap.cson` and use default keymap. 34 | 35 | # Limitation 36 | - Count not supported. 37 | - Currently yank and paste for block range is not supported. 38 | - No support for non-contiguous multi selection. 39 | 40 | # Todo 41 | * [x] Precise state check when escape from visual-block. 42 | * [x] Support other insert-mode initiator like `a`, `i`, `C`. 43 | * [ ] Yank and paste support. 44 | * [ ] Concatenate undo transaction?. 45 | -------------------------------------------------------------------------------- /keymaps/vim-mode-visual-block.cson: -------------------------------------------------------------------------------- 1 | 'atom-text-editor.vim-mode.visual-mode': 2 | 'o': 'vim-mode-visual-block:o' 3 | 'j': 'vim-mode-visual-block:j' 4 | 'k': 'vim-mode-visual-block:k' 5 | 'D': 'vim-mode-visual-block:D' 6 | 'C': 'vim-mode-visual-block:C' 7 | 'I': 'vim-mode-visual-block:I' 8 | 'A': 'vim-mode-visual-block:A' 9 | 'escape': 'vim-mode-visual-block:escape' 10 | 'ctrl-[': 'vim-mode-visual-block:escape' 11 | 'ctrl-c': 'vim-mode-visual-block:escape' 12 | 'ctrl-v': 'vim-mode-visual-block:ctrl-v' 13 | -------------------------------------------------------------------------------- /lib/main.coffee: -------------------------------------------------------------------------------- 1 | _ = require 'underscore-plus' 2 | {CompositeDisposable} = require 'atom' 3 | 4 | Config = 5 | debug: 6 | type: 'boolean' 7 | default: false 8 | 9 | module.exports = 10 | disposables: null 11 | active: false 12 | prefix: 'vim-mode-visual-block' 13 | 14 | activate: (state) -> 15 | @disposables = new CompositeDisposable 16 | blockwiseCommands = {} 17 | commands = 'jkoDCIA'.split('') 18 | commands.push 'escape', 'ctrl-v' 19 | for command in commands 20 | do (command) => 21 | name = "#{@prefix}:#{command}" 22 | blockwiseCommands[name] = (event) => @blockOperation(event, command) 23 | 24 | # blockwiseCommands["#{@prefix}:toggle-debug"] = => @toggleDebug() 25 | @disposables.add atom.commands.add('atom-text-editor', blockwiseCommands) 26 | @reset() 27 | 28 | deactivate: -> 29 | @disposables.dispose() 30 | 31 | consumeVimMode: (@vimModeService) -> 32 | 33 | reset: -> 34 | @startRow = null 35 | 36 | getEditor: -> 37 | atom.workspace.getActiveTextEditor() 38 | 39 | isVisualBlockMode: (vimState) -> 40 | (vimState.mode is 'visual') and (vimState.submode is 'blockwise') 41 | 42 | getVimEditorState: (editor) -> 43 | @vimModeService.getEditorState editor 44 | 45 | adjustSelections: (editor, options) -> 46 | for selection in editor.getSelections() 47 | range = selection.getBufferRange() 48 | selection.setBufferRange range, options 49 | 50 | blockOperation: (event, command) -> 51 | editor = @getEditor() 52 | vimState = @getVimEditorState editor 53 | 54 | unless @isVisualBlockMode vimState 55 | event.abortKeyBinding() 56 | @reset() 57 | return 58 | 59 | # May be non-continuous execution. 60 | if editor.getCursors().length is 1 61 | @reset() 62 | 63 | currentRow = editor.getLastCursor()?.getBufferRow() 64 | @startRow ?= currentRow 65 | 66 | switch command 67 | when 'o' 68 | @startRow = currentRow 69 | when 'D', 'C' 70 | vimState.activateNormalMode() 71 | event.abortKeyBinding() 72 | when 'escape', 'ctrl-v' 73 | vimState.activateNormalMode() 74 | editor.clearSelections() 75 | when 'j', 'k' 76 | cursors = editor.getCursorsOrderedByBufferPosition() 77 | cursorTop = _.first cursors 78 | cursorBottom = _.last cursors 79 | 80 | if (command is 'j' and cursorTop.getBufferRow() >= @startRow) or 81 | (command is 'k' and cursorBottom.getBufferRow() <= @startRow) 82 | lastSelection = editor.getLastSelection() 83 | 84 | if command is 'j' 85 | editor.addSelectionBelow() 86 | else 87 | editor.addSelectionAbove() 88 | 89 | # [FIXME] 90 | # When addSelectionAbove(), addSelectionBelow() doesn't respect 91 | # reversed stated, need improved. 92 | # 93 | # and one more.. 94 | # 95 | # When selection is NOT empty and add selection by addSelectionAbove() 96 | # and then move right, selection range got wrong, maybe this is bug.. 97 | @adjustSelections editor, reversed: lastSelection.isReversed() 98 | else 99 | # [FIXME] 100 | # Guard to not destroying last cursor 101 | # This guard is no longer needed 102 | # Remove unnecessary code after re-think. 103 | if (editor.getCursors().length < 2) 104 | @reset() 105 | return 106 | 107 | if command is 'j' 108 | cursorTop.destroy() 109 | else 110 | cursorBottom.destroy() 111 | when 'I', 'A' 112 | cursorsAdjusted = [] 113 | 114 | adjustCursor = (selection) -> 115 | {start, end} = selection.getBufferRange() 116 | pointEndOfLine = editor.bufferRangeForBufferRow(start.row).end 117 | pointTarget = {'I': start, 'A': end}[command] 118 | {cursor} = selection 119 | 120 | if pointTarget.isGreaterThanOrEqual(pointEndOfLine) 121 | pointTarget = pointEndOfLine 122 | cursorsAdjusted.push cursor 123 | cursor.setBufferPosition(pointTarget) 124 | 125 | adjustCursor(selection) for selection in editor.getSelections() 126 | vimState.activateNormalMode() 127 | vimState.activateInsertMode() 128 | 129 | if command is 'A' and cursorsAdjusted.length 130 | cursor.moveRight() for cursor in cursorsAdjusted 131 | 132 | unless @isVisualBlockMode vimState 133 | @reset() 134 | 135 | toggleDebug: -> 136 | oldState = atom.config.get("#{@prefix}.debug") 137 | atom.config.set("#{@prefix}.debug", not oldState) 138 | state = atom.config.get("#{@prefix}.debug") and "enabled" or "disabled" 139 | console.log "#{@prefix}: debug #{state}" 140 | 141 | debug: (msg) -> 142 | return unless atom.config.get("#{@prefix}.debug") 143 | console.log msg 144 | 145 | # dump: -> 146 | # @debug "@startRow = #{@startRow}" 147 | -------------------------------------------------------------------------------- /package.json: -------------------------------------------------------------------------------- 1 | { 2 | "name": "vim-mode-visual-block", 3 | "main": "./lib/main", 4 | "version": "0.2.16", 5 | "description": "[DEPRECATED] Add visual-blockwise feature to vim-mode", 6 | "repository": "https://github.com/t9md/atom-vim-mode-visual-block", 7 | "license": "MIT", 8 | "engines": { 9 | "atom": ">=0.174.0 <2.0.0" 10 | }, 11 | "consumedServices": { 12 | "vim-mode": { 13 | "versions": { 14 | "^0.1.0": "consumeVimMode" 15 | } 16 | } 17 | }, 18 | "dependencies": { 19 | "underscore-plus": "^1.6.6" 20 | } 21 | } 22 | --------------------------------------------------------------------------------