I recently re-installed my Mint system and now vim does not auto indent when writing code and has poor color coding. Does any one know what I need to change and where the config file for that is? Thanks.

3 Years
Discussion Span
Last Post by JasonHippy

If memory serves, there should be an example vimrc file at the following location:
/usr/share/vim/vimXX (where XX is the version of vim installed)
The file will be called something like vimrc_example.vim. This contains a sane set of defaults for vim, including auto-indent and syntax highlighting. You can copy that to your home directory and rename it .vimrc.
`cp /usr/share/vim/vim74/vimrc_example.vim ~/.vimrc'

Optionally, you might want to edit it and make some changes to it.

I usually add a few custom settings/keybinds to the default .vimrc:

set incsearch           " do incremental searching
set number              " Show line numbers
set hls                 " Highlight search results

" Use enter/return to clear search-result highlights
nnoremap <CR> :noh<CR><CR>:<backspace>  

" Set up a keybind to switch from header to cpp
" F4 - Go to header/source
map <F4> :e %:p:s,.h$,.X123X,:s,.cpp$,.h,:s,.X123X$,.cpp,<CR>
" F3 - Open the file under the cursor 
" (good for opening headers in the include list
map <F3> gf<CR>

The comments explain what each setting does.


Are you sure you entered the entire line correctly?
Here it is again - pasted directly from my .vimrc file:
map <F4> :e %:p:s,.h$,.X123X,:s,.cpp$,.h,:s,.X123X$,.cpp,<CR>

Try copy/pasting the entire line into your .vimrc. It should all go into a single line.

As long as you have it exactly as it is above; it should work.... Works for me at least! :/

I've been using this mapping with vim on several different systems, for a number of years with no problems so far!

With a .cpp file open in vim, pressing F4 should cause vim to open its corresponding header. F4 again should take you back to the cpp file.

The F3 key-bind at line 13 (open file under cursor) is a bit twitchy sometimes. Unless the file path is absolute, it depends on the path to the file that you are trying to open and vims current working directory. But I've never had a problem with my F4 keybind.

This topic has been dead for over six months. Start a new discussion instead.
Have something to contribute to this discussion? Please be thoughtful, detailed and courteous, and be sure to adhere to our posting rules.