码迷,mamicode.com
首页 > 其他好文 > 详细

Ubuntu下VIM使用指南

时间:2014-07-21 09:34:47      阅读:346      评论:0      收藏:0      [点我收藏+]

标签:des   style   color   使用   strong   os   

基本命令:

EscVIM中的万能功能键之一,基本上任何时候按这个键,都可以返回VIM的普通状态。

i:在普通状态下按i可以进入插入编辑状态,这个时候按方向键移动光标,在想要输入的地方输入字符,用Del键删除字符,最后用Esc退出到普通状态。

yyyny):在普通状态下,把光标用方向键移动到想要复制的某行文字上,按两下y,就是复制这一行。如果是想复制这行一下n行,就用yny方式。如复制5行,就是y5y

p:复制后,移动光标到要粘贴的地方,按p既可。

d:和上面相对,按d就是删除当前行。

x:在普通模式下,按x就是删除光标当前位置的字符,汉字就是整个汉字。

:wq!:在普通模式下输入:”就进入命令状态,在这个状态下,q代表退出,w代表保存,!代表强制。比如放弃修改,就是:q!,强制保存退出就是:wq!

 

进入vi 的命令
vi filename :
打开或新建文件,并将光标置于第一行首
vi +n filename
 :打开文件,并将光标置于第n行首
vi + filename
 :打开文件,并将光标置于最后一行首
vi +/pattern filename
:打开文件,并将光标置于第一个与pattern匹配的串处
vi -r filename
 :在上次正用vi编辑时发生系统崩溃,恢复filename
vi filename....filename
 :打开多个文件,依次进行编辑


移动光标类命令
h
 :光标左移一个字符
l
 :光标右移一个字符
space
:光标右移一个字符
Backspace
:光标左移一个字符
k
Ctrl+p:光标上移一行
j
Ctrl+n :光标下移一行
Enter
 :光标下移一行
w
W :光标右移一个字至字首
b
B :光标左移一个字至字首
e
E :光标右移一个字至字尾
)
 :光标移至句尾
