Unable to use NERDCommenter with vundle - vim

I am using vim The-NERD-Commenter plugin along with vundle. But I am not able to get the plugin to work.
I have my leader ley mapped to ,. When I run the :scriptnames command I see that ~\vimfiles\bundle\The-NERD-Commenter\plugin\NERD_commenter.vim is listed in the output. I am also able to bring up help for NERDCommenter using :help NERDCommenter command which tells me that the plugin is installed correctly. But when I try to toggle a comment using <leader>c<space> which translates in my case to ,c it invokes the change command instead.
I have my .vimrc file here https://gist.github.com/bAmrish/be1aac3aeb087925a3e5
Update:
It looks like if I remove the leader key mapping from my .vimrc file then the plugin starts working with the default leader key \.
Please let me know what am I doing wrong.
Thanks,
Amrish

You are installing the plugin twice (lines 15, 29):
Plugin 'The-NERD-Commenter'
Plugin 'https://github.com/scrooloose/nerdcommenter.git'
From scanning the README, the scrooloose version doesn't seem to support the c shortcut, so it may be doing some blocking. Reread the documentations and choose one of the two. Post back if your problem isn't solved by one of those two actions.
UPDATE:
Okay, digging deeper. The plugin's .vim code runs the following line:
let leader = exists('g:mapleader') ? g:mapleader : '\'
In your vim try running
:echo exists('g:mapleader')
:echo 'g:mapleader'
If the mapleader exists and spits back , as expected, then we need to look for unexpected/buggy code in the plugin. If it doesn't exist or isn't , as you expect, then we know what needs to be fixed.

Related

Vim UltiSnips for python not working

Maybe it's a stupid question, but I can't figure it out. I have installed the UltiSnips plugin [UltiSnips plugin][1]. I followed all the instructions on setting it up. I added this into my .vimrc file but it's not working:
" Track the engine.
Plugin 'SirVer/ultisnips'
" Snippets are separated from the engine. Add this if you want them:
Plugin 'honza/vim-snippets'
" Trigger configuration. Do not use <tab> if you use https://github.com/Valloric/YouCompleteMe.
let g:UltiSnipsExpandTrigger="<tab>"
let g:UltiSnipsJumpForwardTrigger="<c-b>"
let g:UltiSnipsJumpBackwardTrigger="<c-z>"
I checked that is not used anywhere in the rest of my .vimrc file. When I pritn 'cl' and press tab nothing happens. However, I am expeting it to offer me insert snippet for the python class.
This is the list of plugin I am using:
ctrlp
jedi-vim
SumpylFold
ultisnips
vim-airline
vim-airline-themes
vim-fugitive
Vundle
indentpython
nerdtree
vim-nerdtree-tabs
syntastic
vim-flake8
What am I missing here?
I got answer here answer to my question. This is some clarification:
I added this line from the documentation of UltiSnips let g:UltiSnipsSnippetDirectories=["UltiSnips"] to the .vimrc file and it's working fine now. It wasn't obvious in my case, though.

Snipmate doesn't expand anymore

Snipmate used to expand snippets, but it stopped working. I changed a few
unrelated things in my vimrc, but I don't know what caused it (and I have no
backup of the old file).
My investigation so far:
Pressing tab doesn't expand and instead inserts whitespace, check :verbose imap:
i <Tab> * =TriggerSnippet()<CR>
Last set from ~\vimfiles\bundle\snipmate.vim\after\plugin\snipMate.vim
Seems reasonable, I wonder what happens if I type <C-R>=TriggerSnippet()<CR> manually? Same result, whitespace is inserted. Weird.
I edited in a few :echo statements into the TriggerSnippet() source code, apparently the function is not executed at all?
Type def in a Python file, position the cursor on the f or on a space next to it, enter :call TriggerSnippet(). This time the function actually runs (debug echos visible), but no expansion. But maybe it really wants to be called from insert mode, not from ex.
Running the following piece of code I found in this question gave an empty result:
fun! GetSnipsInCurrentScope()
let snips = {}
for scope in [bufnr('%')] + split(&ft, '.') + ['_']
call extend(snips, get(s:snippets, scope, {}), 'keep')
call extend(snips, get(s:multi_snips, scope, {}), 'keep')
endfor
return snips
endf
echo keys(GetSnipsInCurrentScope())
----> []
Weird. Why can I run TriggerSnippets via an ex command but not via <C-R>=? What does it mean that there are no snippets defined? Even more important, how do I fix it?
As for my config, nothing in my vimrc mentions Snipmate, I installed it via pathogen on Vim 7.4 on Win7, it worked before. I'm using the latest git version (installed it yesterday and it worked) of Snipmate and the git tree is clean (except for the few debug statements, but it doesn't work without them either).
Edit: Updated after Conspicuous Compiler's explanation about s: variables.
Edit 2: Plugins I have installed using Pathogen: ctrlp-py-matcher
ctrlp.vim,
jedi-vim,
pytest-vim-compiler,
python-mode,
snipmate.vim,
syntastic,
vim-easymotion,
vim-fugitive,
vim-sensible,
vim-sleuth,
I had a snipmate clone from an ancient repository installed. I still have no idea why it worked and then suddenly stopped.
Pro tip for others: check where you get snipmate from. It needs to be (at the time of writing):
https://github.com/garbas/vim-snipmate
If you're using snipmate.vim, get rid of it and install the correct one. Note that the new vim-snipmate has a few dependencies that you need to install as well (see the github repo).
If you are chaning things already, you might also consider switching directly to ultisnips, which seems to be the modern (2015) replacement for snipmate. It requires a vim with +python support, though.

