I Can't work with NERDCommenter - vim

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.

Related

Vim8 cannot delete letters

I installed a vim 8.1 on the cluster I am using in my home folder. I also installed a number of plugins including YouCompleteMe. I then made an alias so that I can open the vim easier.
However, I found that my vim cannot delete letters very well. When I am writing I can delete what I just typed. But if I move the cursor to other places, then it cannot delete letters at all, unless I type in something at first.
I am using a Scientific Linux system developed by the Fermi Lab.
How can I solve this problem?
Thanks
This sounds like the default configuration of the :help 'backspace' option. If this doesn't contain start, you cannot remove characters over the start of insertion by pressing Backspace, only what got inserted before. Removal of characters via the x or d commands (:help deleting) should always work - anywhere. Else, you have a serious misconfiguration should inspect your ~/.vimrc and re-add plugins one by one.
If you're new to Vim (and using backspace for deletion in insert mode is a typical approach of people used to other, modeless editors), you should spend 30 minutes on the vimtutor that comes with it (see :help vimtutor). Then, there are several good resources, cheatsheets, and vi / Vim tutorials out there on the net. http://vimcasts.org/ has several short entertaining episodes that go beyond the basics.
Your problem could be fixed by putting
set backspace=indent,eol,start
into your ~/.vimrc. Also have a look at :help defaults.vim; by including that instead, you'll get other goodies and recommended settings as well! (The reason for the odd defaults is backwards compatibility.)

How do i comment/uncomment with macvim

How do you comment and uncomment out a code block with janus macvim
The janus documentation for nerdcommenter says that binding is
Janus binds command-/ (`<D-/>`) to toggle comments
What does that mean in keystrokes...my leader key is the comma
UPDATE
After reading the nerdcommenter doc it seems like that might not be what i need to comment...any ideas
It just means pressing keys ⌘/.
The Cmd key (or Apple key on old keyboards) is represented in MacVim as <D>.
That key can only be seen by MacVim in "GUI mode". This means that, like with a lot of crap in Janus and other distributions, you end up learning someone else's crappy non-portable mappings instead of your own cross-platform mappings.
The <D-key> notation means exactly the same thing as the usual Cmd+key so <D-/> is the same as Cmd+/: press the Cmd key, press the / key and release both at the same time. Like in TextMate.
NERDCommenter is a popular commenter plugin. Why the Janus maintainers chose it over other plugins is unknown but it works well.
Press the Command (⌘) and forward slash (/) keys simultaneously. You can prefix this with a modifier (e.g. number of lines) for more complicated effects.

Double-slash in Janus/Vim used to maximize a pane. Doesnt work anymore. Any idea why?

