亚洲在线久爱草,狠狠天天香蕉网,天天搞日日干久草,伊人亚洲日本欧美

為了賬號安全,請及時綁定郵箱和手機立即綁定
已解決430363個問題,去搜搜看,總會有你想問的

大神,請問該怎么設置vim,使得創建一個.cc的c++文件?

大神,請問該怎么設置vim,使得創建一個.cc的c++文件?

慕娘9325324 2022-04-08 15:11:39
1 #include <iostream>2 #include <string>34 using namespace std;56 int main(int argc,char **argv)7 {8 return 0;9 }~~
查看完整描述

3 回答

?
小怪獸愛吃肉

TA貢獻1852條經驗 獲得超1個贊

set nobackup
syntax on
set cursorline
set autochdir
set syntax=cpp
set nocompatible
set tabstop=4
set expandtab
set softtabstop=4
set shiftwidth=4
set cindent
set nu
set guifont=Consolas:h10
syntax enable
if has('gui_running')
set background=dark
else
set background=dark
endif
colorscheme solarized

source $VIMRUNTIME/vimrc_example.vim
source $VIMRUNTIME/mswin.vim
behave mswin

set diffexpr=MyDiff()
function MyDiff()
let opt = '-a --binary '
if &diffopt =~ 'icase' | let opt = opt . '-i ' | endif
if &diffopt =~ 'iwhite' | let opt = opt . '-b ' | endif
let arg1 = v:fname_in
if arg1 =~ ' ' | let arg1 = '"' . arg1 . '"' | endif
let arg2 = v:fname_new
if arg2 =~ ' ' | let arg2 = '"' . arg2 . '"' | endif
let arg3 = v:fname_out
if arg3 =~ ' ' | let arg3 = '"' . arg3 . '"' | endif
let eq = ''
if $VIMRUNTIME =~ ' '
if &sh =~ '\<cmd'
let cmd = '""' . $VIMRUNTIME . '\diff"'
let eq = '"'
else
let cmd = substitute($VIMRUNTIME, ' ', '" ', '') . '\diff"'
endif
else
let cmd = $VIMRUNTIME . '\diff'
endif
silent execute '!' . cmd . ' ' . opt . arg1 . ' ' . arg2 . ' > ' . arg3 . eq
endfunction
" set the menu & the message to English
set langmenu=en_US
let $LANG= 'en_US'
source $VIMRUNTIME/delmenu.vim
source $VIMRUNTIME/menu.vim
"Toggle Menu and Toolbar
set guioptions-=m
set guioptions-=T
map <silent> <F2> :if &guioptions =~# 'T' <Bar>
\set guioptions-=T <Bar>
\set guioptions-=m <bar>
\else <Bar>
\set guioptions+=T <Bar>
\set guioptions+=m <Bar>
\endif<CR>

