]> code.delx.au - dotfiles/blob - .vimrc
Moved vim temp files to ~/.cache
[dotfiles] / .vimrc
1 set nocompatible
2 set backspace=indent,eol,start
3
4
5 set backup
6 set backupcopy=yes
7 set directory=~/.cache/vim/swap//
8 set backupdir=~/.cache/vim/backup//
9 set undodir=~/.cache/vim/undo//
10 silent exec "!mkdir -p ~/.cache/vim/{swap,backup,undo}/"
11 silent exec '!find ~/.cache/vim/ -type f -mtime +3 -delete'
12
13
14 syntax on
15 filetype plugin indent on
16
17 " restore position when opening files
18 autocmd BufReadPost *
19 \ if line("'\"") >= 1 && line("'\"") <= line("$") && &ft !~# 'commit'
20 \ | exe "normal! g`\""
21 \ | endif
22
23 " don't automatically continue comments on new lines
24 autocmd BufNewFile,BufRead * setlocal formatoptions-=r
25
26
27 " xterm mouse
28 set mouse=a
29
30 " xterm titles
31 set title
32 " filename (~/some/dir) (1 of 2) (hostname)
33 set titlestring=%t%(\ %M%)%(\ (%{expand(\"%:p:~:h\")})%)%(\ %a%)\ (%{hostname()})
34 set t_ts=\e]0;
35 set t_fs=\a
36
37
38 " show useful things on the status line
39 set showmode
40 set showcmd
41 set ruler
42
43 " display as much as possible of the last line, instead of @
44 set display+=lastline
45
46 " matching brackets
47 set showmatch
48
49 " auto-complete should work like bash
50 set wildmode=longest,list
51
52 " show one extra line when scrolling
53 set scrolloff=1
54
55 " decent searching
56 set incsearch
57 set ignorecase
58 set smartcase
59 set hlsearch
60
61
62 " decent indentation
63 set autoindent
64 set copyindent
65 set shiftround
66
67 " spaces over tabs
68 set expandtab
69 set tabstop=8
70 set softtabstop=4
71 set shiftwidth=4
72
73 " single indent for line continuations
74 set cinoptions=+1s
75 set cinoptions=(1s
76 let g:pyindent_open_paren = &sw
77 let g:pyindent_continue = &sw
78 let g:vim_indent_cont = &sw
79
80 " don't allow syntax/sh.vim to change my iskeyword setting
81 let g:sh_noisk=1
82
83 " single space after full stop
84 set nojoinspaces
85
86 " disable octal
87 set nrformats-=octal
88
89
90 nmap <C-n> :next<CR>
91 nmap <C-p> :prev<CR>
92
93 nmap <C-l> :nohlsearch<CR>:redraw!<CR>
94
95 command SudoWrite call SudoWriteFunction()
96
97 map <F8> :call ToggleSpelling()<CR>
98 imap <F8> <C-o>:call ToggleSpelling()<CR>
99 map <F9> :call InvShow()<CR>
100 imap <F9> <C-o>:call InvShow()<CR>
101 map <F10> :call WrapToggle()<CR>
102 imap <F10> <C-o>:call WrapToggle()<CR>
103 map <F11> :call PasteToggle()<CR>
104 imap <F11> <C-o>:call PasteToggle()<CR>
105
106
107 function ToggleSpelling()
108 if !exists("s:spell_check") || s:spell_check == 0
109 echo "Spell check on"
110 let s:spell_check = 1
111 setlocal spell spelllang=en_au
112 else
113 echo "Spell check off"
114 let s:spell_check = 0
115 setlocal spell spelllang=
116 endif
117 endfunction
118
119 function WrapToggle()
120 if &wrap
121 set nowrap
122 echo "Word wrap off"
123 else
124 set wrap
125 echo "Word wrap on"
126 endif
127 endfunction
128
129 function InvShow()
130 if &list
131 echo "Invisible characters off"
132 set nolist
133 else
134 echo "Invisible characters on"
135 set listchars=tab:.\ ,trail:!
136 set list
137 endif
138 endfunction
139
140 function SudoWriteFunction()
141 :w !sudo tee %
142 :e!
143 endfunction
144
145 function PasteToggle()
146 if &paste
147 set nopaste
148 echo "Paste mode disabled"
149 else
150 set paste
151 echo "Paste mode enabled"
152 endif
153 endfunction
154
155
156 " typos
157 command WQA :wqa
158 command WqA :wqa
159 command WQa :wqa
160 command Wqa :wqa
161 command WA :wa
162 command Wa :wa
163 command WQ :wq
164 command Wq :wq
165 command W :w
166 command Wn :wn
167 command WN :wn
168 command Wp :wp
169 command WP :wp
170 command QA :qa
171 command Qa :qa
172 command Q :q
173