-
-
Notifications
You must be signed in to change notification settings - Fork 448
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
[Feature request] NERDCommenterDuplicate command #435
Comments
This sounds pretty workflow specific, and all the pieces are there already. Why not just add yourself a map that first calls the |
@alerque Thanks for the suggestion :) I tried that already but without much success. Please note that I am not a Vimscript expert so I apologize in advance if I'm doing something stupid. I wrote the following code in my nnoremap gC :call Test()<cr>
function! Test()
:call NERDComment('n', 'yank')
exec 'normal! p'
endfunc
xnoremap gC :call Test2()<cr>
function! Test2()
:call NERDComment('x', 'yank')
exec 'normal! p'
endfunc The first function/binding for normal mode works correctly but the function/binding for visual mode doesn't work at all. Any idea what I'm doing wrong? Also, even if the second function/binding did do what I was expecting, I believe it still wouldn't be the desired result. Since after executing the
where the uncommented version gets pasted below the first line instead of below the last line of the commented section. |
For the visual mode example, before running the normal mode command I think you need to jump the cursor to the end of the visual selection and switch to normal mode. |
@alerque Yes I think that would work if it wasn't for the other issue that I mentioned. If I modify the function so that it jumps to the end of the visual selection like this: xnoremap gC :call Test2()<cr>
function! Test2()
:call NERDComment('x', 'yank')
exec "normal! '>"
exec 'normal! p'
endfunc It results in the following code. It seems like the
Any idea why this would be happening? |
@alerque I did some more testing and this code snippet xnoremap gC :call Test2()<cr>
function! Test2()
:call NERDComment('x', 'yank')
endfunc does not even do the same thing as |
I am currently trying to move from feraltogglecommentify to nerdcommenter and after struggling to recreate its functionality with nerdcommenter I came here to open an issue and found this already existing one. While its correct that vim can easily compose simple things, sometimes it gets a bit more complicated for the average vim users, which are often not well versed in vim script. The problems I was facing (and could not solve) in replicating the functionality of C-c of feraltogglecommentify are:
Additionally I was hoping that with this I could find a solution that would not even clobber the "" register. Therefore it would really be nice if this could be a done as a plugin feature. |
I would consider a PR if somebody submits a function that copies to a non-default register, pastes a copy, comments one of them, then leaves the cursor at a reasonable location. |
A command that in addition to yanking (like the
NERDCommenterYank
) command also pastes the yanked code below the commented out version.For example:
Before running
NERDCommenterDuplicate
commandAfter running
NERDCommenterDuplicate
command with the three lines selected in visual modeObviously is you are in normal mode and not visual mode then it would just yank, comment and paste the current line.
I hope you like the idea!
The text was updated successfully, but these errors were encountered: