简体   繁体   中英

Vim - ab for each language

I try to write :ab in Vim for faster coding but the question is can I write ab for each language .

Like in HTML : I write begincode : I'll be HTML DOC TYPE

in C++ : It'll be int main () { return 1; };

I'm a new beginner in Vim and I miss intellisense in visual studio, can I have it in Vim . I mean not only for C++, but another language too :)

Thanks for reading .

You can write filetype plugins for the languages you'd like abbreviations for.

There's a full section in the documentation about this - type :help ftplugin within vim, or see it online . The ftplugins are named after the filetype they run for, for example cpp.vim for C++ code.

If this is just for you, you can place your filetype plugin in ~/.vim/ftplugin . For a example, for ~/.vim/ftplugin/cpp.vim you could write:

ab begincode int main () { return 1; };
ab authorheader /* Programmer: nXqd */
...

If you're interested, you can see all the built-in filetype plugins in the vim install's ftplugin directory - on most systems, that's /usr/share/vim/vimXX/ftplugin , where vimXX is the vim version (eg vim72 for Vim 7.2). If you have any additional ones installed system-wide, they'd be in /usr/share/vim/vimfiles/ftplugin .

Instead of going for your own file type plugin, i would strongly recommend c.vim plugin for you. That is one of the largely used vim plugin, where a lot of facilities are available including the one which you are asking for.

Very first, it has lot of shortcuts for frequently done things as, \\im for including the main function. And according to the type of the file, and not for all files. And you can also include your own predefined codes, and get it using shortcuts.

Have a look at this for more clarification: c++ IDE

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM