vim配置及指令

1 篇文章 0 订阅

vim基本配置

/etc/vim/vimrc 或者 vim ~/.vimrc
复制以下内容到vimrc文件底部

set ai                          " 自动缩进,新行与前面的行保持—致的自动空格
set aw                          " 自动写,转入shell或使用:n编辑其他文件时,当前的缓冲区被写入
"set flash                       " 在出错处闪烁但不呜叫(缺省)
set ic                          " 在查询及模式匹配时忽赂大小写
set nu        
set number                      " 屏幕左边显示行号
"set showmatch                   " 显示括号配对,当键入“]”“)”时,高亮度显示匹配的括号
set showmode                    " 处于文本输入方式时加亮按钮条中的模式指示器
set showcmd                     " 在状态栏显示目前所执行的指令,未完成的指令片段亦会显示出来
"set warn/nowarn                 " 对文本进行了新的修改后,离开shell时系统给出显示(缺省)
"set ws/nows                     " 在搜索时如到达文件尾则绕回文件头继续搜索
"set wrap/nowrap                 " 长行显示自动折行
"colorscheme evening            " 设定背景为夜间模式
filetype plugin on              " 自动识别文件类型,自动匹配对应的, “文件类型Plugin.vim”文件,使用缩进定义文件
set autoindent                  " 设置自动缩进:即每行的缩进值与上一行相等;使用 noautoindent 取消设置
set cindent                     " 以C/C++的模式缩进
set noignorecase                " 默认区分大小写
set ruler                       " 打开状态栏标尺
set scrolloff=5                 " 设定光标离窗口上下边界 5 行时窗口自动滚动
set shiftwidth=4                " 设定 <<>> 命令移动时的宽度为 4
set softtabstop=4               " 使得按退格键时可以一次删掉 4 个空格,不足 4 个时删掉所有剩下的空格)
set tabstop=4                   " 设定 tab 长度为 4
set wrap                        " 自动换行显示
syntax enable
syntax on                       " 自动语法高亮
imap [ []<ESC>i  
imap ( ()<ESC>i
imap [ []<LEFT>
imap ( ()<LEFT>
inoremap ' ''<ESC>i
inoremap " ""<ESC>i
inoremap { {<CR>}<ESC>O

安装ycm插件

建议看第一个
https://blog.csdn.net/qq_41376740/article/details/79182596
https://blog.csdn.net/sanoseiichirou/article/details/53791317

快捷键

https://www.cnblogs.com/gmpy/p/11177719.html

u //撤销
d //删除
y //复制
p //粘贴
vV // 可视模式
yy 单行复制
nyy 多行复制
dG 删除到文末
ggyG 全部复制
ggvG 全选

ndd 删除光标所在行下的n行
nG 转到第n行
:x, .d 删除第x行到当前行
:x,yd 删除x-y行

vim a.cpp b.cpp
:n和:N交换光标所在文件

fX,X可用任何字符
l表示向右移一位
ct'表示删除至引号前
ct'
di'
df'
vf'hc
f'l

如何把vim里的内容复制出去:

sudo apt-get install vim-gtk

可视模式下选中需要的行,使用命令: "+y 即可
或者在vim里面复制完后,使用命令: "+y 即可

https://www.cnblogs.com/mrlonely2018/p/15118982.html
%y+
多行注释
注释符为#等::.,+499 s/^/#/g,取消注释::12,25s/^#//g
块选择模式:

注释:命令行模式下按下ctrl+v进入VISUAL BLOCK模式,使用hjkl选中需要注释的行;按下大写I进入插入模式,输入//,再按ESC即可。
取消注释:命令行模式下按下ctrl+v进入VISUAL BLOCK模式,使用hjkl选中需要取消注释的行;按x或d都行。

vim编译运行

命令模式中输入::!python %可运行python

map <F5> :call CompileRunGcc()<CR>
func! CompileRunGcc()
	exec "w"
	if &filetype == 'c'
		exec "!g++ % -o %<"
		exec "!time ./%<"
	elseif &filetype == 'cpp'
		exec "!g++ % -o %<"
		exec "!time ./%<"
	elseif &filetype == 'java' 
		exec "!javac %" 
		exec "!time java %<"
	elseif &filetype == 'sh'
		:!time bash %
	elseif &filetype == 'python'
		exec "!time python2.7 %"
    elseif &filetype == 'html'
        exec "!firefox % &"
    elseif &filetype == 'go'
        exec "!go build %<"
        exec "!time go run %"
    elseif &filetype == 'mkd'
        exec "!~/.vim/markdown.pl % > %.html &"
        exec "!firefox %.html &"
	endif
endfunc


""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""
" Quickly Run
"""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""

map <F5> :call CompileRunGcc()<CR>

func! CompileRunGcc()
    exec "w" 
    if &filetype == 'c' 
        exec '!g++ % -o %<'
        exec '!time ./%<'
    elseif &filetype == 'cpp'
        exec '!g++ % -o %<'
        exec '!time ./%<'
    elseif &filetype == 'python'
        exec '!time python %'
    elseif &filetype == 'sh'
        :!time bash %
    endif                                                                              
endfunc 

java实验3:

/**
 * Copyright (C), 2018-2019, csust
 * FileName: StoolApp
 * Author:   Cwolf9
 * Date:     2019/03/29 15:40
 * Description:
 * History:
 * <author>          <time>          <version>          <desc>
 * Cwolf9           2019/03/29           2018.3
 */

/**
 * 〈可怕的是比你强的人比你还努力〉
 * 〈〉
 *
 * @author Cwolf9
 * @create 2019/03/29
 * @since 1.0.0
 */
import java.util.Scanner;

class Circle{
    private double radius;
    private double PI = 3.1415926;
    public Circle() {}
    public Circle(double _r) {
        radius = _r;
    }
    public double getRadius(){
        return radius;
    }
    public double getPI() {
        return PI;
    }
    public double getArea() {
        return PI*radius*radius;
    }
}
class Cylinder extends Circle{
    private double height;
    public Cylinder() {}
    public Cylinder(double _r, double _h) {
        super(_r);
        height = _h;
    }
    public double getHeight() {
        return height;
    }
    public double getVol() {
        return getArea()*height;
    }
}
class Stool{
    private Cylinder top, middle, bottom;
    public Stool() {}
    public Stool(double a, double b, double c, double d, double e, double f) {
        top = new Cylinder(a, b);
        middle = new Cylinder(c, d);
        bottom = new Cylinder(e, f);
    }
    public double getArea() {
        return 2*(bottom.getArea()+top.getArea()-middle.getArea())
                +2*top.getPI()*(top.getHeight()*top.getRadius()+middle.getHeight()*middle.getRadius()
                +bottom.getHeight()*bottom.getRadius());
    }
    public double getVol() {
        return top.getVol()+middle.getVol()+bottom.getVol();
    }
}

public class StoolApp {
    static double getPaint(int n, Stool[] stools) {
        double ans = 0;
        for(int i = 0; i < n; ++i) {
            ans += stools[i].getArea();
        }
        return ans * 0.1;
    }
    static double getTimber(int n, Stool[] stools) {
        double ans = 0;
        for(int i = 0; i < n; ++i) {
            ans += stools[i].getVol();
        }
        return ans * 1.2;
    }
    public static void main(String[] args) {
        Scanner cin = new Scanner(System.in);
        int n = cin.nextInt();
        Stool[] stools = new Stool[n];
        for(int i = 0; i < n; ++i) {
            double a = cin.nextDouble(), b = cin.nextDouble();
            double c = cin.nextDouble(), d = cin.nextDouble();
            double e = cin.nextDouble(), f = cin.nextDouble();
            stools[i] = new Stool(a, b, c, d, e, f);
        }
        System.out.println(3.1415926*8);
        System.out.println(3.1415926*3*1.2);
        System.out.println("这"+n+"件凳子共需油漆:"+getPaint(n, stools)+"公斤");
        System.out.println("这"+n+"件凳子共需木料:"+getTimber(n, stools)+"立方米");
    }
}
  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 1
    评论
评论 1
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值