6.19学咋
来源:互联网 发布:药品网络销售 编辑:程序博客网 时间:2024/06/11 05:26
打开终端快捷键 contrl alt T
sudo apt-get install vim
在某路径下打开一个终端,或打开终端后进入你想存放源文件的路径,然后
[root@localhost ~]# vim hello.cpp
- vi编辑器入门
- vi是linux下最最最常用的编辑工具之一~下面对他进行简单的介绍
- vi启动是:vi filename
- 该命名打开或者创建一个文件。首先进入vi后,是cmd模式(命令模式)。在该模式下可以移动光标,复制,移动,删除等。如:
- 移动光标:up/down/left/right或者h/j/k/l字母键
- 删除当前光标所在行:dd
- 删除当前光标后n行:n+dd
- 向下翻页:ctl+f
- 向上翻页:ctl+b
- 在cmd模式下使用":"可以进入到last命令输入,此模式下几个常用命令:
- w:保存
- q:退出
- wq:保存并退出
- w!:强制保存
- q!:强制退出
- 在cmd下可以用下面几个命令进入编辑模式:
- i:在当前光标插入
- a:在当前光标后插入
- o:在当前光标下创建新的一行并插入
- 编辑模式下,只能输入,不能使用光标移动,使用esc可以切换到cmd模式
- 4 linux下c/c++编程
- 上面介绍了vi的基本使用,下面我将建立我在linux下的第一个c++程序。
- 使用vi test.cpp建立一个cpp文件,进入vi进行编辑。编辑完毕之后,使用g++ test.cpp -o test编译cpp文件生成test输出文件,如果直接使用g++ test.cpp将直接生成命为a.out的输出文件。接着使用./test可以运行test。这里需要注意的是,linux自带了c和c++编译器,默认安装了c编译器,可以使用gcc编译c文件,但是c++的编译器没有默认安装,可以使用sudo apt-get install g++来安装。
设置vim语法高亮显示和自动缩进
二、接下来设置vim的配置文件
" All system-wide defaults are set in $VIMRUNTIME/debian.vim (usually just
" /usr/share/vim/vimcurrent/debian.vim) and sourced by the call to :runtime
" you can find below. If you wish to change any of those settings, you should
" do it in this file (/etc/vim/vimrc), since debian.vim will be overwritten
" everytime an upgrade of the vim packages is performed. It is recommended to
" make changes after sourcing debian.vim since it alters the value of the
" 'compatible' option.
" This line should not be removed as it ensures that various options are
" properly set to work with the Vim-related packages available in Debian.
runtime! debian.vim
" Uncomment the next line to make Vim more Vi-compatible
" NOTE: debian.vim sets 'nocompatible'. Setting 'compatible' changes numerous
" options, so any other options should be set AFTER setting 'compatible'.
"set compatible
" Vim5 and later versions support syntax highlighting. Uncommenting the next
" line enables syntax highlighting by default.
if has("syntax")
syntax on
endif
" If using a dark background within the editing area and syntax highlighting
" turn on this option as well
"set background=dark
" Uncomment the following to have Vim jump to the last position when
" reopening a file
"if has("autocmd")
" au BufReadPost * if line("'\"") > 1 && line("'\"") <= line("$") | exe "normal! g'\"" | endif
"endif
" Uncomment the following to have Vim load indentation rules and plugins
" according to the detected filetype.
"if has("autocmd")
" filetype plugin indent on
"endif
" The following are commented out as they cause vim to behave a lot
" differently from regular Vi. They are highly recommended though.
"set showcmd " Show (partial) command in status line.
"set showmatch " Show matching brackets.
"set ignorecase " Do case insensitive matching
"set smartcase " Do smart case matching
"set incsearch " Incremental search
"set autowrite " Automatically save before commands like :next and :make
"set hidden " Hide buffers when they are abandoned
"set mouse=a " Enable mouse usage (all modes)
"set tabstop=4 " 设置(软)制表符宽度为4:
"set softtabstop=4 "
"set shiftwidth=4 "设置缩进的空格数为4
"set autoindent "设置自动缩进:即每行的缩进值与上一行相等;使用 noautoindent 取消设置:
"set cindent "设置使用 C/C++ 语言的自动缩进方式
"set cinoptions={0,1s,t0,n-2,p2s,(03s,=.5s,>1s,=1s,:1s ) } "设置C/C++语言的具体缩进方式(以我的windows风格为例)
set nu "
set wildmenu "增强模式中的命令行自动完成操作
set foldmethod=manual "设定折叠方式为手动
set cin "实现C程序的缩进
set sta
"插入<tab>时使用’shiftwidth’
set backspace=2
"指明在插入模式下可以使用<BS>删除光标前面的字符
syntax enable
"设置高亮关键字显示
set nocompatible
"去掉讨厌的有关vi一致性模式,避免以前版本的一些bug和局限
set number
"显示行号
filetype on
"检测文件的类型
set history=1000
"记录历史的行数
set background=dark
"背景使用黑色
set autoindent
set smartindent
"上面两行在进行编写代码时,在格式对起上很有用;
"第一行,vim使用自动对起,也就是把当前行的对起格式应用到下一行;
"第二行,依据上面的对起格式,智能的选择对起方式,对于类似C语言编写上很有用
"第一行设置tab键为4个空格,第二行设置当行之间交错时使用4个空格
set tabstop=4
set shiftwidth=4
set showmatch
"设置匹配模式,类似当输入一个左括号时会匹配相应的那个右括号
set ruler
"在编辑过程中,在右下角显示光标位置的状态行
set incsearch
"查询时非常方便,如要查找book单词,当输入到/b时,会自动找到第一
"个b开头的单词,当输入到/bo时,会自动找到第一个bo开头的单词,依
"次类推,进行查找时,使用此设置会快速找到答案,当你找要匹配的单词
"时,别忘记回车。
set enc=utf-8
"设置编码为中文
set winaltkeys=no
"Alt组合键不映射到菜单上
set laststatus=2
"总是出现状态栏
set statusline=%<%f\ %h%m%r%=%-14.(%l,%c%V%)\ %P>
"设置状态栏
set hidden
"设置隐藏已修改buffer
autocmd FileType python setlocal et sta sw=4 sts=4
" Source a global configuration file if available
if filereadable("/etc/vim/vimrc.local")
source /etc/vim/vimrc.local
endif
#include<iostream>
using namespace std;
int main()
{
cout<<"hello world!"<<"\n";
}
>>>>
然后按Esc,再输入“:w”保存文件,再“:q”退出。然后编译:
[root@localhost ~]# g++ hello.cpp)
这个时候执行查看指令“ls”可以看到路径下多了个名为“a.out”的文件,
[root@localhost ~]# ./a.out
就可以看到执行结果了。以上是直接在终端进行的方法,如果想通过终端打开VIM程序来编辑,那把上面的vim命令换成gvim就行了,这样也是蛮方便的,而且功能也更完善些。
0 0