vim代码自动格式化
-
- 帖子: 2
- 注册时间: 2010-04-22 22:43
vim代码自动格式化
我在shell中使用vim编辑C代码,可是每次按回车后光标都会到下一行的最开头,而不是自动格式化到正确的位置。请问如何使vim打开格式化代码的功能呢?
- adagio
- 论坛版主
- 帖子: 22110
- 注册时间: 2008-02-17 23:47
- 来自: 美丽富饶的那啥星球
Re: vim代码自动格式化
不懂你的“自动格式化”啥意思
明天就换大三八!
——8核CPU、8G内存、8T硬盘……
8卡交火,80寸大屏放8个……
IPv8的光纤要8条……
---------------------------------------------------------------------------------
★ [图片版]新手当自强(续)FAQ
★ [新手进阶]挂载、fstab、调整linux分区
★ [图片版]E17桌面环境配置手把手
——8核CPU、8G内存、8T硬盘……
8卡交火,80寸大屏放8个……
IPv8的光纤要8条……
---------------------------------------------------------------------------------
★ [图片版]新手当自强(续)FAQ
★ [新手进阶]挂载、fstab、调整linux分区
★ [图片版]E17桌面环境配置手把手
-
- 帖子: 2
- 注册时间: 2010-04-22 22:43
Re: vim代码自动格式化
如我输入if(){,按回车后我希望光标已经缩进好而不是停留在开头我还得手工TAB几下才能缩进
- 佚之狐L
- 帖子: 840
- 注册时间: 2008-01-28 13:02
- adam8157
- 帖子: 2794
- 注册时间: 2009-03-05 16:31
- 联系:
Re: vim代码自动格式化
代码: 全选
"""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""
" 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
-
- 帖子: 23
- 注册时间: 2010-01-05 22:47
Re: vim代码自动格式化
196 """"""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""vimindel 写了:我在shell中使用vim编辑C代码,可是每次按回车后光标都会到下一行的最开头,而不是自动格式化到正确的位置。请问如何使vim打开格式化代码的功能呢?
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/)
-
- 帖子: 55
- 注册时间: 2009-11-24 13:05
Re: vim代码自动格式化
vi ~/.vimrc
加入
set cindent
加入
set cindent
-
- 帖子: 5
- 注册时间: 2010-08-05 15:24
Re: vim代码自动格式化
自动格式化代码命令
gg=G
gg=G