vim mode 'r <Enter>' keeps replace mode active #1246
Loading…
Add table
Add a link
Reference in a new issue
No description provided.
Delete branch "%!s()"
Deleting a branch is permanent. Although the deleted branch may continue to exist for a short time before it actually gets removed, it CANNOT be undone in most cases. Continue?
I use 'r ' to split lines and when I do so, my next keypress is taken as the character to use in the replace. The is also used, but replace mode remains active.
Well, I'm seeing that typing 'r ' replaces the current character with the word 'Space', which is definitely a bug. I don't understand what you mean by using 'r ' to split lines though. Could you provide a more concrete example?
sorry, yes.
'r ' replaces the character with Space, 'r' replaces the character with the word 'Down', etc. 'r' should replace the current character with a newline, which it does, but should also end replace mode.
For example:
hello world
cursor is on the space between 'hello' and 'world', typing 'ri' should leave the buffer as
hello
world
and insert mode should be active. Instead, we get
hello
iorld
Got it, github is stripping out your
<Enter>, you should enclose it with backticks. So you are sayingr<Enter>should replace the current character with\n. I agree and I think I have an idea of how to fix that.But could you type out again the key sequence that results in
hello
iorld
Doing
r<Enter>iwould get me helloEnterworld, with the cursor before the E, in insert mode. No newline is inserted.ah, sorry for the confusion. yes, so
r<Enter>idoes result in helloEnterworld in the vim keybindings demo on the codemirror site.In the application I am using that uses codemirror the same keystrokes lead to
\nbeing inserted instead ofEnterbut theiis then inserted in place of the next character. Perhaps fixing the entering of special characters as words will help both those cases...@mightyguavaI've added a few changes at vim.js:598 for that in my personal version of CodeMirror (not the one on github though), and planned to commit those here once I've got the current additions stable. In my version I actually explicitely catch the keys fromspecialKeysthat have printable equivalents (Space and Enter right now). My code doesn't do anything with the others, but probably it should do something 'bell'-like (maybe we should open an issue about how to deal with these errors in general). Also in my coder<CR>leaves the cursor at the start of the new linebreak (as in 'behind the last character of the line') which I need to fix. I'd like to sort out the selection-issues first though, since a more significant change I made toris allowing it to operate on selections. For that again I had to write a test first that expected wrong results, due to selection being one character short.@metatheosAwesome! I was planning to tackle this today but you got to it first :) You may need to special case<CR>in the replace motion, since you'll probably want to use newlineAndIndentContinueComment to make the newline instead of\nYes... visual mode handling is quite inelegant since CodeMirror's selection model is a little bit different from what would be expected of Vim. I believe I added a hack to include the last character in visual mode here
github.com/metatheos/CodeMirror@58e56150cb/keymap/vim.js (L875). Is it not working for you?I also thought you were planning in https://github.com/marijnh/CodeMirror/pull/1235#issuecomment-13551933 to keep a separate selection model and emulate CodeMirror selections with setSelection, which can go a long way to make this better. Or is that for later?
You're right, I definitely have to adapt that for consistency. Vim-help actually states that it will insert only one linebreak if
<CR>or<NL>is the replacement character for a given range, so this is a special case anyway.I would need to check why it didn't work. I also could have added the same hack to
rof course, but at that point I was curious whether it would work out to improve visual mode either way ;)I would prefer to maybe add optional
from/to-arguments tosetSelectionif codemirror can reliably deal with that in general. Locally I do have an implementation that feels a lot more clean, save the new vim.js-specificsetSelectionthat is pretty much:mentioned in merge request !8420
This is fixed by the above change by
@metatheos.Please verify and close.