๐Ÿ“ฆ andreifilip123 / dotfiles

๐Ÿ“„ .vimrc ยท 222 lines
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222set encoding=utf-8
set fileencoding=utf-8
set termencoding=utf-8
set visualbell
set t_vb=

set incsearch
set hlsearch
" Keep search matches in the middle of the window.
nnoremap n nzzzv
nnoremap N Nzzzv

set number
set showmatch " Blinks the closing brackets to show match
set matchtime=2 " Hundreds of milliseconds to show the matching parent
set virtualedit=block " Cursor block limit gone only in <C-V> mode
set autoindent
set smartindent
filetype indent on
set tabstop=2
set shiftwidth=2
set softtabstop=2
set expandtab
set smarttab
set cursorline
set scrolloff=999
set ruler
set ignorecase
set smartcase
set noerrorbells

"
" Folding -----------------------------------------------------------------

" Options & Mappings

set foldenable "Enable code folding

set foldlevelstart=0
set foldmethod=syntax

" Space to toggle folds.
nnoremap <Space> za
vnoremap <Space> za

set laststatus=2
set noshowmode
set clipboard=unnamed
set fileformat=unix " new line endings
set ttyfast " faster terminal
set undofile " Save undo history in a file
set undoreload=10000 " Costly for Memory
set title " Show the title in window bar
set autowrite
set autoread
set mousehide "Hide mouse when typing
set shell=zsh
set wildignore+=*/tmp/*,*/node_modules/*     " MacOSX/Linux

" Sudo to write
cnoremap w!! w !sudo tee % >/dev/null
command! Q :q
command! Qa :qa
command! QA :qa
command! W :w

" ================ Turn Off Swap Files ==============
set noswapfile
set nobackup
set nowb

" ================ Persistent Undo ==================
" Keep undo history across sessions, by storing in file.
" Only works all the time.
if has('persistent_undo')
  silent !mkdir ~/.vim/backups > /dev/null 2>&1
  set undodir=~/.vim/backups
  set undofile
endif

" Auto indent pasted text
nnoremap p p=`]<C-o>
nnoremap P P=`]<C-o>

"
" Line Return

" Make sure Vim returns to the same line when you reopen a file.
augroup line_return
    au!
    au BufReadPost *
        \ if line("'\"") > 0 && line("'\"") <= line("$") |
        \     execute 'normal! g`"zvzz' |
        \ endif
augroup END

" Disable arrow keys
map <up> <nop>
map <down> <nop>
map <left> <nop>
map <right> <nop>

" Automatically install Vim Plug if not installed
if empty(glob('~/.vim/autoload/plug.vim'))
  silent !curl -fLo ~/.vim/autoload/plug.vim --create-dirs
    \ https://raw.githubusercontent.com/junegunn/vim-plug/master/plug.vim
  autocmd VimEnter * PlugInstall --sync | source $MYVIMRC
endif

" Vim Plug zone
call plug#begin('~/.vim/plugged')

" Basics
Plug 'tpope/vim-sensible'

" Looks
Plug 'crusoexia/vim-monokai' " Monokai Theme
Plug 'mhinz/vim-signify' " Show git diff signs before lines
Plug 'fortes/vim-escuro'

" Utility
Plug 'scrooloose/nerdtree' " Navigation tree
Plug 'jistr/vim-nerdtree-tabs' " Tabs for NERDTree
Plug 'kien/ctrlp.vim' " Search for file
Plug 'itchyny/lightline.vim' " That nice line at the bottom of this file
Plug 'ervandew/supertab' "Autocompletion using tab
Plug 'tpope/vim-commentary' " Comment using gc or gcc
Plug 'Raimondi/delimitMate' " Auto insert brackets/quotes/etc
Plug 'junegunn/fzf', { 'dir': '~/.fzf', 'do': './install --all' }
Plug 'junegunn/fzf.vim' " Search in all project
Plug 'pakutoma/toggle-terminal' " Toggle :terminal
Plug 'vim-syntastic/syntastic' " ESLint and stuff
Plug 'w0rp/ale' " ESLint and stuff
Plug 'zivyangll/git-blame.vim' " Git blame

" Languages
Plug 'sheerun/vim-polyglot' " Collection of languages
Plug 'pangloss/vim-javascript'
Plug 'crusoexia/vim-javascript-lib'
Plug 'othree/javascript-libraries-syntax.vim'


call plug#end()

let mapleader = ","
syntax on
syntax enable
color escuro
set t_Co=256
let g:monokai_term_italic = 1
let g:monokai_gui_italic = 1

" Remap ctrlp to cmd T
let g:ctrlp_map = '<Leader>t'
let g:ctrlp_cmd = 'CtrlP'
let g:ctrlp_custom_ignore = {
  \ 'dir':  '\.git$\|node_modules\|ios\/build\|ios\/.*\.xcworkspace\|ios\/.*\.xcodeproj\|ios\/Pods\|android\/app\/build$',
  \ 'file': '\.exe$\|\.so$\|\.dat$'
  \ }
let g:ctrlp_working_path_mode = 'ra'

" FZF
nnoremap <silent> <Leader>f :Ag<CR>

" NERDTree config
nmap <Leader>n :NERDTreeTabsToggle<CR>
let g:NERDTreeWinSize=30
let g:nerdtree_tabs_open_on_console_startup=1

" Close vim if the only window left open is a NERDTree
autocmd bufenter * if (winnr("$") == 1 && exists("b:NERDTree") && b:NERDTree.isTabTree()) | q | endif

" Open NERDTree automatically when vim starts up on opening a directory
autocmd StdinReadPre * let s:std_in=1
autocmd VimEnter * if argc() == 1 && isdirectory(argv()[0]) && !exists("s:std_in") | exe 'NERDTree' argv()[0] | wincmd p | ene | exe 'cd '.argv()[0] | endif

nnoremap . <NOP>
nmap <Leader>s :write<Enter>
set termwinsize=15x0
set splitbelow
tnoremap <silent> <Leader>. <C-w>:ToggleTerminal<CR>
nnoremap <silent> <Leader>. :ToggleTerminal<CR>
let g:toggle_terminal#command = 'zsh'

" Check if NERDTree is open or active
function! IsNERDTreeOpen()
  return exists("t:NERDTreeBufName") && (bufwinnr(t:NERDTreeBufName) != -1)
endfunction

" Call NERDTreeFind iff NERDTree is active, current window contains a modifiable
" file, and we're not in vimdiff
function! SyncTree()
  if &modifiable && IsNERDTreeOpen() && strlen(expand('%')) > 0 && !&diff
    NERDTreeFind
    wincmd p
  endif
endfunction

" Highlight currently open buffer in NERDTree
autocmd BufEnter * call SyncTree()

" Open images in vim (requires iterm)
autocmd BufEnter *.png,*.jpg,*gif exec "! ~/.iterm2/imgcat ".expand("%") | :bw

" Configure Syntastic
set statusline+=%#warningmsg#
set statusline+=%{SyntasticStatuslineFlag()}
set statusline+=%*
let g:syntastic_always_populate_loc_list = 1
let g:syntastic_auto_loc_list = 1
let g:syntastic_check_on_open = 1
let g:syntastic_check_on_wq = 0
let g:syntastic_javascript_checkers = ['eslint']
let g:syntastic_javascript_eslint_exe = 'npm run lint --'

let g:ale_fixers = {
\  'javascript': ['eslint']
\}

" Use ESC to exit insert mode in :term
tnoremap <Esc> <C-\\><C-n>