LinuxSir.cn,穿越时空的Linuxsir!

 找回密码
 注册
搜索
热搜: shell linux mysql
查看: 5009|回复: 15

如何设置vi才能实现缩进两个空格?

[复制链接]
发表于 2004-8-29 15:31:07 | 显示全部楼层 |阅读模式
现在我在用vi写java的代码
我的编程风格就是缩进两个空格,比如:
public static void main(String[] args){
  int a;
  String str;
  if (condition){
    code to hanle;
  }
}

每次转行后总要敲很多空格,很烦呀!

请问各位兄弟如何解决?  谢谢!
发表于 2004-8-29 22:51:51 | 显示全部楼层
我用 vim 的

配置一下 vim ,使她自动编排格式 ( C自动缩进)
我的 /usr/share/vim/vimrc



  1. " An example for a vimrc file.
  2. "
  3. " Maintainer:   Bram Moolenaar <Bram@vim.org>
  4. " Last change:  2002 Sep 19
  5. "
  6. " To use it, copy it to
  7. "     for Unix and OS/2:  ~/.vimrc
  8. "             for Amiga:  s:.vimrc
  9. "  for MS-DOS and Win32:  $VIM\_vimrc
  10. "           for OpenVMS:  sys$login:.vimrc

  11. " When started as "evim", evim.vim will already have done these settings.
  12. if v:progname =~? "evim"
  13.   finish
  14. endif

  15. " Use Vim settings, rather then Vi settings (much better!).
  16. " This must be first, because it changes other options as a side effect.
  17. set nocompatible
  18. " allow backspacing over everything in insert mode
  19. set backspace=indent,eol,start

  20. if has("vms")
  21.   set nobackup          " do not keep a backup file, use versions instead
  22. else
  23.   set backup            " keep a backup file
  24. endif
  25. set history=50          " keep 50 lines of command line history
  26. set ruler               " show the cursor position all the time
  27. set showcmd             " display incomplete commands
  28. set incsearch           " do incremental searching

  29. " For Win32 GUI: remove 't' flag from 'guioptions': no tearoff menu entries
  30. " let &guioptions = substitute(&guioptions, "t", "", "g")

  31. " Don't use Ex mode, use Q for formatting
  32. map Q gq

  33. " This is an alternative that also works in block mode, but the deleted
  34. " text is lost and it only works for putting the current register.
  35. "vnoremap p "_dp

  36. " Switch syntax highlighting on, when the terminal has colors
  37. " Also switch on highlighting the last used search pattern.
  38. if &t_Co > 2 || has("gui_running")
  39.   syntax on
  40.   set hlsearch
  41. endif

  42. " Only do this part when compiled with support for autocommands.
  43. if has("autocmd")

  44.   " Enable file type detection.
  45.   " Use the default filetype settings, so that mail gets 'tw' set to 72,
  46.   " 'cindent' is on in C files, etc.
  47.   " Also load indent files, to automatically do language-dependent indenting.
  48.   filetype plugin indent on

  49.   " Put these in an autocmd group, so that we can delete them easily.
  50.   augroup vimrcEx
  51.   au!

  52.   " For all text files set 'textwidth' to 78 characters.
  53.   autocmd FileType text setlocal textwidth=78

  54.   " When editing a file, always jump to the last known cursor position.
  55.   " Don't do it when the position is invalid or when inside an event handler
  56.   " (happens when dropping a file on gvim).
  57.   autocmd BufReadPost *
  58.     \ if line("'"") > 0 && line("'"") <= line("$") |
  59.     \   exe "normal g`"" |
  60.     \ endif

  61.   augroup END

  62. else

  63.   set autoindent                " always set autoindenting on

  64. endif " has("autocmd")

复制代码



在 X 下还是用 gvim 好

把高亮显示设为 java ,狠好用的



不过我喜欢的风格是缩进一个 Tab
发表于 2004-8-30 09:15:24 | 显示全部楼层
VI跟VIM有什么区别?我只知道VIM是VI的升级版。对吗?

好像看到大家都不喜欢用VIM的。为什么啊......
发表于 2004-8-30 09:23:19 | 显示全部楼层
set tabstop=2

可以设置Tab的距离
发表于 2004-8-30 11:29:25 | 显示全部楼层
哪里是,大家都喜欢用 vim 或 emacs 的

很少用纯粹 vi 的



vim 支持自动缩进,语法高亮,多窗口,多缓冲区等等许多增强特性

用来写程序绝对比 vi 方便


在好些发行版里 命令 vi 实际上都是 vim
发表于 2004-8-30 13:14:04 | 显示全部楼层
set tabstop=2
set shiftwidth=2
 楼主| 发表于 2004-8-31 19:07:46 | 显示全部楼层
请问tabstop和shiftwidth是什么意思?
发表于 2004-8-31 19:09:24 | 显示全部楼层
tabstop :一个 TAB 相当几个空格

shiftwidth:缩进宽度
发表于 2004-9-1 16:15:34 | 显示全部楼层
在/root/.vimrc里添加set tabstop=2

然后保存就行了,马上生效的
 楼主| 发表于 2004-9-1 18:32:13 | 显示全部楼层
已经试过了,确实好使了,多谢兄弟们!
您需要登录后才可以回帖 登录 | 注册

本版积分规则

快速回复 返回顶部 返回列表