t9md / atom-vim-mode-plus

vim-mode improved
https://atom.io/packages/vim-mode-plus
MIT License
1.4k stars 112 forks source link

[Documentation improvement] InsertCharacter operator which insert the specified character #909

Closed galou closed 7 years ago

galou commented 7 years ago

Would it be possible to improve the already great documentation of this great plugin by adding a function InsertCharacter which, similar to InsertSpaces, would insert the character specified after the command in normal mode? For example, if I bind it to ` (space), _` (space + underscore) would insert an underscore and stay in normal mode.

Check list

t9md commented 7 years ago

Do you want new operator?why issue subject saying documentation-improve?(its confuse me).

Also what is your usecase if this new operator. You alrady can do 'i then char then escape' to prepare temporal insert-char edit-session you can repeat it by . command.

galou commented 7 years ago

I guess vim-mode-plus does not need to be altered to implement this new function, that's why it's more about documenting how to implement it as a user.

My use case is exactly this, replace 3 key strokes by 2. I never used spaces in normal mode in vim and bound it this function, which I happen to use quite a lot.

t9md commented 7 years ago

OK, you want documentation on WIki, will update and put link here.

t9md commented 7 years ago

see this wiki, count supported.

If you map it _, 3 _ a insert aaa at cursor position.

galou commented 7 years ago

Excellent! Thanks!

galou commented 6 years ago

An update of atom or vim-mode-plus rendered the InsertCharacter documented at the wiki non functional

Could you please have a look at it? Thanks a lot!

Gaël

PS: For some reason, vim-mode-plus doesn't update anymore on my version of atom.

Atom : 1.21.1 Electron: 1.6.15 Chrome : 56.0.2924.87 Node : 7.4.0 vim-mode-plus: 1.16.0

t9md commented 6 years ago

Your Atom is too old to update to latest vmp. You can check by finding engines in pkg.json.

https://github.com/t9md/atom-vim-mode-plus/blob/eb4ee5bb22f9dace9f4f81711be560f428e65fbd/package.json#L9-L11

And what's the issue? InsertCharacter once worked and now become un-functional? Or you cannot make it work from the beginning?

galou commented 6 years ago

What a quick answer! Thanks!

I have

  "engines": {
    "atom": "^1.19.0"
  },

InsertCharacter worked back in October'17. I can't remember when it stopped working. The issue is:

[Enter steps to reproduce:]

  1. Press space

Atom: 1.21.1 x64 Electron: 1.6.15 OS: Ubuntu 14.04.5 Thrown From: vim-mode-plus package 1.16.0

Stack Trace

Uncaught TypeError: Cannot read property 'repeat' of null

At /home/gael/.atom/packages/vim-mode-plus/lib/operation-stack.js:157

TypeError: Cannot read property 'repeat' of null
    at InsertCharacter.mutateSelection (/home/gael/.atom/init.js:31:66)
    at InsertCharacter.mutateSelections (/packages/vim-mode-plus/lib/operator.js:267:12)
    at /packages/vim-mode-plus/lib/operator.js:280:37
    at TextBuffer.module.exports.TextBuffer.transact (/opt/atom/resources/app/node_modules/text-buffer/lib/text-buffer.js:952:24)
    at TextEditor.module.exports.TextEditor.transact (/opt/atom/resources/app/src/text-editor.js:1673:32)
    at InsertCharacter.startMutation (/packages/vim-mode-plus/lib/operator.js:261:17)
    at InsertCharacter.execute (/packages/vim-mode-plus/lib/operator.js:279:10)
    at OperationStack.execute (/packages/vim-mode-plus/lib/operation-stack.js:193:33)
    at OperationStack.process (/packages/vim-mode-plus/lib/operation-stack.js:186:12)
    at OperationStack.run (/packages/vim-mode-plus/lib/operation-stack.js:102:14)
    at /packages/vim-mode-plus/lib/base.js:329:45)
    at CommandRegistry.handleCommandEvent (/opt/atom/resources/app/src/command-registry.js:381:36)
    at KeymapManager.module.exports.KeymapManager.dispatchCommandEvent (/opt/atom/resources/app/node_modules/atom-keymap/lib/keymap-manager.js:621:22)
    at KeymapManager.module.exports.KeymapManager.handleKeyboardEvent (/opt/atom/resources/app/node_modules/atom-keymap/lib/keymap-manager.js:412:28)
    at WindowEventHandler.module.exports.WindowEventHandler.handleDocumentKeyEvent (/opt/atom/resources/app/src/window-event-handler.js:100:42)
    at HTMLDocument.<anonymous> (/opt/atom/resources/app/src/window-event-handler.js:3:65)

