Vim和GCC

Vim

vim filename				# filename不存在就创建并打开
vim -p 	file1 file2 ...		# 多标签形式打开文件(gt进行切换标签页)
tabnew filename	# 已经启动vim后,命令模式下,打开指定的文件作为一个新标签页

gg# 到内容顶端
shift+g# 到内容底端
shift+k#光标停留在某个函数上时,shift+k,可以直接跳到man手册
dd# 删除光标所在行
3dd# 删除光标所在行及下面的2行(一共删除三行)
5G 光标移到第五行
o# 在当前行下面新增1行,并将光标移到新行的开头,并进入插入模式
k# 将光标移到上一行
2k# 将光标向上移两行
u# 撤销
yy# 复制光标所在行
3yy# 复制光标所在行及下面的2行(一共复制三行)
p# 在光标所在行下面进行粘贴
P# 在光标所在行上面进行粘贴

/+关键字,回车.从当前位置向下查找关键字,按n键查找关键字下一个位置,N查找上一个位置

想查看代码中使用的系统函数例如:printf的原型,光标移到那里,shift+k (等价于 man printf)
ctrl+p  自动补齐
:set nu 		 	是显示行号
:set ts=4		 	是设置tab键是4
# 可以在/etc/vim/vimrc中底部写入
# ~/.vimrc是用户级别的,只适用当前用户
# set ts=4
# set nu

敲a进入编辑模式, 编辑完之后, Esc切换到命令模式,然后:wq保存并退出
nohlsearch # 取消高亮
:colorscheme	# 查看当前使用的主题
:colorscheme空格tab	# 切换主题
#保存文件时遇到E212:Can't open file for writing
#强制保存文件
:w !sudo tee % > /dev/null

编译工具

# Centos
yum install gcc # 安装gcc
yum install gcc-c++ # 安装g++
yum clean all && yum makecache
yum install cmake# cmake版本比较低,可以官网下载解压,配置环境变量,使用

# Ubuntu
sudo apt update
sudo apt install build-essential
sudo apt install cmake

# CentOS7.9的gcc版本是4.8.5,默认的C标准是gnu89,GNU dialect of ISO C90 (including some C99 features).
# C89 and C90 both refer to the same version of the C programming language standard.C89和C90一样.
# Note that the C90 standard is the same as the C89 one with only changes in the formatting and section numbering.

常用选项

//预处理,E要大写,处理预编译指令
g++ -E test.cpp
//编译,默认生成一个 test.s的汇编文件
g++ -S test.cpp
//汇编,默认生成机器语言的test.o文件=>等价于as test.s
g++ -c test.s/test.cpp
//链接,生成a.out可执行文件
g++ test.o

//保存在编译过程当中留下来的临时文件
g++ test.cpp -o test --save-temps
-g 产生能被gdb使用的调试信息
-O2 对源代码进行一些优化,使执行效率更高
-Wall//打印警告信息
-std=c++11//设置编译标准

// When a base standard is specified,the compiler accepts all programs following that standard plus those
// using GNU extensions that do not contradict it.
// On the other hand, when a GNU dialect of a standard is specified, all features supported by the compiler are enabled,
// even when those features change the meaning of the base standard. 
// The particular standard is used by -Wpedantic to identify which features are GNU extensions given that version of the standard.

-Wpedantic
//Issue all the warnings demanded by strict ISO C and ISO C++;
//reject all programs that use forbidden extensions, and some other programs that do not follow ISO C and ISO C++.
gcc tmp.c -std=c89 -pedantic-errors
gcc tmp.c -std=c89 -Wall -Wpedantic
gcc -E -x c - -v < /dev/null

-M
//Instead of outputting the result of preprocessing, output a rule suitable for make describing the dependencies
//of the main source file.
-MM
//Like -M but do not mention header files that are found in system header directories.
gcc -M dup.c
gcc -MM dup.c

Vim的搜索技巧
vim中多标签和多窗口的使用
查看GCC默认使用的C标准
https://developerinsider.co/c-programming-language-version-history/
https://en.wikichip.org/wiki/c/c89
https://liushiming.cn/article/vim-force-save-explained.html

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值