nerdcommenter icon indicating copy to clipboard operation
nerdcommenter copied to clipboard

Confusion about creating maps ("Comment" getting inserted after)

Open MarcelRobitaille opened this issue 8 years ago • 3 comments

I am having a very hard time getting mappings set up for this plugin. Right now, I have the following in my vimrc:

let g:NERDSpaceDelims = 1

map <C-_> <Plug>NERDCommenterToggle
imap <C-_> <Plug>NERDCommenterInsertComment

The toggle command works fine. The insert one adds Comment after the comment delimiters. Am I calling the function correctly? I tried your suggestions from #267 but that didn't work either. If there is something obvious I am missing, maybe it should be added to the readme?

I just ran PlugUpdate and PlugUpgrade so I should have the latest version of everything. I couldn't find how to print the version. Sorry.

vim --version:

VIM - Vi IMproved 8.0 (2016 Sep 12, compiled Apr 26 2017 07:50:37)
Included patches: 1-586
Compiled by Arch Linux
Huge version without GUI.  Features included (+) or not (-):
+acl             +file_in_path    +mouse_sgr       +tag_old_static
+arabic          +find_in_path    -mouse_sysmouse  -tag_any_white
+autocmd         +float           +mouse_urxvt     +tcl/dyn
-balloon_eval    +folding         +mouse_xterm     +termguicolors
-browse          -footer          +multi_byte      +terminfo
++builtin_terms  +fork()          +multi_lang      +termresponse
+byte_offset     +gettext         -mzscheme        +textobjects
+channel         -hangul_input    +netbeans_intg   +timers
+cindent         +iconv           +num64           +title
-clientserver    +insert_expand   +packages        -toolbar
-clipboard       +job             +path_extra      +user_commands
+cmdline_compl   +jumplist        +perl/dyn        +vertsplit
+cmdline_hist    +keymap          +persistent_undo +virtualedit
+cmdline_info    +lambda          +postscript      +visual
+comments        +langmap         +printer         +visualextra
+conceal         +libcall         +profile         +viminfo
+cryptv          +linebreak       +python/dyn      +vreplace
+cscope          +lispindent      +python3/dyn     +wildignore
+cursorbind      +listcmds        +quickfix        +wildmenu
+cursorshape     +localmap        +reltime         +windows
+dialog_con      +lua/dyn         +rightleft       +writebackup
+diff            +menu            +ruby/dyn        -X11
+digraphs        +mksession       +scrollbind      -xfontset
-dnd             +modify_fname    +signs           -xim
-ebcdic          +mouse           +smartindent     -xpm
+emacs_tags      -mouseshape      +startuptime     -xsmp
+eval            +mouse_dec       +statusline      -xterm_clipboard
+ex_extra        +mouse_gpm       -sun_workshop    -xterm_save
+extra_search    -mouse_jsbterm   +syntax          
+farsi           +mouse_netterm   +tag_binary      
   system vimrc file: "/etc/vimrc"
     user vimrc file: "$HOME/.vimrc"
 2nd user vimrc file: "~/.vim/vimrc"
      user exrc file: "$HOME/.exrc"
       defaults file: "$VIMRUNTIME/defaults.vim"
  fall-back for $VIM: "/usr/share/vim"
Compilation: gcc -c -I. -Iproto -DHAVE_CONFIG_H   -D_FORTIFY_SOURCE=2  -march=x86-64 -mtune=generic -O2 -pipe -fstack-protector-strong -U_FORTIFY_SOURCE -D_FORTIFY_SOURCE=1       
Linking: gcc   -L. -Wl,-O1,--sort-common,--as-needed,-z,relro -fstack-protector -rdynamic -Wl,-export-dynamic -Wl,-E -Wl,-rpath,/usr/lib/perl5/core_perl/CORE  -Wl,-O1,--sort-common,--as-needed,-z,relro -L/usr/local/lib -Wl,--as-needed -o vim        -lm -lncurses -lelf -lnsl    -lacl -lattr -lgpm -ldl   -Wl,-E -Wl,-rpath,/usr/lib/perl5/core_perl/CORE -Wl,-O1,--sort-common,--as-needed,-z,relro -fstack-protector-strong -L/usr/local/lib  -L/usr/lib/perl5/core_perl/CORE -lperl -lpthread -lnsl -ldl -lm -lcrypt -lutil -lc   -L/usr/lib -ltclstub8.6 -ldl -lz -lpthread -lieee -lm     

MarcelRobitaille avatar May 31 '17 01:05 MarcelRobitaille

The function name you want to call from your mapping is just NERDCommenterInsert, the word "Comment" is getting inserted inside your new comment because you followed the recognized function name with that string. Just use:

imap <C-_> <Plug>NERDCommenterInsert

alerque avatar May 31 '17 08:05 alerque

I'm leaving this issue open for a bit because the documentation (at least the Readme) does seem to be a bit out of sync. I'm not sure what's up with that and don't have time to fix it at the moment, but if anybody want's to jump in with a PR that would be awesome!

alerque avatar May 31 '17 08:05 alerque

Thanks for the reply. That mapping does seem to work.

You say the readme needs an update but even the help page has the Comment at the end.

|NERDComInsertComment| Adds comment delimiters at the current cursor position and inserts between. Disabled by default.

Also, what is the difference between the commands I see in the help page (with NERDCom) and the ones I see elsewhere (with NERDComment)?

Thanks.

MarcelRobitaille avatar May 31 '17 12:05 MarcelRobitaille