My old Vim setup using Janus had a helpful shortcut for maximizing a given pane in a split pane environment: Press slash twice. This shortcut doesnt work since I changed computers and setup Janus again. Was this some obscure plugin that I dont remember and just can't find or was it a janus preset that got discontinued? Either ways...how do I get it back?
It was actually double backslash. I'm not sure when it got replaced, but now it's \zw (for "ZoomWin"). To get it back, put this in your .vimrc.after:
call janus#add_mapping('zoomwin', 'map', '<Leader><Leader>', ':ZoomWin<CR>')
(<Leader> is a special key that can be mapped to anything, but it's backslash by default (and in Janus). You could also specify the mapping as '\\'.)
You can maximize a pane with <C-w>_ (see :help CTRL-W__). If you want to see what a key is mapped to try :map //. You could always set this up again with nnoremap // <C-w>_.

While moving the cursor across a vim process open in a tmux session, every now and then, why does it leave a trail of ghost characters - ^[OB, ^[OA?

These disappear if I do a page-up and page-down. Why does this happen and how do I rectify it?
http://i.stack.imgur.com/DnMYl.png
I recently fiddled around with my vimrc. Could that be the cause?
UPDATE:
I figured out the cause. I had added to functions that automatically updated the cwd name and the current git branch in my vim statusline. This caused vim to be laggy and everytime it lagged on a up/down/left/right key hit, it printed out the ghost characters ^[OA, etc.
It's possible that stuff got complicated because I was using vim in tmux, but I saw the ghost characters outside tmux also. So, probably not.
I've turned off those two functions in my .vimrc and my vim statusline is presently less awesome than it used to be :(
Wish there's a way out.
^[OB and ^[OA are how your terminal represent <down> and <up>.
I've seen these (and their friends ^[OC and ^[OD) appear in the "command line" or omni-completion menus and during usage of a couple of plugins in vim in tmux.
My solution was to map them to the directional keys:
map ^[OA <up>
map ^[OB <down>
map ^[OC <right>
map ^[OD <left>
In case you don't know, you must not type ^[ as two characters, you must do <C-v><Esc>.
That is, while in --INSERT-- mode press the Control key and the V key together then hit the Escape key. Doing so will input the correct single character that looks like ^[.
This issue is discussed at length on the Vim Wiki article. There seem to be multiple causes, I personally encountered this issue when running vim under tmux.
A solution from there that worked for me and seems less hacky than mapping the keys was the following config:
set term=cons25
Hard to say without knowing what's in your vimrc, but you can confirm whether it's something in there by starting it up without running it and seeing if it still happens using the following...
vim -u NONE
Do you happen to be using zsh? I had this issue with vim + zsh/oh-my-zsh. Moving back to vanilla bash solved this issue (amongst others) that I was having with vim.

Delete Key is changing letter case in Vim

I'm trying to get into Vim. I'm running it in the terminal on OS X.
Anytime I hit the delete key, it simply changes case of that letter instead of deleting it. When I SSH into my server and use Vim there, it deletes normally.
Any ideas what may be going wrong?
The problem
The Del key generates the code ^[[3~ in my urxvt terminal on GNU/Linux, and might generate a similar code in your OS X terminal.
My theory is that Vim for some reason doesn't recognize any keybinding for the delete key, and simply tries to interpret the string ^[[3~ as input instead. ^[ is the keycode for the Esc key (which puts you in normal mode), and ~ is the Vim command for changing the case of a letter (from normal mode).
You can confirm the keycodes I mentioned by pressing Ctrl+V Esc and Ctrl+V Del from insert mode in Vim. Ctrl+V means that the next character should be inserted as text instead of being interpreted by the editor.
The solution
As for the solution, try editing your Vim configuration file (presumably ~/.vimrc):
vim ~/.vimrc
And append the following code to it:
nmap <Ctrl-V><Del> x
imap <Ctrl-V><Del> <Ctrl-V><Esc>lxi
I hope this helps :)
The problem was that in my .vimrc I had
set term = ansi
Took that out and all was well - sorry about the troubles, thanks!
Well, this took forever for me to resolve. When using vim I was in Iterm2 on macOSx to access a Centos5 system via gnu screen. Not only was the delete key changing the letter case, and causing delays in vim, but also the arrow keys didnt work. I think the problem was simply in the old configuration on the Centos5 machine, but may have had something to also do with either iterm or gnu screen, but i hadnt had this issue at all on any Centos6 systems.
What did Not work:
I compile vim 7.4, that did not resolve it, so don't go down that path.
I also tried these configurations that did not work
"set term=ansi
"set backspace=indent,eol,start
"set nocompatible
"fixdel
":if &term == "xterm"
":if &term == "xterm-256"
": set t_kD=^V<Delete>
":endif
"nmap <Ctrl-V><Del> x
"imap <Ctrl-V><Del> <Ctrl-V><Esc>xi
I finally found the solution.
Solution: Set the following in .vimrc
set term-builtin_xterm
Additionally, you may also notice that 256 colors have an issue on this same system. So if it helps, you can check your TERM environment variable echo $TERM. If it is xterm you can switch it to 256 colors, e.g. export TERM='xterm-256color to get the color schemes back on track for this same system. reference
I had the same issue where vim suddenly interpreted keys differently.
The answer for me was that the environment variable $TERM had somehow been to to 'dumb' in my terminal.
I added
export TERM=xterm-color
to ~/.bashrc (in my case) and that fixed all the issues with keys; DEL worked as expected etc.
I didn't need to add or change anything in ~/.vimrc
I should mention this affected more than just vim for me - if you also see 'less' behave differently for example, you may have the same cause as I did.
I use vim regularly on my OSX machine (vim version 7.2.108), and I do not have this issue. Try renaming your vimrc file and then reload vim, and see if the issue persists. If there is no issue after renaming you vimrc file, then your issue is in that file.
On my machine, my vimrc file is pretty much empty:
set ruler
set tabstop=2
set cindent
set number
syntax on
None of these solutions worked for me, until I found a solution on the vim fandom website.
Those solutions are for a similar problems with arrow keys, which I was experiencing in addition to the delete key problem.
Solution 8 fixed it for me, the problem was that I had remapped <Esc> to <Esc>l in order to move the cursor right every time I entered normal mode, evidently this caused any other key code with included ^[ (which is the escape code) including the arrow keys ( ^[OA ^[OB etc ) and the delete key ( ^[[3~ ) to be misunderstood.
Removing the offending line from my .vimrc fixed the problem.

Resources