blob: 6d5eac4f74c1e1904b32d704a280cb7d8fa50592 [file] [log] [blame]
Bram Moolenaar071d4272004-06-13 20:20:40 +00001" An example for a vimrc file.
2"
3" Maintainer: Bram Moolenaar <Bram@vim.org>
Bram Moolenaar54f1b7a2016-04-05 22:07:04 +02004" Last change: 2016 Apr 05
Bram Moolenaar071d4272004-06-13 20:20:40 +00005"
6" To use it, copy it to
7" for Unix and OS/2: ~/.vimrc
8" for Amiga: s:.vimrc
9" for MS-DOS and Win32: $VIM\_vimrc
10" for OpenVMS: sys$login:.vimrc
11
12" When started as "evim", evim.vim will already have done these settings.
13if v:progname =~? "evim"
14 finish
15endif
16
Bram Moolenaar5c736222010-01-06 20:54:52 +010017" Use Vim settings, rather than Vi settings (much better!).
Bram Moolenaar071d4272004-06-13 20:20:40 +000018" This must be first, because it changes other options as a side effect.
19set nocompatible
20
21" allow backspacing over everything in insert mode
22set backspace=indent,eol,start
23
24if has("vms")
25 set nobackup " do not keep a backup file, use versions instead
26else
Bram Moolenaar76756882014-02-05 22:02:01 +010027 set backup " keep a backup file (restore to previous version)
28 set undofile " keep an undo file (undo changes after closing)
Bram Moolenaar071d4272004-06-13 20:20:40 +000029endif
30set history=50 " keep 50 lines of command line history
31set ruler " show the cursor position all the time
32set showcmd " display incomplete commands
33set incsearch " do incremental searching
34
35" For Win32 GUI: remove 't' flag from 'guioptions': no tearoff menu entries
36" let &guioptions = substitute(&guioptions, "t", "", "g")
37
38" Don't use Ex mode, use Q for formatting
39map Q gq
40
Bram Moolenaaraba88572008-06-25 20:13:35 +000041" CTRL-U in insert mode deletes a lot. Use CTRL-G u to first break undo,
42" so that you can undo CTRL-U after inserting a line break.
43inoremap <C-U> <C-G>u<C-U>
44
Bram Moolenaarc81e5e72007-05-05 18:24:42 +000045" In many terminal emulators the mouse works just fine, thus enable it.
Bram Moolenaarc236c162008-07-13 17:41:49 +000046if has('mouse')
47 set mouse=a
48endif
Bram Moolenaar071d4272004-06-13 20:20:40 +000049
Bram Moolenaar54f1b7a2016-04-05 22:07:04 +020050" Switch syntax highlighting on when the terminal has colors or when using the
51" GUI (which always has colors).
Bram Moolenaar071d4272004-06-13 20:20:40 +000052if &t_Co > 2 || has("gui_running")
53 syntax on
Bram Moolenaar54f1b7a2016-04-05 22:07:04 +020054
55 " Also switch on highlighting the last used search pattern.
Bram Moolenaar071d4272004-06-13 20:20:40 +000056 set hlsearch
Bram Moolenaar54f1b7a2016-04-05 22:07:04 +020057
58 " I like highlighting strings inside C comments.
59 let c_comment_strings=1
Bram Moolenaar071d4272004-06-13 20:20:40 +000060endif
61
62" Only do this part when compiled with support for autocommands.
63if has("autocmd")
64
65 " Enable file type detection.
66 " Use the default filetype settings, so that mail gets 'tw' set to 72,
67 " 'cindent' is on in C files, etc.
68 " Also load indent files, to automatically do language-dependent indenting.
69 filetype plugin indent on
70
71 " Put these in an autocmd group, so that we can delete them easily.
72 augroup vimrcEx
73 au!
74
75 " For all text files set 'textwidth' to 78 characters.
76 autocmd FileType text setlocal textwidth=78
77
78 " When editing a file, always jump to the last known cursor position.
79 " Don't do it when the position is invalid or when inside an event handler
80 " (happens when dropping a file on gvim).
81 autocmd BufReadPost *
Bram Moolenaar5a5f4592015-04-13 12:43:06 +020082 \ if line("'\"") >= 1 && line("'\"") <= line("$") |
Bram Moolenaarc81e5e72007-05-05 18:24:42 +000083 \ exe "normal! g`\"" |
Bram Moolenaar071d4272004-06-13 20:20:40 +000084 \ endif
85
86 augroup END
87
88else
89
90 set autoindent " always set autoindenting on
91
92endif " has("autocmd")
Bram Moolenaarc81e5e72007-05-05 18:24:42 +000093
94" Convenient command to see the difference between the current buffer and the
95" file it was loaded from, thus the changes you made.
Bram Moolenaaraba88572008-06-25 20:13:35 +000096" Only define it when not defined already.
97if !exists(":DiffOrig")
Bram Moolenaar8e5af3e2011-04-28 19:02:44 +020098 command DiffOrig vert new | set bt=nofile | r ++edit # | 0d_ | diffthis
Bram Moolenaaraba88572008-06-25 20:13:35 +000099 \ | wincmd p | diffthis
100endif
Bram Moolenaar4391cf92014-11-05 17:44:52 +0100101
102if has('langmap') && exists('+langnoremap')
103 " Prevent that the langmap option applies to characters that result from a
104 " mapping. If unset (default), this may break plugins (but it's backward
105 " compatible).
106 set langnoremap
107endif
Bram Moolenaaraedfcbe2016-03-25 17:02:51 +0100108
109
110" Add optional packages.
111"
112" The matchit plugin makes the % command work better, but it is not backwards
113" compatible.
114packadd matchit