linux vi vim 配置 用于写c语言
先说一下vi和vim的区别:
它们都是多模式编辑器,不同的是vim 是vi的升级版本,它不仅兼容vi的所有指令,而且还有一些新的特性在里面。
vim的这些优势主要体现在以下几个方面:
1、多级撤消
我们知道在vi里,按 u只能撤消上次命令,而在vim里可以无限制的撤消。
2、易用性
vi只能运行于unix中,而vim不仅可以运行于unix,windows ,mac等多操作平台。
3、语法加亮
vim可以用不同的颜色来加亮你的代码。
4、可视化操作
就是说vim不仅可以在终端运行,也可以运行于x window、 mac os、 windows。
5、对vi的完全兼容
某些情况下,你可以把vim当成vi来使用。
我前段时间也下载使用了vim编辑器,我用的xp系统,之前在linux SUSE下也用过vi,个人感觉是vim相对于vi来说,扩展性更强了,以前使用vi时ctrl+s和ctrl+z之类的是不能用的(应该没有记错),但是vim就可以的。
然后,介绍一下用vi 写c程序的话,主要的一些配置:
一种方法是在vi 的底行模式下,输入一些配置命令,如 :set all 显示所有配置选项。
:set hlsearch
:set backspace=2
:set smartindent
:sysntax on
然后按 Esc,输入:wq退出
下面逐一解释一下:
:set hlsearch 作用:将搜索字符串反白
:set backspace=2 作用:可以删除任意值(经常输入错误,所以要删掉)
:set smartindent 作用:自动缩进(这个是最重要的,要不麻烦,程序些出来不整齐)
:sysntax on 作用:根据语法显示不同的颜色(检查语法,要是有颜色不对的,肯定有些错的地方)
还有就是你想一次搞定,以后不用再临时配置的话,你就修改vim的配置文件。
配置vim的方法是在用户主目录下建立个.vimrc文件,我一般使用root帐户,所以就在/root/下建立一个.vimrc文件:vi /root/.vimrc。
一下是一些关于vim常用的配置说明:
"语法高亮
syntax on
"显示行号
set nu
"修改默认注释颜色
hi Comment ctermfg=DarkCyan
"允许退格键删除
set backspace=2
"启用鼠标
set mouse=a
set selection=exclusive
set selectmode=mouse,key
"侦测文件类型
filetype on
"载入文件类型插件
filetype plugin on
"为特定文件类型载入相关缩进文件
filetype indent on
"设置编码自动识别, 中文引号显示
let &termencoding=&encoding
set fileencodings=utf-8,gbk,ucs-bom,cp936
set encoding=euc-cn
set ambiwidth=double
"设置高亮搜索
set hlsearch
"在搜索时,输入的词句的逐字符高亮
set incsearch
"按C语言格式缩进
set cindent
"设置Tab长度为4格
set tabstop=4
"设置自动缩进长度为4格
set shiftwidth=4
"继承前一行的缩进方式,特别适用于多行注释
set autoindent
"显示括号匹配
set showmatch
"括号匹配显示时间为1(单位是十分之一秒)
set matchtime=1
"增强模式中的命令行自动完成操作
set wildmenu
"不要生成swap文件,当buffer被丢弃的时候隐藏它
setlocal noswapfile
set bufhidden=hide
=====================================================================
syntax on
set nu
set fileencodings=utf-8,gbk
set tabstop=4
set shiftwidth=4
set expandtab
好了,就说到这吧。
下面把.vimrc 的一个模板放在这:
" An example for a vimrc file.
"
" Maintainer: Bram Moolenaar <>
" Last change: 2002 May 28
"
" To use it, copy it to
" for Unix and OS/2: ~/.vimrc
" for Amiga: s:.vimrc
" for MS-DOS and Win32: $VIM\_vimrc
" for OpenVMS: sys$login:.vimrc
" When started as "evim", evim.vim will already have done these settings.
if v:progname =~? "evim"
finish
endif
" Use Vim settings, rather then Vi settings (much better!).
" This must be first, because it changes other options as a side effect.
set nocompatible
" allow backspacing over everything in insert mode
set backspace=indent,eol,start
set autoindent " always set autoindenting on
if has("vms")
set nobackup " do not keep a backup file, use versions instead
else
set backup " keep a backup file
endif
set history=50 " keep 50 lines of command line history
set ruler " show the cursor position all the time
set showcmd " display incomplete commands
set incsearch " do incremental searching
set nu
set smartindent
set mouse=a
set selection=exclusive
set selectmode=mouse,key
set nobackup
set nowritebackup
let &termencoding=&encoding
set fileencodings=utf-8,gbk,ucs-bom,cp936
set encoding=euc-cn
"set ambiwidth=double
set shiftwidth=4
set cindent
" For Win32 GUI: remove 't' flag from 'guioptions': no tearoff menu entries
" let &guioptions = substitute(&guioptions, "t", "", "g")
" Don't use Ex mode, use Q for formatting
map Q gq
" This is an alternative that also works in block mode, but the deleted
" text is lost and it only works for putting the current register.
"vnoremap p "_dp
" Switch syntax highlighting on, when the terminal has colors
" Also switch on highlighting the last used search pattern.
if &t_Co > 2 || has("gui_running")
syntax on
set hlsearch
endif
" Only do this part when compiled with support for autocommands.
if has("autocmd")
" Enable file type detection.
" Use the default filetype settings, so that mail gets 'tw' set to 72,
" 'cindent' is on in C files, etc.
" Also load indent files, to automatically do language-dependent indenting.
filetype plugin indent on
" For all text files set 'textwidth' to 78 characters.
autocmd FileType text setlocal textwidth=78
" When editing a file, always jump to the last known cursor position.
" Don't do it when the position is invalid or when inside an event handler
" (happens when dropping a file on gvim).
autocmd BufReadPost *
\ if line("'\"") > 0 && line("'\"") <= line("$") |
\ exe "normal g`\"" |
\ endif
endif " has("autocmd")
更多推荐
所有评论(0)