Linux下vim好用好看的vimrc配置-竞赛篇

这篇博客详细介绍了如何在Vim中配置C++和Python文件的自动模板生成,以及设置一系列快捷键,如F3至F12,用于快速打开输入/输出文件、运行、编译和执行程序。此外,还展示了如何自定义代码编辑环境,如设置高亮搜索、颜色方案和文件类型特定的代码结构。

摘要生成于 C知道 ,由 DeepSeek-R1 满血版支持, 前往体验 >

新建C++文件会自动生成基本框架

新建python文件会自动生成读入函数

  • F3 打开输入文件编辑页面
  • F4 以该输入文件运行该程序
  • F5 打开输出文件编辑页面
  • F8 运行该程序
  • F9 编译程序
  • F12 运行python程序
syntax on
set backspace=indent,eol,start
set shortmess=atI
set nu si ci ai mouse=a sw=4 sts=4 ts=4
set hlsearch incsearch
colorscheme torte
set guioptions-=m
set guioptions-=T
set completeopt=longest,menu
:cd ~/code
nmap<C-A> ggvG
vmap<C-C> "*y
nmap<F3> : vs %<.in <CR>
nmap<F4> : !/home/jk/code/%< < !/home/jk/code/%<.in <CR>
nmap<F5> : vs %<.out <CR>
nmap<F8> :call Run()<CR>
nmap<F9> :call Compile()<CR>
map <F12> :!python3 %<CR>
func Compile()
    exec "w"
        if &filetype == "python"
	    exec "!python %"
        elseif &filetype == 'cpp'
            exec "!g++ % -o %< -std=c++17"
        endif
endfunc
func Run()
    exec "w"
        if &filetype == 'java'
            exec "!java -classpath %:h; %:t:r"
        elseif &filetype == 'cpp'
            exec "!/home/jk/code/%< "
        endif
endfunc
if executable("vimtweak.dll") 
autocmd guienter * call libcallnr("vimtweak","SetAlpha",210) 
endif
autocmd BufNewFile *.cpp,*.[ch],*.sh,*.java,*.py exec ":call StTitle()"
func StTitle()
	if &filetype == 'cpp'
		call setline(1,"#include <bits/stdc++.h>")
		call append(line("."), "")
		call append(line(".")+1, "using namespace std;")
		call append(line(".")+2, "using ll = long long;")
		call append(line(".")+3, "")
		call append(line(".")+4, "int main() {")
		call append(line(".")+5, "    ios::sync_with_stdio(false);")
		call append(line(".")+6, "    cin.tie(nullptr);")
		call append(line(".")+7, "")
		call append(line(".")+8, "")
		call append(line(".")+9, "")
		call append(line(".")+10, "")
		call append(line(".")+11, "")
		call append(line(".")+12, "    return 0;")
		call append(line(".")+13, "}")
	elseif &filetype == 'python'
		call setline(1,"import sys")
		call append(line("."), "")
		call append(line(".")+1, "I = lambda: [*map(int, sys.stdin.readline().split())]")
		call append(line(".")+2, "")
		call append(line(".")+3, "")
	endif
endfunc

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值