[vim] change cursor shape based on mode
[~bandali/configs] / vim / .vimrc
1 "set nocompatible " be iMproved, required
2 "filetype off " required
3
4 call plug#begin('~/.vim/plugged')
5
6 Plug 'kien/rainbow_parentheses.vim'
7 "Plug 'hsanson/vim-android'
8 Plug 'scrooloose/nerdcommenter'
9 Plug 'SirVer/ultisnips' | Plug 'honza/vim-snippets'
10 "Plug 'kien/ctrlp.vim'
11 "Plug 'tacahiroy/ctrlp-funky'
12 Plug 'Raimondi/delimitMate'
13 Plug 'Yggdroot/indentLine'
14 "Plug 'tpope/vim-fugitive'
15 Plug 'airblade/vim-gitgutter'
16 "Plug 'altercation/vim-colors-solarized'
17 Plug 'terryma/vim-multiple-cursors'
18 "Plug 'elzr/vim-json'
19 "Plug 'lervag/vim-latex'
20 Plug 'tpope/vim-surround'
21 Plug 'rust-lang/rust.vim'
22 Plug 'phildawes/racer'
23 Plug 'whatyouhide/vim-gotham'
24
25 call plug#end()
26
27
28 " Use the Solarized Dark theme
29 set background=dark
30 colorscheme gotham
31
32 " Make Vim more useful
33 set nocompatible
34 " Use the OS clipboard by default (on versions compiled with `+clipboard`)
35 set clipboard=unnamedplus
36 " Enhance command-line completion
37 set wildmenu
38 " Allow cursor keys in insert mode
39 set esckeys
40 " Allow backspace in insert mode
41 set backspace=indent,eol,start
42 " Optimize for fast terminal connections
43 set ttyfast
44 " Add the g flag to search/replace by default
45 set gdefault
46 " Use UTF-8 without BOM
47 set encoding=utf-8 nobomb
48 " Change mapleader
49 let mapleader=","
50 " Don’t add empty newlines at the end of files
51 set binary
52 set noeol
53 " Centralize backups, swapfiles and undo history
54 set backupdir=~/.vim/backups
55 set directory=~/.vim/swaps
56 if exists("&undodir")
57 set undodir=~/.vim/undo
58 endif
59 set undofile
60
61 " Don’t create backups when editing files in certain directories
62 set backupskip=/tmp/*,/private/tmp/*
63
64 " Respect modeline in files
65 set modeline
66 set modelines=4
67 " Enable per-directory .vimrc files and disable unsafe commands in them
68 set exrc
69 set secure
70 " Enable line numbers
71 set number
72 " Enable syntax highlighting
73 syntax on
74 " Highlight current line
75 "set cursorline
76 " Make tabs as wide as two spaces
77 set tabstop=4
78 " Show “invisible” characters
79 set lcs=tab:▸\ ,eol:\ \,nbsp:_
80 " set lcs=tab:▸\ ,trail:·,eol:¬,nbsp:_
81 set list
82 " Highlight searches
83 set hlsearch
84 " Ignore case of searches
85 set ignorecase
86 " Highlight dynamically as pattern is typed
87 set incsearch
88 " Always show status line
89 set laststatus=2
90 " Enable mouse in all modes
91 set mouse=a
92 " Disable error bells
93 set noerrorbells
94 " Don’t reset cursor to start of line when moving around.
95 set nostartofline
96 " Show the cursor position
97 set ruler
98 " Don’t show the intro message when starting Vim
99 set shortmess=atI
100 " Show the current mode
101 set showmode
102 " Show the filename in the window titlebar
103 set title
104 " Show the (partial) command as it’s being typed
105 set showcmd
106 " Use relative line numbers
107 "if exists("&relativenumber")
108 "set relativenumber
109 "au BufReadPost * set relativenumber
110 "endif
111 " Start scrolling three lines before the horizontal window border
112 set scrolloff=3
113
114 " Strip trailing whitespace (,ss)
115 function! StripWhitespace()
116 let save_cursor = getpos(".")
117 let old_query = getreg('/')
118 :%s/\s\+$//e
119 call setpos('.', save_cursor)
120 call setreg('/', old_query)
121 endfunction
122 noremap <leader>ss :call StripWhitespace()<CR>
123 " Save a file as root (,W)
124 noremap <leader>W :w !sudo tee % > /dev/null<CR>
125
126 " Automatic commands
127 if has("autocmd")
128 " Enable file type detection
129 filetype plugin indent on
130 " Treat .json files as .js
131 autocmd BufNewFile,BufRead *.json setfiletype json syntax=javascript
132 endif
133
134 " Enable pathogen
135 "execute pathogen#infect()
136
137 " swap ; and :
138 nnoremap ; :
139 nnoremap : ;
140 vnoremap ; :
141 vnoremap : ;
142
143 ":au FocusLost * :set number
144 ":au FocusGained * :set relativenumber
145 autocmd InsertEnter * :set number
146 autocmd InsertEnter * :set norelativenumber
147 autocmd InsertLeave * :set relativenumber
148 "autocmd InsertLeave * :set nonumber
149
150 " Rainbow Parantheses
151 au Syntax * RainbowParenthesesLoadRound
152 au Syntax * RainbowParenthesesLoadSquare
153 au Syntax * RainbowParenthesesLoadBraces
154 noremap <leader>m :RainbowParenthesesToggle<CR>
155
156
157 " ==== <UltiSnips> ====
158 " Trigger configuration. Do not use <tab> if you use
159 " https://github.com/Valloric/YouCompleteMe.
160 let g:UltiSnipsExpandTrigger="<tab>"
161 "let g:UltiSnipsJumpForwardTrigger="<c-b>"
162 let g:UltiSnipsJumpForwardTrigger="<tab>"
163 "let g:UltiSnipsJumpBackwardTrigger="<c-z>"
164 let g:UltiSnipsJumpBackwardTrigger="<s-tab>"
165 " ==== </UltiSnips> ====
166
167 " Spaces FTW
168 set shiftwidth=4
169 set expandtab
170
171 let g:ctrlp_map = '<space>'
172 "let g:ctrlp_map = '<leader>p'
173 set wildignore+=*/build/**
174 let g:android_sdk_path= '/Applications/Android\ Studio.app/sdk/'
175 let g:android_adb_tool= '/Applications/Android\ Studio.app/sdk/platform-tools/adb'
176 let gradle_path= '~/.gradle/'
177 let g:android_build_type= 'gradle'
178
179 let delimitMate_expand_space=1
180 let delimitMate_expand_cr=2
181
182 let g:indentLine_enabled=1
183 "let g:indentLine_color_term = 239
184 "let g:indentLine_color_gui = '#09AA08'
185 "let g:indentLine_char = '│'
186 let g:indentLine_char = '¦'
187
188 " ctrlp {
189 if isdirectory(expand("~/.vim/bundle/ctrlp.vim/"))
190 let g:ctrlp_working_path_mode = 'ra'
191 nnoremap <silent> <D-t> :CtrlP<CR>
192 nnoremap <silent> <D-r> :CtrlPMRU<CR>
193 let g:ctrlp_custom_ignore = {
194 \ 'dir': '\.git$\|\.hg$\|\.svn$',
195 \ 'file': '\.exe$\|\.so$\|\.dll$\|\.pyc$' }
196
197 " On Windows use "dir" as fallback command.
198 if executable('ag')
199 let s:ctrlp_fallback = 'ag %s --nocolor -l -g ""'
200 elseif executable('ack-grep')
201 let s:ctrlp_fallback = 'ack-grep %s --nocolor -f'
202 elseif executable('ack')
203 let s:ctrlp_fallback = 'ack %s --nocolor -f'
204 else
205 let s:ctrlp_fallback = 'find %s -type f'
206 endif
207 let g:ctrlp_user_command = {
208 \ 'types': {
209 \ 1: ['.git', 'cd %s && git ls-files . --cached --exclude-standard --others'],
210 \ 2: ['.hg', 'hg --cwd %s locate -I .'],
211 \ },
212 \ 'fallback': s:ctrlp_fallback
213 \ }
214
215 if isdirectory(expand("~/.vim/bundle/ctrlp-funky/"))
216 " CtrlP extensions
217 let g:ctrlp_extensions = ['funky']
218
219 "funky
220 nnoremap <Leader>fu :CtrlPFunky<Cr>
221 endif
222 endif
223 "}
224 "
225
226 " change cursor shape based on mode
227 if &term =~ "xterm\\|rxvt"
228 " use a solid vertical bar in insert mode
229 let &t_SI .= "\<Esc>[6 q"
230 " use a solid block otherwise
231 let &t_EI .= "\<Esc>[2 q"
232 endif
233 " eliminite the delay when switching modes
234 set ttimeoutlen=0
235
236 set pastetoggle=<leader>p
237
238 "set conceallevel=0
239 "let g:vim_json_syntax_conceal = 0
240 "let g:indentLine_noConcealCursor=""
241 " latex mode settings
242 let g:Tex_DefaultTargetFormat = "pdf"
243
244 set hidden
245 let g:racer_cmd = "racer"
246 let $RUST_SRC_PATH=expand('~/misc/rs/rust/src/')