Picon

Switching between sets of keybindings in vim

There are times where I want to switch between an entire set of
keybindings/commands depending on the type of file I'm editing. For
example, if I'm using C/C++, I'd like to (hypothetically) have a
shortkey <C-f> to create an for loop block as such:
for (i=0;i<b;i++) {
<TAB>
}

But in python, I'd like it to do;
for i in range (b):
<TAB>

or it's equivalently for bash or any other language.

I'm wondering how I would do this with Vim.

Another thing I'd like to do is create a generic function to insert
snippets like <C-I>f would insert a for loop, <C-I>i a if block, etc. My
doubt is how to send the 'f', 'i' as arguments to a vim function, and in
the function how to access the filetype, etc.

--

-- 
Arun Tejasvi Chaganty (vimzard)
Blog: http://arunchaganty.wordpress.com

_______________________________________________
To unsubscribe, email ilugc-request@... with 
"unsubscribe <password> <address>"
(Continue reading)

Girish Venkatachalam | 10 May 00:47
Picon

Re: Switching between sets of keybindings in vim

On 19:28:24 May 09, Arun Tejasvi Chaganty wrote:
> There are times where I want to switch between an entire set of
> keybindings/commands depending on the type of file I'm editing. For
> example, if I'm using C/C++, I'd like to (hypothetically) have a
> shortkey <C-f> to create an for loop block as such:
> for (i=0;i<b;i++) {
> ???<TAB>
> }
> 
> But in python, I'd like it to do;
> for i in range (b):
> <TAB>
> 
> or it's equivalently for bash or any other language.
> 
> I'm wondering how I would do this with Vim.
> 
> Another thing I'd like to do is create a generic function to insert
> snippets like <C-I>f would insert a for loop, <C-I>i a if block, etc. My
> doubt is how to send the 'f', 'i' as arguments to a vim function, and in
> the function how to access the filetype, etc.
> 

Some vim scripting can take you places.

I have no exact answer for your question as I have not wanted what you
want so far.

How about asking this in a vim specific list? There will be many gurus
there.
(Continue reading)

Picon

Re: Switching between sets of keybindings in vim

I've found this amazing plugin: SnippetsEmu which does what I want and
so much more (thanks to Vimal for pointing it out to me). Thank god the
code is open, so I'll be hacking through it to learn something. Can you
point me to some good vimscripting tutorials perhaps?

--

-- 
Arun Tejasvi Chaganty (vimzard)
Blog: http://arunchaganty.wordpress.com

_______________________________________________
To unsubscribe, email ilugc-request@... with 
"unsubscribe <password> <address>"
in the subject or body of the message.  
http://www.ae.iitm.ac.in/mailman/listinfo/ilugc
Sykora | 10 May 11:08
Picon

Re: Switching between sets of keybindings in vim

> On 19:28:24 May 09, Arun Tejasvi Chaganty wrote:
>> There are times where I want to switch between an entire set of
>> keybindings/commands depending on the type of file I'm editing. For
>> example, if I'm using C/C++, I'd like to (hypothetically) have a
>> shortkey <C-f> to create an for loop block as such:
>> for (i=0;i<b;i++) {
>> ???<TAB>
>> }
>>
>> But in python, I'd like it to do;
>> for i in range (b):
>> <TAB>
>>
>> or it's equivalently for bash or any other language.

You can do this with filetype plugins. These are plugins that are
loaded only when a particular filetype is being edited.

Basically, you put whatever filetype specific commands you want in the
file ~/.vim/ftplugin/≤filetype>.vim

where <filetype> is the filetype, eg c.vim for c files, python.vim for python.

See :help filetype and :help filetype-plugins

>> Another thing I'd like to do is create a generic function to insert
>> snippets like <C-I>f would insert a for loop, <C-I>i a if block, etc. My
>> doubt is how to send the 'f', 'i' as arguments to a vim function, and in
>> the function how to access the filetype, etc.

(Continue reading)


Gmane