sodu vim /usr/share/vim/vimrc
set ai " auto indenting
set history=100 " keep 100 lines of history
set ruler " show the cursor position
syntax on " syntax highlighting
set hlsearch " highlight the last searched term
filetype plugin on " use the file type plugins自动添加#include
function InsertIncludeFileI()
let sourcefilename=expand("%:t")
let outfilename=substitute(sourcefilename,'\(\.[^.]*\)$','.h','g')
call setline('.','#include "'.outfilename.'"')
endfunction
imap <c-b><c-h> <ESC>:call InsertIncludeFileI()<CR>
function InsertIncludeFileN()
let sourcefilename=expand("%:t")
let outfilename=substitute(sourcefilename,'\(\.[^.]*\)$','.h','g')
call setline('.','#include "'.outfilename.'"')
endfunction
nmap ,hh :call InsertIncludeFileN()<CR>
本文介绍了一种使用Vim编辑器时自动插入相对应的头文件的方法。通过简单的Vimscript脚本实现了在C/C++源文件中快速添加#include指令的功能。此配置能够提高开发效率,并适用于那些频繁切换于源文件及其头文件之间的开发场景。
159

被折叠的 条评论
为什么被折叠?



