[vim] save file as root with <leader>w
[~bandali/configs] / vim / .vimrc
CommitLineData
38acf911
AB
1"set nocompatible " be iMproved, required
2"filetype off " required
3
4call plug#begin('~/.vim/plugged')
5
6Plug 'kien/rainbow_parentheses.vim'
7"Plug 'hsanson/vim-android'
8Plug 'scrooloose/nerdcommenter'
9Plug 'SirVer/ultisnips' | Plug 'honza/vim-snippets'
10"Plug 'kien/ctrlp.vim'
11"Plug 'tacahiroy/ctrlp-funky'
12Plug 'Raimondi/delimitMate'
13Plug 'Yggdroot/indentLine'
14"Plug 'tpope/vim-fugitive'
15Plug 'airblade/vim-gitgutter'
16"Plug 'altercation/vim-colors-solarized'
17Plug 'terryma/vim-multiple-cursors'
18"Plug 'elzr/vim-json'
19"Plug 'lervag/vim-latex'
20Plug 'tpope/vim-surround'
21Plug 'rust-lang/rust.vim'
22Plug 'phildawes/racer'
37cd1e87 23Plug 'whatyouhide/vim-gotham'
38acf911
AB
24
25call plug#end()
26
debd020d
AB
27
28" Use the Solarized Dark theme
29set background=dark
37cd1e87 30colorscheme gotham
debd020d
AB
31
32" Make Vim more useful
33set nocompatible
34" Use the OS clipboard by default (on versions compiled with `+clipboard`)
3bdc98f3 35set clipboard=unnamedplus
debd020d
AB
36" Enhance command-line completion
37set wildmenu
38" Allow cursor keys in insert mode
39set esckeys
40" Allow backspace in insert mode
41set backspace=indent,eol,start
42" Optimize for fast terminal connections
43set ttyfast
44" Add the g flag to search/replace by default
45set gdefault
46" Use UTF-8 without BOM
47set encoding=utf-8 nobomb
48" Change mapleader
49let mapleader=","
50" Don’t add empty newlines at the end of files
51set binary
52set noeol
53" Centralize backups, swapfiles and undo history
54set backupdir=~/.vim/backups
55set directory=~/.vim/swaps
56if exists("&undodir")
57 set undodir=~/.vim/undo
58endif
59set undofile
60
61" Don’t create backups when editing files in certain directories
62set backupskip=/tmp/*,/private/tmp/*
63
64" Respect modeline in files
65set modeline
66set modelines=4
67" Enable per-directory .vimrc files and disable unsafe commands in them
68set exrc
69set secure
70" Enable line numbers
71set number
72" Enable syntax highlighting
73syntax on
74" Highlight current line
75"set cursorline
76" Make tabs as wide as two spaces
77set tabstop=4
78" Show “invisible” characters
79set lcs=tab:▸\ ,eol:\ \,nbsp:_
80" set lcs=tab:▸\ ,trail:·,eol:¬,nbsp:_
81set list
82" Highlight searches
83set hlsearch
84" Ignore case of searches
85set ignorecase
86" Highlight dynamically as pattern is typed
87set incsearch
88" Always show status line
89set laststatus=2
90" Enable mouse in all modes
91set mouse=a
92" Disable error bells
93set noerrorbells
94" Don’t reset cursor to start of line when moving around.
95set nostartofline
96" Show the cursor position
97set ruler
98" Don’t show the intro message when starting Vim
99set shortmess=atI
100" Show the current mode
101set showmode
102" Show the filename in the window titlebar
103set title
104" Show the (partial) command as it’s being typed
105set showcmd
106" Use relative line numbers
75905dbc
AB
107"if exists("&relativenumber")
108 "set relativenumber
109 "au BufReadPost * set relativenumber
110"endif
debd020d
AB
111" Start scrolling three lines before the horizontal window border
112set scrolloff=3
113
114" Strip trailing whitespace (,ss)
115function! 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)
121endfunction
122noremap <leader>ss :call StripWhitespace()<CR>
2c667b7e
AB
123" Save a file as root (,w)
124noremap <leader>w :w !sudo tee % > /dev/null<CR>
debd020d
AB
125
126" Automatic commands
127if 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
132endif
133
134" Enable pathogen
135"execute pathogen#infect()
136
137" swap ; and :
138 nnoremap ; :
139 nnoremap : ;
140 vnoremap ; :
141 vnoremap : ;
142
debd020d
AB
143":au FocusLost * :set number
144":au FocusGained * :set relativenumber
145autocmd InsertEnter * :set number
146autocmd InsertEnter * :set norelativenumber
147autocmd InsertLeave * :set relativenumber
148"autocmd InsertLeave * :set nonumber
149
150" Rainbow Parantheses
151au Syntax * RainbowParenthesesLoadRound
152au Syntax * RainbowParenthesesLoadSquare
153au Syntax * RainbowParenthesesLoadBraces
154noremap <leader>m :RainbowParenthesesToggle<CR>
155
156
157" ==== <UltiSnips> ====
158" Trigger configuration. Do not use <tab> if you use
159" https://github.com/Valloric/YouCompleteMe.
160let g:UltiSnipsExpandTrigger="<tab>"
161"let g:UltiSnipsJumpForwardTrigger="<c-b>"
162let g:UltiSnipsJumpForwardTrigger="<tab>"
163"let g:UltiSnipsJumpBackwardTrigger="<c-z>"
164let g:UltiSnipsJumpBackwardTrigger="<s-tab>"
165" ==== </UltiSnips> ====
166
167" Spaces FTW
168set shiftwidth=4
169set expandtab
170
dc1f43cb
AB
171let g:ctrlp_map = '<space>'
172"let g:ctrlp_map = '<leader>p'
debd020d
AB
173set wildignore+=*/build/**
174let g:android_sdk_path= '/Applications/Android\ Studio.app/sdk/'
175let g:android_adb_tool= '/Applications/Android\ Studio.app/sdk/platform-tools/adb'
176let gradle_path= '~/.gradle/'
177let g:android_build_type= 'gradle'
178
179let delimitMate_expand_space=1
180let delimitMate_expand_cr=2
181
182let g:indentLine_enabled=1
183"let g:indentLine_color_term = 239
184"let g:indentLine_color_gui = '#09AA08'
185"let g:indentLine_char = '│'
186let 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
58b04a47
AB
227if &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"
232endif
233" eliminite the delay when switching modes
234set ttimeoutlen=0
debd020d 235
dc1f43cb 236set pastetoggle=<leader>p
debd020d 237
b55b6430
AB
238"set conceallevel=0
239"let g:vim_json_syntax_conceal = 0
240"let g:indentLine_noConcealCursor=""
45688401
AB
241" latex mode settings
242let g:Tex_DefaultTargetFormat = "pdf"
38acf911
AB
243
244set hidden
245let g:racer_cmd = "racer"
246let $RUST_SRC_PATH=expand('~/misc/rs/rust/src/')