Why vim's <Leader> key not working when I want to use bufexplorer or vim-buffergator plugin?

I am using Ubuntu now.
I used vundle installed bufexplorer and vim-buffergator plugin for vim. But when I type ¥be or ¥b, the <Leader> key ¥ not working in the vim editor. Is it necessary to set something in the ~/.vimrc file?
I didn't meet this problem until now, even I used Ubuntu or CentOS before.
Check out whether the mappings have actually been defined via:
:verbose nmap <Leader>b
This will also show what key the <Leader> key is configured to. If there's no output, check whether the plugin has been correctly installed (output of :scriptnames lists the plugin script, commands like :BufExplorer are available, etc.)
vim-buffergator explanation mentioned conflict with bufexplorer.
From https://github.com/jeetsukumaran/vim-buffergator :
[NOTE: If you have other plugins installed that have key maps that start with "<Leader>b" (e.g., BufExplorer, which uses "<Leader>bs", "<Leader>bv", etc.), then you may notice a slight delay or lag when typing the default "<Leader>b" to start Buffergator. In this case, you should either use another keymap for Buffergator or BufExplorer.]

vim-cucumber doesn't find definitions

I'm trying to switch to Vim from Sublime. I do a lot of Cucumber work. A Sublime plugin allows me to jump from the step in feature file to the corresponding step definition. It looks like vim-cucumber is designed for that purpose as well. I've installed vim-cucumber using Vundle. However, when I use any of the commands in the vim-cucumber readme (e.g. [<C-d> or <C-W>d) I always get E388: Couldn't find definition. Is there some prior command or configuration I need to run to load the existing definitions for vim-cucumber to work?
The mappings used by that plugin override buit-in mappings that do more or less the same thing (but not for cucumber so that's alright).
The error message you get is associated with those buit-in mappings (:help e388) so it looks like the buit-in mappings are not overriden and thus that your plugin is not installed correctly.
romani, thanks for pointing me in the right direction. To fix the issue:
I removed vim-cucumber from my Vundle plugin list in .vimrc
executed :PluginClean
removed some references to cucumber.vim in my .vim directory that I think I added either via pathogen or manually at some point
added the plugin back in to .vimrc
executed :PluginInstall
Looks like jumping to definitions is working. Thanks.

I Can't work with NERDCommenter

I installed NerdCommenter like how it should be installed. And I read the help files. So, for commenting a line I need to do <leader>c$.
I also read that the leader key is \ by default. But it didn't work for me. I never used the leader key so I think I am doing something wrong.
Can anybody help me for using the basic commenting and uncommenting selected lines using nerdcommenter?
Problem
On many non-English keyboards, the backslash \ is only accessible through a AltGr key combination. This makes the default setting of the <Leader> character rather impractical for these users. Moreover, <Leader> key combinations are subject to a default 1000ms time-out. This can be observed by the disappearance of the <Leader> key at the right edge of the command line.
So, non-English keyboard users need to be real quick typists for \cc to work. Failure to do so, results in an undesired cc line change.
Here is an example of a German keyboard layout with the backslash-bearing key on the top row, third from right:
Solution
Non-English keyboard users are advised to change the <Leader> key from the \ character to the more accessible , key. Vim beginners should also consider a slightly longer 1500ms time-out. Here is what needs to be added to ~/.vimrc
let mapleader=","
set timeout timeoutlen=1500
One final caveat; these changes only take effect after completely exiting Vim. Resourcing with :source $MYVIMRC will not work!
Now, one can use ,cc for commenting with NERD Commenter.
I had the same problem, and I was noticing that it wouldn't flat out deny the command, but would say "No Error" and just not do anything. I read the install instructions for NERDCommenter very carefully and noticed this bit:
After the 'Classic' or 'Pathogen' install, make sure that you have
filetype plugins enabled, as the script makes use of |'commentstring'|
where possible (which is usually set in a filetype plugin). See
|filetype-plugin-on| for details, but basically, stick this in your
vimrc:
filetype plugin on
Even though I'd used NeoBundle rather than Pathogen, I tried that, and after a restart, voila. Hope it helps.

Resources