vim的安装和设置

Alex posted @ 2011年8月21日 21:35 in linux , 2951 阅读

wucy@wucy-laptop:~$ ls
app      examples.desktop  公共的  视频  文档  音乐
apue.2e  src.tar.gz        模板    图片  下载  桌面
wucy@wucy-laptop:~$ cd app
wucy@wucy-laptop:~/app$ ls
wucy@wucy-laptop:~/app$ vim ls.c
程序“vim”已包含在下列软件包中:
 * vim
 * vim-gnome
 * vim-tiny
 * vim-gtk
 * vim-nox
请尝试:sudo apt-get install <选定的软件包>
wucy@wucy-laptop:~/app$ sudo apt-get install vim
[sudo] password for wucy:
正在读取软件包列表... 完成
正在分析软件包的依赖关系树       
正在读取状态信息... 完成       
将会安装下列额外的软件包:
  vim-runtime
建议安装的软件包:
  ctags vim-doc vim-scripts
下列【新】软件包将被安装:
  vim vim-runtime
升级了 0 个软件包,新安装了 2 个软件包,要卸载 0 个软件包,有 433 个软件包未被升级。
需要下载 6,572kB 的软件包。
解压缩后会消耗掉 27.1MB 的额外空间。
您希望继续执行吗?[Y/n]y
获取:1 http://cn.archive.ubuntu.com/ubuntu/ lucid/main vim-runtime 2:7.2.330-1ubuntu3 [5,706kB]
获取:2 http://cn.archive.ubuntu.com/ubuntu/ lucid/main vim 2:7.2.330-1ubuntu3 [865kB]
下载 6,572kB,耗时 6分 18秒 (17.3kB/s)                                                    
选中了曾被取消选择的软件包 vim-runtime。
(正在读取数据库 ... 系统当前总共安装有 125450 个文件和目录。)
正在解压缩 vim-runtime (从 .../vim-runtime_2%3a7.2.330-1ubuntu3_all.deb) ...
正在添加 “diversion of /usr/share/vim/vim72/doc/help.txt to /usr/share/vim/vim72/doc/help.txt.vim-tiny by vim-runtime”
正在添加 “diversion of /usr/share/vim/vim72/doc/tags to /usr/share/vim/vim72/doc/tags.vim-tiny by vim-runtime”
选中了曾被取消选择的软件包 vim。
正在解压缩 vim (从 .../vim_2%3a7.2.330-1ubuntu3_i386.deb) ...
正在处理用于 man-db 的触发器...
正在设置 vim-runtime (2:7.2.330-1ubuntu3) ...
Processing /usr/share/vim/addons/doc

正在设置 vim (2:7.2.330-1ubuntu3) ...
update-alternatives: 使用 /usr/bin/vim.basic 来提供 /usr/bin/vim (vim),于 自动模式 中。
update-alternatives: 使用 /usr/bin/vim.basic 来提供 /usr/bin/vimdiff (vimdiff),于 自动模式 中。
update-alternatives: 使用 /usr/bin/vim.basic 来提供 /usr/bin/rvim (rvim),于 自动模式 中。
update-alternatives: 使用 /usr/bin/vim.basic 来提供 /usr/bin/rview (rview),于 自动模式 中。
update-alternatives: 使用 /usr/bin/vim.basic 来提供 /usr/bin/vi (vi),于 自动模式 中。
update-alternatives: 使用 /usr/bin/vim.basic 来提供 /usr/bin/view (view),于 自动模式 中。
update-alternatives: 使用 /usr/bin/vim.basic 来提供 /usr/bin/ex (ex),于 自动模式 中。

 

  1 #include <stdio.h>
  2 #include <stdlib.h>
  3 #include <dirent.h>
  4
  5 int main(int argc,char *argv[])
  6 {
  7     DIR *dp;
  8     struct dirent *dirp;
  9
 10     if(argc != 2)
 11         printf("err argument");
 12
 13     if((dp = opendir(argv[1])) == NULL)
 14         printf("can't open %s",argv[1]);
 15
 16     while((dirp = readdir(dp)) != NULL)
 17         printf("%s\n", dirp->d_name);
 18
 19     closedir(dp);
 20     exit(0);
 21 }
                                                                 

vim 自动对齐 在/etc/vimrc中设置

只要在 /etc/vimrc中加上这两句就行了
set autoindent
set smartindent
--------------------------------------------------------
pip我说过vim很好很强大滴
--------------------------------------------------------
 

====================================

详细:

在终端下使用vim进行编辑时,默认情况下,编辑的界面上是没有显示行号、语法高亮度显示、智能缩进

等功能的。为了更好的在vim下进行工作,需要手动设置一个配置文件:.vimrc。
在启动vim时,当前用户根目录下的.vimrc文件会被自动读取,该文件可以包含一些设置甚至脚本,

所以,一般情况下把.vimrc文件创建在当前用户的根目录下比较方便,即创建的命令为:
$vi ~/.vimrc
设置完后
$:x 或者 $wq
进行保存退出即可。
下面给出一个例子,其中列出了经常用到的设置,详细的设置信息请参照参考资料:
“双引号开始的行为注释行,下同
“去掉讨厌的有关vi一致性模式,避免以前版本的一些bug和局限
set nocompatible
“显示行号
set number
“检测文件的类型
filetype on
“记录历史的行数
set history=1000
“背景使用黑色
set background=dark
“语法高亮度显示
syntax on
“下面两行在进行编写代码时,在格式对起上很有用;
“第一行,vim使用自动对起,也就是把当前行的对起格式应用到下一行;
“第二行,依据上面的对起格式,智能的选择对起方式,对于类似C语言编
“写上很有用
set autoindent
set smartindent
“第一行设置tab键为4个空格,第二行设置当行之间交错时使用4个空格
set tabstop=4
set shiftwidth=4
“设置匹配模式,类似当输入一个左括号时会匹配相应的那个右括号
set showmatch
“去除vim的GUI版本中的toolbar
set guioptions=T
“当vim进行编辑时,如果命令错误,会发出一个响声,该设置去掉响声
set vb t_vb=
“在编辑过程中,在右下角显示光标位置的状态行
set ruler
“默认情况下,寻找匹配是高亮度显示的,该设置关闭高亮显示
set nohls
“查询时非常方便,如要查找book单词,当输入到/b时,会自动找到第一
“个b开头的单词,当输入到/bo时,会自动找到第一个bo开头的单词,依
“次类推,进行查找时,使用此设置会快速找到答案,当你找要匹配的单词
“时,别忘记回车
set incsearch
“修改一个文件后,自动进行备份,备份的文件名为原文件名加“~“后缀
if has(“vms”) //注意双引号要用半角的引号" "
set nobackup
else
set backup
endif
如果去除注释后,一个完整的.vimrc配置信息如下所示:
set nocompatible
set number
filetype on
set history=1000
set background=dark
syntax on
set autoindent
set smartindent
set tabstop=4
set shiftwidth=4
set showmatch
set guioptions-=T
set vb t_vb=
set ruler
set nohls
set incsearch
if has("vms")
set nobackup
else
set backup
endif

wucy@wucy-laptop:~/app$ vim ls.c
wucy@wucy-laptop:~/app$ gcc ls.c -o ls
wucy@wucy-laptop:~/app$ ls ./
ls  ls.c  ls.c~
wucy@wucy-laptop:~/app$

 


登录 *


loading captcha image...
(输入验证码)
or Ctrl+Enter