Chinaunix首页 | 论坛 | 博客
  • 博客访问: 1359763
  • 博文数量: 704
  • 博客积分: 10140
  • 博客等级: 上将
  • 技术积分: 6230
  • 用 户 组: 普通用户
  • 注册时间: 2010-07-15 20:41
文章分类

全部博文(704)

文章存档

2013年(1)

2012年(16)

2011年(536)

2010年(151)

分类: C/C++

2011-06-09 13:59:19

Vim

“设置行号
set nu
“设置逐字高亮搜索
set incsearch
“开启语法高亮
syntax enable
syntax on
“智能缩进
set autoindent
set softtabstop=4
set shiftwidth=4
set tabstop=4
set smarttab
“不在单词中断行
set lbr
set autochdir
“无备份文件
set nobackup
“关闭交换文件
set nowb
set noswapfile
set updatecount=0
set smartindent
“关闭高亮搜索
set nohlsearch
set history=400
“关闭兼容模式
set nocompatible
“设置主题色彩方案
colorscheme desert
“设置标尺
set ruler
“关闭遇到错误时声音提示
set magic
“显示匹配的行号
set showmatch
“在状态栏显示命令
set showcmd
“匹配时忽略大小写
set ignorecase
“控制台启用鼠标
“set mouse=a
“设置VIM内部的编码
set encoding=utf-8
“设置终端编码,就是VIM显示的编码
set termencoding=utf-8
“设置文件编码
set fileencoding=zh_CN.utf-8
“高亮当前行背景
“set cursorline

“设置标签的快捷键
map te :tabedit
map tc :tabclose
map tm :tabmove
map tl :bn
map tr :bp
set nocompatible

######################################################################

命令整理:

A: 在行尾插入
I: 在行首插入

######################################################################

:split file1 水平分割窗口file1
:vsplit file2 垂直分割窗口
:only 将其他窗口隐藏,只专注当前窗口
:new 打开新窗口(水平)
:vnew 打开新窗口(垂直)
:10split file 打开一个10行高度的file
:qall 退出所有窗口(未保存的不退出)
:wall 保存所有窗口
:wqall 保存并退出所有窗口

Ctrl+w 在窗口之间切换

######################################################################

vim -o file1 file2 file3 打开3个文件并水平排列窗口
vim -O file1 file2 file3 打开3个文件并垂直排列窗口

######################################################################

文件比较:
1. 在打开set backup情况下,编辑一个文件然后退出,就会得到一个名为filename~的备份文件:
#vimdiff filename filename~
可以对比增加了那几行(在SHELL里执行,而不是VIM

2. 在VIM中,打开一个文件,并执行对比:
e fil1
vertical diffsplit file1~
注意,vertical是垂直打开并对比,如果没有它就是水平方向

######################################################################

假如当前正在编辑thisfile:
#vi file1
:tabedit file2
:tabedit file3
就打开了多个页签,使用gt(Goto Tab)在多个页签之间切换

#vim -p file1 file2 file3 每个文件打开一个页签

######################################################################

解决GVIM在windows下编码的问题:

set encoding=utf-8
set fileencodings=utf-8,chinese,latin-1
if has(“win32″)
set fileencoding=chinese
else
set fileencoding=utf-8
endif
“解决菜单乱码
source $VIMRUNTIME/delmenu.vim
source $VIMRUNTIME/menu.vim
“解决consle输出乱码
language messages zh_CN.utf-8

######################################################################

更好的解决办法,可以让VIM和GVIM都不再乱码:

if has(“gui_running”)
set encoding=utf-8
set fileencodings=utf-8,chinese,latin-1

if has(“win32″)
set fileencoding=chinese
else
set fileencoding=utf-8
endif

let &termencoding=&encoding

“解决菜单乱码
source $VIMRUNTIME/delmenu.vim
source $VIMRUNTIME/menu.vim

“解决consle输出乱码
language messages zh_CN.utf-8
endif

阅读(648) | 评论(0) | 转发(0) |
给主人留下些什么吧!~~