Commands

     -0:19.8.0 vim-mode-plus-user:insert-character (input.hidden-input)
     -0:19.5.0 vim-mode-plus:set-input-char-space (input.hidden-input)
     -0:06.6.0 vim-mode-plus-user:insert-character (input.hidden-input)
     -0:03.8.0 vim-mode-plus:set-input-char-f (input.hidden-input)

Non-Core Packages

autocomplete-paths 2.12.1 
autocomplete-python 1.10.5 
document-outline 1.6.18 
ex-mode 0.18.0 
file-icons 2.1.15 
git-plus 7.10.0 
git-time-machine 1.5.9 
go-config 1.2.4 
go-get 2.1.1 
go-hyperclick 1.1.2 
Hydrogen 2.2.0 
hyperclick 0.1.5 
hyperclick-markdown 0.2.2 
hyperlink-hyperclick 1.3.4 
js-hyperclick 1.12.2 
jupyter-notebook 0.0.10 
kite 0.58.0 
language-diff 0.7.0 
language-latex 1.1.1 
language-nxc 3.6.1 
language-restructuredtext 1.1.0 
language-weave 0.4.2 
latextools 0.8.5 
navigator-go 1.1.3 
open-vim 0.2.3 
path-hyperclick 0.3.0 
pdf-view 0.61.0 
preview-inline 1.5.0 
python-indent 1.1.4 
python-isort 0.0.7 
python-mrigor 2.1.3 
python-tools 0.6.9 
rst-preview 1.3.1 
rst-preview-pandoc 0.1.12 
split-diff 1.5.1 
table-editor 0.2.2 
toggler 0.3.1 
vim-mode-plus 1.16.0 

and

[Enter steps to reproduce:]

  1. Press space
  2. Press a character

Atom: 1.21.1 x64 Electron: 1.6.15 OS: Ubuntu 14.04.5 Thrown From: vim-mode-plus package 1.16.0

Stack Trace

Uncaught TypeError: Cannot read property 'isReady' of undefined

At /home/gael/.atom/packages/vim-mode-plus/lib/operation-stack.js:179

TypeError: Cannot read property 'isReady' of undefined
    at OperationStack.process (/packages/vim-mode-plus/lib/operation-stack.js:179:13)
    at InsertCharacter.processOperation (/packages/vim-mode-plus/lib/base.js:102:34)
    at onConfirm (/packages/vim-mode-plus/lib/base.js:140:14)
    at CompositeDisposable.onDidSetInputChar.char (/packages/vim-mode-plus/lib/vim-state.js:482:9)
    at Function.module.exports.Emitter.simpleDispatch (/opt/atom/resources/app/node_modules/event-kit/lib/emitter.js:25:20)
    at Emitter.module.exports.Emitter.emit (/opt/atom/resources/app/node_modules/event-kit/lib/emitter.js:141:34)
    at VimState.emitDidSetInputChar (/packages/vim-mode-plus/lib/vim-state.js:214:18)
    at /packages/vim-mode-plus/lib/main.js:186:14)
    at /packages/vim-mode-plus/lib/main.js:199:28)
    at CommandRegistry.handleCommandEvent (/opt/atom/resources/app/src/command-registry.js:381:36)
    at KeymapManager.module.exports.KeymapManager.dispatchCommandEvent (/opt/atom/resources/app/node_modules/atom-keymap/lib/keymap-manager.js:621:22)
    at KeymapManager.module.exports.KeymapManager.handleKeyboardEvent (/opt/atom/resources/app/node_modules/atom-keymap/lib/keymap-manager.js:412:28)
    at WindowEventHandler.module.exports.WindowEventHandler.handleDocumentKeyEvent (/opt/atom/resources/app/src/window-event-handler.js:100:42)
    at HTMLDocument.<anonymous> (/opt/atom/resources/app/src/window-event-handler.js:3:65)

