I'm trying to set up a fairly traditional environment for C programming in Vim just to get a taste of it coming from a graphical IDE background. Currently my .vimrc file looks like this:
syntax on
:filetype indent on
This provides good syntax highlighting and some indentation. However, the auto indent indents 8 spaces in. Is this standard among vim users? Is there a reason for this? It feels a little... spacious ... coming from environments where 4 spaces is the norm. I'm sure there's a way to change it, but should I?
I'd also like to have something to complete my brackets and parentheses like Eclipse does. I've heard of the AutoClose plugin. Is this the best route, or is there something a little more lightweight?
Any other essentials?
You should drop the :
it's not needed in your ~/.vimrc
, the correct line should be:
filetype plugin indent on
The plugin
part loads additional filetype-specific plugins that often provide useful commands/mappings/settings.
8 characters is actually the universal and historical default width for a <Tab>
. If you want it to be displayed shorter (which I can understand), you'll have to add these lines to your ~/.vimrc
:
set softtabstop=4 " see :h 'softtabstop'
set shiftwidth=4 " see :h 'shiftwidth'
There's a comprehensive explanation in :h 'tabstop'
.
Note that it doesn't change anything to the actual content of the file.
I use DelimitMate but there are many "auto closing" plugins. If you are satisfied with AutoClose and need that feature, there's no reason to change, I guess. But you should know that a naive but working implementation of that concept can be achieved with a handful of custom mappings like:
inoremap ( ()<Left>
This is the minimal ~/.vimrc
that I put on every server I work on. It is small but it sets a number of super useful options like hidden
or incsearch
.
set nocompatible
filetype plugin indent on
syntax on
silent! runtime macros/matchit.vim
set autochdir
set backspace=indent,eol,start
set foldenable
set hidden
set incsearch
set laststatus=2
set ruler
set switchbuf=useopen,usetab
set tags=./tags,tags;/
set wildmenu
nnoremap gb :buffers<CR>:sb<Space>
To know what each option does, just do :h 'option
(with the single quote) and add it to your ~/.vimrc
only if you understand what it does and you actually need it.
Generally, learning how to use the documentation is key.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With