(
 :光标移至句首
}
:光标移至段落开头
{
:光标移至段落结尾
nG
:光标移至第n行首
n+
:光标下移n
n-
:光标上移n
n$
:光标移至第n行尾
H
 :光标移至屏幕顶行
M
 :光标移至屏幕中间行
L
 :光标移至屏幕最后行
0
:(注意是数字零)光标移至当前行首
$
:光标移至当前行尾

屏幕翻滚类命令
Ctrl+u
:向文件首翻半屏
Ctrl+d
:向文件尾翻半屏
Ctrl+f
:向文件尾翻一屏
Ctrl
b;向文件首翻一屏
nz
:将第n行滚至屏幕顶部,不指定n时将当前行滚至屏幕顶部。

插入文本类命令
i
 :在光标前
I
 :在当前行首
a
:光标后
A
:在当前行尾
o
:在当前行之下新开一行
O
:在当前行之上新开一行
r
:替换当前字符
R
:替换当前字符及其后的字符,直至按ESC
s
:从当前光标位置处开始,以输入的文本替代指定数目的字符
S
:删除指定数目的行,并以所输入文本代替之
ncw
nCW:修改指定数目的字
nCC
:修改指定数目的行

删除命令
ndw
ndW:删除光标处开始及其后的n-1个字
do
:删至行首
d$
:删至行尾
ndd
:删除当前行及其后n-1
x
X:删除一个字符,x删除光标后的,而X删除光标前的
Ctrl+u
:删除输入方式下所输入的文本

搜索及替换命令
/pattern
:从光标开始处向文件尾搜索pattern
?pattern
:从光标开始处向文件首搜索pattern
n
:在同一方向重复上一次搜索命令
N
:在反方向上重复上一次搜索命令
s/p1/p2/g:将当前行中所有p1均用p2替代
n1,n2s/p1/p2/g:将第n1n2行中所有p1均用p2替代
g/p1/s//p2/g:将文件中所有p1均用p2替换

选项设置
all
:列出所有选项设置情况
term
:设置终端类型
ignorance
:在搜索中忽略大小写
list
:显示制表位(Ctrl+I)和行尾标志($)
number
:显示行号
report
:显示由面向行的命令修改过的数目
terse
:显示简短的警告信息
warn
:在转到别的文件时若没保存当前文件则显示NO write信息
nomagic
:允许在搜索模式中,使用前面不带\”的特殊字符
nowrapscan
:禁止vi在搜索到达文件两端时,又从另一端开始
mesg
:允许vi显示其他用户用write写到自己终端上的信息

最后行方式命令
n1,n2 co n3:将n1行到n2行之间的内容拷贝到第n3行下
n1,n2 m n3:将n1行到n2行之间的内容移至到第n3行下
n1,n2 d :将n1行到n2行之间的内容删除
w :保存当前文件
e filename:打开文件filename进行编辑
x:保存当前文件并退出
q:退出vi
q!:不保存文件并退出vi
!command:执行shell命令command
n1,n2 w!command:将文件中n1行至n2行的内容作为command的输入并执行之,若不指定n1n2,则表示将整个文件内容作为command的输
r!command:将命令command的输出结果放到当前行

寄存器操作
"?nyy
:将当前行及其下n行的内容保存到寄存器?中,其中?为一个字母,n为一个数字
"?nyw
:将当前行及其下n个字保存到寄存器?中,其中?为一个字母,n为一个数字
"?nyl
:将当前行及其下n个字符保存到寄存器?中,其中?为一个字母,n为一个数字
"?p
:取出寄存器?中的内容并将其放到光标位置处。这里?可以是一个字母,也可以是一个数字
ndd
:将当前行及其下共n行文本删除,并将所删内容放到1号删除寄存器中。

 

vi编辑器里面命令模式选项
:set all
 查看所有set选项
:set
 显示当前set设置
:filetype on
 通过$VIMRUNTIME/filetype.vim.打开文件类型检测

 

*******************************************华丽的分割线****************************************************

VIM的安装:
sudo apt-get install vim

文件位置:
/etc/vim/vimrc

VIM配置:
"-----------------------
"
基本设置
"-----------------------
"
不使用与vi兼容的键盘模式
set nocompatible
"
检测文件的类型
filetype on
"
记录历史的行数
set history=1000
"
修改一个文件后,自动进行备份,备份的文件名为原文件名加~“后缀
"if has("vms")
"set nobackup
"else
"set backup
"endif
"
 可以在buffer的任何地方使用鼠标
set mouse=a
set selection=exclusive
set selectmode=mouse,key


"-----------------------
"
界面设置
"----------------------
"
显示行号
set nu!
"
高亮显示当前行
set cursorline
"
背景使用黑色
set background=dark
"
去除vimGUI版本中的toolbar
set guioptions-=T
"
在编辑过程中,在右下角显示光标位置
set ruler
"always show the status line
set laststatus=2


"---------------------
"
格式设置
"---------------------
"
自动换行
set wrap
"
整词换行
set linebreak
"
自动对齐
set autoindent
"
智能对齐
set smartindent
"
设置自动缩进
set ai!
"
设置tab键为4个空格
set tabstop=4
"
不要用空格代替制表符
set noexpandtab
"
设置行间交错为4个空格
set shiftwidth=4
"
使退格键可用
set backspace=2
"
允许backspace和光标键跨越行边界
set whichwrap+=<,>,h,l


"---------------------
"
编程设置
"---------------------
"
语法高亮度显示
syntax on
"
设置匹配模式,类似当输入一个左括号时会匹配相应的那个右括号
set showmatch

 

"--------------------
"
搜索相关设置
"-------------------
"
默认情况下,搜索结果是高亮度显示的,该设置关闭高亮显示
"set nohlsearch
"
随输入增量搜索
set incsearch


一般设置如下:
" 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.
"syntax on

" 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("‘\"") > 0 && line("‘\"") <= line("$")
" \| exe "normal g‘\"" | endif
"endif

" Uncomment the following to have Vim load indentation rules according to the
" detected filetype. Per default Debian Vim only load filetype specific
" plugins.
"if has("autocmd")
" filetype 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) in terminals

" Source a global configuration file if available
" XXX Deprecated, please move your changes here in /etc/vim/vimrc
if filereadable("/etc/vim/vimrc.local")
source /etc/vim/vimrc.local
endif

个人添加的配置:
"
有两个的只能取其一
set ai/noai "
 自动缩进,新行与前面的行保持致的自动空格/不自动空格(缺省)
set aw/noaw "
 自动写,转入shell或使用:n编辑其他文件时,当前的缓冲区被写入/不写
set flash/noflash "
 在出错处闪烁但不呜叫(缺省)/使用呜叫而不闪烁
set ic/noic "
 在查询及模式匹配时忽赂大小写/不忽略大小写(缺省)
set nu/nonu
set number/nonumber "
 屏幕左边显示行号/不显示行号(缺省)
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 "
 自动语法高亮

Ubuntu下VIM使用指南,布布扣,bubuko.com

Ubuntu下VIM使用指南

标签:des   style   color   使用   strong   os   

原文地址:http://www.cnblogs.com/lukcyjane/p/3856210.html

(0)
(0)
   
举报
评论 一句话评论(0
登录后才能评论!
© 2014 mamicode.com 版权所有  联系我们:gaon5@hotmail.com
迷上了代码!