Commands

     -1:30.6.0 vim-mode-plus-user:insert-character (input.hidden-input)
     -1:30.4.0 vim-mode-plus:set-input-char-space (input.hidden-input)
     -1:17.5.0 vim-mode-plus-user:insert-character (input.hidden-input)
     -1:14.7.0 vim-mode-plus:set-input-char-f (input.hidden-input)

Non-Core Packages

autocomplete-paths 2.12.1 
autocomplete-python 1.10.5 
document-outline 1.6.18 
ex-mode 0.18.0 
file-icons 2.1.15 
git-plus 7.10.0 
git-time-machine 1.5.9 
go-config 1.2.4 
go-get 2.1.1 
go-hyperclick 1.1.2 
Hydrogen 2.2.0 
hyperclick 0.1.5 
hyperclick-markdown 0.2.2 
hyperlink-hyperclick 1.3.4 
js-hyperclick 1.12.2 
jupyter-notebook 0.0.10 
kite 0.58.0 
language-diff 0.7.0 
language-latex 1.1.1 
language-nxc 3.6.1 
language-restructuredtext 1.1.0 
language-weave 0.4.2 
latextools 0.8.5 
navigator-go 1.1.3 
open-vim 0.2.3 
path-hyperclick 0.3.0 
pdf-view 0.61.0 
preview-inline 1.5.0 
python-indent 1.1.4 
python-isort 0.0.7 
python-mrigor 2.1.3 
python-tools 0.6.9 
rst-preview 1.3.1 
rst-preview-pandoc 0.1.12 
split-diff 1.5.1 
table-editor 0.2.2 
toggler 0.3.1 
vim-mode-plus 1.16.0 

I will fully understand if you don't want to solve this minor issue on an outdated system.

t9md commented 6 years ago

Why you don't update Atom? Which allows you to update vmp to the latest, might solve your issue too.

galou commented 6 years ago

Ubuntu 14.04 decided not to update Atom anymore, I guess. I use http://ppa.launchpad.net/webupd8team/atom/ubuntu.

t9md commented 6 years ago

http://flight-manual.atom.io/getting-started/sections/installing-atom/#platform-linux then go to #debian-and-ubuntu-debapt section

Read this, and try, also you can download latest deb pkg directly.

galou commented 6 years ago

Thanks for the tip!

So I now have Atom 1.23.1 and vmp 1.24.4 but the issue is still present:

[Enter steps to reproduce:]

  1. Add custom function InsertCharacter as specified in the wiki.
  2. Bind it to space for example
  3. Press space

Atom: 1.23.1 x64 Electron: 1.6.15 OS: Ubuntu 14.04.5 Thrown From: vim-mode-plus package 1.24.4

Stack Trace

Uncaught TypeError: Cannot read property 'repeat' of null

At /home/gael/.atom/packages/vim-mode-plus/lib/operation-stack.js:151

