How do i comment/uncomment with macvim - vim

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.

Related

Map Alt-j to <Esc><j> in IdeaVim

I am now really used to send escape to Vim in my terminals using the Alt(Meta) key + a movement (like 'j'). Using any "Vim plugin" in IDEs becomes a pain, because they usually do not forward the alt keypress to the emulator plugin.
For example, I cannot obtain this behavior in IdeaVim.
I tried to :map <A-j> <Esc><j>, and also to edit the keymaps for IdeaVim in File->Settings without any success.
Does someone know if this is possible ?
As of IdeaVim 0.33 (released 2014-04-28), key mappings in ~/.vimrc are now supported.
Release announcement
VIM-288
(Note: This question could probably be considered a duplicate of this other StackOverflow question.)
:map, :vmap, and the like are not currrently supported by IdeaVim. However you can vote for them to be implemented in the IdeaVim Bugtracker.
If you want this behaviour now you could use AutoHotKey and the following line:
; Remap <A-j> to <Esc><j>
!j::Send {Escape}{j}
Note that this will remap the keys everywhere not just in vim
ideavim Mappings are only supported at a very basical level. Like map j h. I tried mapping jj to and it didn't work myself, awhile ago. It seems the multi-letter keystrokes don't work in insert mode. Which kind of makes sense as this is emulating vim, and it has to go through, and abide by the key event API of a CUA.

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.

Vim langmap breaks plugin (bépo)

I am using a bépo keymap (http://bepo.fr) and seeking the perfect vim mapping.
So far I used a long list of noremap, but for many binding (for exemple, the motion aw or Ctrl+r), the first keystroke is well remaped but not the others, I reckon it's the expected behaviour, but then this is not what I need.
Ideally I would have my keyboard totally remaped in a higher level (before the map commands) except when typing text (in insertion mode and when typing a substitution for exemple). What I'm looking for seems to be langmap, but I have problems using it.
I added this langmap to my .vimrc, It seems perfect but it broke some of my plugins. SuperTab now insert <Plug>SuperTabForward when pressing Tab in insertion mode, I have t<SNR>24_SelectCompletion(1) when pressing enter.
Does someone know how to fix this langmap issue or a better way to remap my keyboard?
This is a known bug, that has been discussed before. I have made a patch (see the thread starting here) and hopefully Bram will include this change soon.
Update 11/05/2014
This has been fixed by patch 7.4.502. Use the langnoremap option to fix this.

Remapping a key to Escape in Vim (German keyboard)

Okay, so I've been trying out Vim (the standard console version; my OS is Linux Mint 13) and I'd like to get rid of having to use the Escape key to change modes. Preferably, I'd like to swap the Capslock and Escape keys, but as far as I've heard, that's not possible within Vim itself. Most "solutions" I've found involve changing the key on a global level (using xmodmap or whatever), but I don't really want that. If there's an easy way to swap Capslock and Escape only in Vim, please let me know.
Another common thing I've heard of is using "Ctrl-[" as an equivalent to Escape. However, because I'm using a German keyboard with a different layout, that's not an option. So, I thought I'd use noremap <C-ü> <Esc> in Vim (the "ü" key on a German keyboard is in the same place as the "[" key on US keyboards), but that didn't work, either. I'm assuming that's because "ü" isn't an ASCII character. Is there any way to get either of these options working?
UPDATE: Well, this is strange. After experimenting some more, it seems that "Ctrl-ü" does work after all. I'm not sure what happened – maybe I messed up some encoding-related settings while trying different things? If there is no good solution for remapping capslock, I guess I will stick with "Ctrl-ü".
So, yeah, eventually I decided to go with <C-ü> because it doesn't conflict with anything else and because it's the same as <C-[> on US keyboards.
However, because I'm getting tired of using the German keyboard layout for programming (for example, to get "{" you need to type "Alt Gr-7"), I'm switching my keyboard to US-International, which essentially has a similar effect as far as Vim is concerned. It also helps if you want to want to get into the habit of touch-typing; you actually can't look at the keyboard because the keys aren't labeled "correctly" ;-)
A lot of people use jk:
inoremap jk <Esc>
You can also simply do <C-c>.
Here is another alternative that may be useful to you! It involves changing the keyboard file related to VIM. I found this suggestion on this youtube video
$ cd /usr/share/X11/xkb/symbols/
sudo vim pc
to edit the capslock key to escape, change the capslock line to read as follows:
key <CAPS> { [ Escape ] };
:wq # to write and close the file
Log out and log back into the machine and it should be updated!

"M-" bindings in vim on iTerm2/Terminal don't work

I noticed that iTerm2 offers the very convenient feature of using "Option key as +ESC" (or as meta, but apparently that's obsolete).
I tried them both and the option key works as expected in Bash (set -o emacs mode) and Emacs, but not in Vim. Thus, I can't make use of any "M-" bindings.
What I've found is that:
if I set option to "+ESC", vim just understands ESC+key, and has no idea I actually meant Meta-key.
if I set option to "meta", keys modified with "option" behave just as without a modifier (don't know how to formally test what vim understands from a key combination that I'm typing).
"M-" mappings work perfectly in MacVim (7.3.53), but that's outside of a console and not in the scope of this question.
I'm interested in how to make those mappings work in Vim, under iTerm2 or Terminal.
My specs:
MAC OS X Lion 10.7.2
iTerm2 1.0.0.20111020
vim #7.3.107_0+python26 [though MacPorts]
I've downloaded the latest iTerm2 and tried to see what it sent to/what was printed by Vim (i<C-v><M-a>) with the following settings:
Option as Option:
Vim prints æ which is normal and expected on my french keyboard
Option as Meta:
Vim stays there, waiting for something to happen. Nothing is printed. If I press Option and a in sequence I just obtain a. Pressing Option and a in some random order may print á, which is weird and totally unexpected.
Option as +ESC:
Vim prints ^[a which means "Escape character followed by the character a".
From these tests it appears that Vim will never ever receive <M-> without some hypothetical black magic.
If you stick with "Option as +ESC", it seems that you will have to change all your custom <M-something> mappings to <Esc>something. This may work but it will make writing any kind of prose in any non-english language a pain.
What I do: I leave the Option key as it is so that I can type characters like œ…«» easily and I use <Leader> (mapped to ,, see :help mapleader) for all my custom mappings.
Some people here like to reserve it for plugins and advocate a somewhat simpler and potentially safer approach.
inoremap <leader>, <C-x><C-o> "my way (copied elsewhere)
inoremap ,, <C-x><C-o> "another way
I left my option key to act as Normal and discovered that Vim saw them as <T- bindings. So, for example, I have this mapping setup in my .vimrc to move to the end of a word when in Insert mode:
noremap! <T-Right> <C-o><Right>;

Resources