如何在vim中创建映射以自动化.h c ++文件的ifdef命令 [英] How do I create a mapping in vim to automate the ifdef commands for .h c++ file

查看:166
本文介绍了如何在vim中创建映射以自动化.h c ++文件的ifdef命令的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

如何在vim中创建映射以自动执行.h c ++文件的ifdef命令?基本上我想有一个映射,将创建以下将与.h和.hpp等工作。

How do I create a mapping in vim to automate the ifdef commands for .h c++ file? Basically I want to have a mapping that will create the following that will work with .h and .hpp etc

#ifndef <filename>_<extension>__
#define <filename>_<extension>__

#endif  // <filename>_<extension>__


推荐答案

只需在.vimrc文件中键入以下内容。您的.vimrc文件应该在您的主目录中。这将输出您要找的。您可以在编辑.h或.hpp文件后使用,然后点击< f12>

Just type the following in your .vimrc file. Your .vimrc file should be in your home directory. This will output what you are looking for. You can use this after editing a .h or .hpp file and just hit the <f12> key

nnoremap <f12> "%pF.r_A__<esc>I#ifndef <esc>gUwyypldwidefine <esc>yypldwiendif //<esc>O<esc>
inoremap <f12> <esc>"%pF.r_A__<esc>I#ifndef <esc>gUwyypldwidefine <esc>yypldwiendif //<esc>O<esc>i

这篇关于如何在vim中创建映射以自动化.h c ++文件的ifdef命令的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