TypeError: Cannot read property 'repeat' of null
    at InsertCharacter.mutateSelection (/home/gael/.atom/init.js:31:66)
    at InsertCharacter.mutateSelections (/packages/vim-mode-plus/lib/operator.js:261:12)
    at InsertCharacter.execute (/packages/vim-mode-plus/lib/operator.js:289:35)
    at OperationStack.execute (/packages/vim-mode-plus/lib/operation-stack.js:187:33)
    at OperationStack.process (/packages/vim-mode-plus/lib/operation-stack.js:180:12)
    at OperationStack.run (/packages/vim-mode-plus/lib/operation-stack.js:96:14)
    at /packages/vim-mode-plus/lib/vim-state.js:67:45)
    at CommandRegistry.handleCommandEvent (/usr/share/atom/resources/app/src/command-registry.js:388:36)
    at KeymapManager.module.exports.KeymapManager.dispatchCommandEvent (/usr/share/atom/resources/app/node_modules/atom-keymap/lib/keymap-manager.js:621:22)
    at KeymapManager.module.exports.KeymapManager.handleKeyboardEvent (/usr/share/atom/resources/app/node_modules/atom-keymap/lib/keymap-manager.js:412:28)
    at WindowEventHandler.handleDocumentKeyEvent (/usr/share/atom/resources/app/src/window-event-handler.js:108:40)

Commands

     -0:05.5.0 vim-mode-plus-user:insert-character (input.hidden-input)
     -0:05.3.0 vim-mode-plus:set-input-char-space (input.hidden-input)

Non-Core Packages

autocomplete-paths 2.12.1 
autocomplete-python 1.10.5 
document-outline 2.0.1 
ex-mode 0.18.0 
file-icons 2.1.15 
git-plus 7.10.0 
git-time-machine 1.5.9 
go-config 1.2.4 
go-get 2.1.1 
go-hyperclick 1.1.2 
Hydrogen 2.2.0 
hyperclick 0.1.5 
hyperclick-markdown 0.2.2 
hyperlink-hyperclick 1.3.4 
js-hyperclick 1.12.2 
jupyter-notebook 0.0.10 
kite 0.58.0 
language-diff 0.7.0 
language-latex 1.1.1 
language-nxc 3.6.1 
language-restructuredtext 1.1.0 
language-weave 0.4.2 
latextools 0.8.5 
navigator-go 1.1.3 
open-vim 0.2.3 
path-hyperclick 0.3.0 
pdf-view 0.61.0 
preview-inline 1.5.1 
python-indent 1.1.4 
python-isort 0.0.7 
python-mrigor 2.1.3 
python-tools 0.6.9 
rst-preview 1.3.1 
rst-preview-pandoc 0.1.12 
split-diff 1.5.1 
table-editor 0.2.2 
toggler 0.3.1 
vim-mode-plus 1.24.4 

The second issue has already been reported: https://github.com/t9md/atom-vim-mode-plus/issues/948. The exception is raised when pressing a character after the space.

t9md commented 6 years ago

updated wiki, try it again!

galou commented 6 years ago

Now I get Failed to load ..../init.js, Base is not defined.

My complete init.js is


"use babel"

class InsertCharacter extends Base.getClass("Operator") {
  static commandPrefix = "vim-mode-plus-user"
  target = "Empty"
  readInputAfterSelect = true

  mutateSelection(selection) {
    const point = selection.getHeadBufferPosition()
    this.editor.setTextInBufferRange([point, point], this.input.repeat(this.getCount()))
  }
}
InsertCharacter.registerCommand()
t9md commented 6 years ago

Read whole doc at that page and also Replace service.Base.getClass to service.getClass.

galou commented 6 years ago

OK, I got it working. Thanks! I don't know what you mean with "Replace service.Base.getClass to service.getClass" but didn't need it.

I'm note sure about something. In init.js can there be several calls to consumeService? If yes, I'd write the code for InsertCharacter like this:

consumeService("vim-mode-plus", "provideVimModePlus", ({Base}) => {
  class InsertCharacter extends Base.getClass("Operator") {
    static commandPrefix = "vim-mode-plus-user"
    target = "Empty"
    readInputAfterSelect = true

    mutateSelection(selection) {
      const point = selection.getHeadBufferPosition()
      this.editor.setTextInBufferRange([point, point], this.input.repeat(this.getCount()))
    }
  }
  InsertCharacter.registerCommand()
})

If not, I would write the first and last lines (consumeService("vim-mode-plus", "provideVimModePlus", ({Base}) => { and })) with a comment in the wiki. At first, I didn't get that the code written in the wiki for InsertCharacter has to be put inside the call to consumeService.