preservim / nerdcommenter

Vim plugin for intensely nerdy commenting powers
Creative Commons Zero v1.0 Universal
4.97k stars 447 forks source link

[Question] how to placte the cursor a line below commented section? #505

Closed gilbh closed 1 year ago

gilbh commented 1 year ago

Hi,

Is there a way to move down the caret after the commented section? I don't know how to add the motion 'j' at the end of the following command:

nnoremap <Leader>3 <plug>NERDCommenterInvert

Thanks!

puttehi commented 1 year ago

Have you tried any of the following:

  1. nnoremap <leader>3 <plug>NERDCommenterInvertj
  2. nnoremap <leader>3 <plug>NERDCommenterInvert j
  3. nnoremap <leader>3 :execute "normal \<Plug>NERDCommenterInvert"<CR>j

Off the top of my head I feel like 1 and 3 both work

dsyabitov commented 1 year ago

I've used this way in neovim and lua (may be it will helpfull for someone)

local map = vim.api.nvim_set_keymap

function nm(key, command)
    map('n', key, command, {noremap = true, silent = true})
end

function commentLineToggle()
    vim.cmd('call nerdcommenter#Comment("n", "toggle")')
    vim.cmd('normal j')
end

nm('<C-_>', "<cmd>lua commentLineToggle()<CR>")
gilbh commented 1 year ago

Thanks @puttehi ! Actually, all the three options worked! Fantastic!

@dsyabitov , I didn't start writing in lua yet, but what you show here very clear and can serve as a sort-of a boilerplate for other stuff too. Thanks!!