Wednesday, May 22, 2013

How to get Allman style while typing and templated C++ code in Vim 7.3

Hi guys, my first post here and this is my 3rd day with vim.

I'm under Ubuntu 13.04 64 bit so I have vim 7.3 installed, I currently use clang_complete to get some C++ related features like autocompletition but I'm stuck with code formatting rules and I can't find a way to speed up some particular activity when creating new classes or new code that can be easily templated because it follows some clear patterns.

I'm used to astyle ( http://astyle.sourceforge.net/ ) and I like the Allman style and I would love the ability to get some smart formatting while typing C++ code, for example I found really inconsistent what happens with the brackets, if I have

{}

And my cursor is right in the middle, when I hit enter I would like to have this situation

{
_
}

where that _ underscore is the actual cursor, and the source code it's formatted according to the Allman style. This is just an example, because I'm wondering how to get Allman style for the whole document while typing in real time.

The second part it's about how under Vim it's possible to create some pre-packed files with some boring code and being able to just replace some key parts with some script, for example when creating a new C++ class I need the usual set of boring methods and ctors and the only thing that changes most of the time it's just the name of the class, so I would like to spend less time coding this repetitive portions of the code and kinda template and script the code generation for my source files.

My actual .vimrc is this one
----------------------------
" gnome-shell workaround http://askubuntu.com/questions/67/how-do-i-enable-full-color-support-in-terminal
if $COLORTERM == 'gnome-terminal'
set t_Co=256
endif

syntax on
set number " show numbers on the left side
set scrolloff=5 " keep at least 5 lines above/below
set sidescrolloff=5 " keep at least 5 lines left/right
set autoindent smartindent " auto/smart indent

" tab & space related settings
set autoindent
set cindent
set tabstop=2
set shiftwidth=2
set expandtab
----------------------------

As you can see I already have some autoformatting rules going on but I'm not really happy with them.

Thanks.

--
--
You received this message from the "vim_use" maillist.
Do not top-post! Type your reply below the text you are replying to.
For more information, visit http://www.vim.org/maillist.php

---
You received this message because you are subscribed to the Google Groups "vim_use" group.
To unsubscribe from this group and stop receiving emails from it, send an email to vim_use+unsubscribe@googlegroups.com.
For more options, visit https://groups.google.com/groups/opt_out.

No comments: