分页: 1 / 1

vim代码自动格式化

发表于 : 2010-04-22 22:46
vimindel
我在shell中使用vim编辑C代码,可是每次按回车后光标都会到下一行的最开头,而不是自动格式化到正确的位置。请问如何使vim打开格式化代码的功能呢?

Re: vim代码自动格式化

发表于 : 2010-04-22 23:15
adagio
不懂你的“自动格式化”啥意思

Re: vim代码自动格式化

发表于 : 2010-04-22 23:56
vimindel
如我输入if(){,按回车后我希望光标已经缩进好而不是停留在开头我还得手工TAB几下才能缩进

Re: vim代码自动格式化

发表于 : 2010-04-22 23:56
佚之狐L
默认是选中后=号键

Re: vim代码自动格式化

发表于 : 2010-04-22 23:58
adam8157

代码: 全选

"""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""
" Indent
"""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""

" Auto indent
set autoindent

" Smart indet
set smartindent

" C-style indeting
set cindent

" Set tabstop width
set tabstop=4
set shiftwidth=4
set softtabstop=4

" Enable filetype plugin
filetype on
filetype plugin on
filetype indent on

" Set <BS> delete fake tabs
set smarttab

" Insert spaces instead of real tabs
set expandtab

Re: vim代码自动格式化

发表于 : 2010-04-23 12:08
zerger
vimindel 写了:我在shell中使用vim编辑C代码,可是每次按回车后光标都会到下一行的最开头,而不是自动格式化到正确的位置。请问如何使vim打开格式化代码的功能呢?
196 """"""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""
197 " 6. Autocommands
198 """"""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""
199 " do c-style indenting, cinoptions changes:
200 ":N Place case labels N characters from the indent of the switch(). (default 'shiftwidth').
201 "gN Place C++ scope declarations N characters from the indent of the block they are in. (default 'shiftwidth').
202 "tN Indent a function return type declaration N characters from the margin. (default 'shiftwidth').
203 "(N When in unclosed parentheses, indent N characters from the line with the unclosed parentheses. (default 'shiftwidth' * 2).
204 autocmd FileType c,cpp :set cindent cinoptions=:0,g0,t0,(0 textwidth=79 formatoptions=tcroqmB

更多设置请参考我的博客: "Vim学习笔记11: 晒晒我的
.vimrc"(http://guoyoooping.blog.163.com/blog/st ... 317316862/)

Re: vim代码自动格式化

发表于 : 2010-04-25 19:50
混混人见人爱
vi ~/.vimrc

加入
set cindent

Re: vim代码自动格式化

发表于 : 2010-08-15 18:41
hpccn
自动格式化代码命令

gg=G