"turn off vim compatible check
set nocompatible
"check file type
filetype on
"histroy line count
set history=1000
"set background
set autoindent
set smartindent
"show match '(' and ')'
set showmatch
"left-down status line
set ruler
"auto match targets
set incsearch
"high light search
set hlsearch
"auto backup file with filename+~
"set backup
set title
set foldenable
"fold code by syntax 'cmd':
"'zi' open/close all folds
"'za' open/close current fold
"'zM' close all folds
"'zR' open all folds
set foldmethod=indent
"set foldmethod=marker
"set foldmethod=indent
set foldcolumn=0
set foldopen=all
"set foldclose=all
"colorscheme evening
"set cinoptions+={2,0,p0,t0
set cindent
set syntax=cpp
set formatoptions=tcqr
set nu
function MyTitle()
call setline(1,"/**************************************")
call append(line("."), "Author : Pegasus")
call append(line(".")+1,"Time :".strftime("%c"))
call append(line(".")+2,"FileName:".expand("%"))
call append(line(".")+3,"Desc :")
call append(line(".")+4,"*************************************/")
endf
"add header
map <F9> <Esc>:call MyTitle()<CR><Esc>:$<Esc>o<Esc>
function CppFramework()
call setline(8,"#include <iostream>")
call setline(9,"#include <cstdio>")
call setline(10,"#include <cmath>")
call setline(11,"#include <algorithm>")
call setline(12,"using namespace std;")
call setline(13,"int main()")
call setline(14,"{")
call setline(15," return 0;")
call setline(16,"}")
endf
"add cpp framework
map <F10> <Esc>:call CppFramework()<CR><Esc>:$<Esc>2ko
function AddComment()
if &syntax=="cpp" || &syntax=="c"
execute "normal \<Esc>\<S-$>a\<TAB>/* */\<Esc>2ha"
elseif &syntax=="py"
execute "normal \<Esc>\<S-$>a\<TAB>#\<Esc>2ha"
elseif &syntax=="lua"
execute "normal \<Esc>\<S-$>a\<TAB>--\<Esc>2ha"
endif
endf
"add comment
map <F4> <Esc>:call AddComment()<CR>i
function CommOneLine()
let tmp=getline(".")
call setline(line("."),"/*")
call append(line("."),"".tmp." //by Pegasus ".strftime("%c"))
call append(line(".")+1," */")
endf
map <F5> <Esc>:call CommOneLine()<CR><ESC>
"foramt code with K&R style
map <F8> <Esc>:1,$g/^$/d<CR><Esc>gg=G<Esc>gg
let $Tlist_Ctags_Cmd='/usr/bin/Ctags'
map <F7> <Esc>:TlistToggle<CR>

"big header
map <F11> <Esc>:call MyTitle()<CR><Esc>:$<Esc>o<Esc>
function BigCppFramework()
call setline(8,"#include <iostream>")
call setline(9,"#include <cstdio>")
call setline(10,"#include <string>")
call setline(11,"#include <cstring>")
call setline(12,"#include <vector>")
call setline(13,"#include <list>")
call setline(14,"#include <deque>")
call setline(15,"#include <map>")
call setline(16,"#include <set>")
call setline(17,"#include <stack>")
call setline(18,"#include <queue>")
call setline(19,"#include <algorithm>")
call setline(20,"#include <functional>")
call setline(21,"#include <cmath>")
call setline(22,"#include <cstdlib>")
call setline(23,"#include <ctime>")
call setline(24,"using namespace std;")
call setline(25,"int main()")
call setline(26,"{")
call setline(27,"#ifndef ONLINE_JUDGE")
call setline(28," freopen(\"in.txt\", \"r\", stdin);")
call setline(29,"#endif")
call setline(30," return 0;")
call setline(31,"}")
endf
"add cpp framework
map <F12> <Esc>:call BigCppFramework()<CR><Esc>:$<Esc>2ko
function BigAddComment()
if &syntax=="cpp" || &syntax=="c"
execute "normal \<Esc>\<S-$>a\<TAB>/* */\<Esc>2ha"
elseif &syntax=="py"
execute "normal \<Esc>\<S-$>a\<TAB>#\<Esc>2ha"
elseif &syntax=="lua"
execute "normal \<Esc>\<S-$>a\<TAB>--\<Esc>2ha"
endif
endf

上面是我的vimrc文件,你用一下這個專門對c++的,然后再命令模式下按ctrl +F9再ctrl+F10



查看完整回答
反對 回復 2022-04-11
?
交互式愛情

TA貢獻1712條經驗 獲得超3個贊

使用 vim 的 autocmd 命令可以實現,但是更簡單的方式是在 shell 中用腳本語言重新定義 vim 命令,使文件名參數匹配 *.cc,并且是一個新文件時,先把固定模型寫入新文件再開始編輯。


查看完整回答
反對 回復 2022-04-11
?
慕俠2389804

TA貢獻1719條經驗 獲得超6個贊

vim沒這功能吧。
你實現做一個template.cc文件,需要的時候:
cp template.cc newfile.cc
不就行了。

查看完整回答
反對 回復 2022-04-11
  • 3 回答
  • 0 關注
  • 190 瀏覽
慕課專欄
更多

添加回答

舉報

0/150
提交
取消
微信客服

購課補貼
聯系客服咨詢優惠詳情

幫助反饋 APP下載

慕課網APP
您的移動學習伙伴

公眾號

掃描二維碼
關注慕課網微信公眾號