1

Re: Mapping custom functions.

I am evaluating viemu for VS and one thing that I have noticed is that I cannot create my own functions and then map them to a key. For example in vim I have a function Komment which I mapped to ctr-k. Simple little thing which comments out (c style) a line of code. How can I create this using viemu with VS. I do not really care where I set it, as long as I get a fast way of commenting out a line or region of code.

2

Re: Mapping custom functions.

Hi Eric,

You can assign it from VS's system: go to Tools|Options|Keyboard, type "Edit.CommentSelection", and assign Ctrl-K to it. You need to either activate "Use VS Selection for visual mode", or use gS before triggering it. You will also need to do remove all two-key assignments which start with Ctrl-K, of which there are a few, too.

It can also be done using ViEmu's :vscmd ex command, which calls a VS command. Let me know if the above method doesn't suit you.

Best regards,

  Jon

3

Re: Mapping custom functions.

Thanks Jon, that trick worked. The problem is that I had to assign another key for uncomenting code. With my little vim function, ctr-k would comment code out or uncomment it if it was already commented. I have some other little vim utility functions which I would like to “bring over” to VS land. Do you plan to support this in the future?

Thx for writing viemu!

4

Re: Mapping custom functions.

Hi Eric,

This can be done with VS's macro language, it makes more sense than implementing the viml scripting language in ViEmu.

The basic trick is that you can assign Ctrl-K to run a VS command *or* macro:

  :nnoremap <c-k> :macro MyMacros.Module1.myMacro<cr>

And you can do whatever you want in that macro. I would scan for the first couple of characters of the selection (if there is a selection) and detect whether to call Edit.CommentSelection or Edit.UncommentSelection depending on that. It's language dependent, but you can check the current file's extension if you use several languages.

It can be a little bit convoluted, but it shouldn't be too complex and should work fine.

Let me know if there is some other area which is not quite clear enough.

Best regards,

  Jon