-
Notifications
You must be signed in to change notification settings - Fork 0
/
.vimrc
209 lines (182 loc) · 5.76 KB
/
.vimrc
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
set nocompatible
filetype off
" ================ UPDATER ================== "
if !has('python3')
call confirm('You must have vim compiled with python3', 'OK')
finish
endif
function UpdateUpdater()
silent !curl -fLo ~/.vimrc.updater.py
\ https://raw.githubusercontent.com/Joklost/.vimrc/master/updater.py
endfunction
if empty(glob('~/.vimrc.updater.py'))
call UpdateUpdater()
endif
py3file ~/.vimrc.updater.py
function UpdateVimrc()
silent !curl -fLo ~/.vimrc.json
\ https://raw.githubusercontent.com/Joklost/.vimrc/master/version.json
silent !curl -fLo ~/.vimrc
\ https://raw.githubusercontent.com/Joklost/.vimrc/master/.vimrc
call UpdateUpdater()
silent !echo 'The latest .vimrc version has been downloaded.'
endfunction
function UpdateVimrcCmd()
call UpdateVimrc()
:q!
endfunction
function CheckUpdates()
" The python function asks the user to type :Update,
" as I have no easy way to get the output of a python
" function.
python3 check_updates()
endfunction
command CheckUpdates call CheckUpdates()
command Update call UpdateVimrcCmd()
" =========================================== "
" ================ PLUGINS ================== "
if empty(glob('~/.vim/autoload/plug.vim'))
let g:first_time = 1
silent !mkdir -p ~/.vim/autoload
silent !curl -fLo ~/.vim/autoload/plug.vim
\ https://raw.githubusercontent.com/junegunn/vim-plug/master/plug.vim
autocmd VimEnter * PlugInstall --sync | qall
endif
call plug#begin('~/.vim/plugged')
Plug 'vim-scripts/taglist.vim'
Plug 'vim-scripts/indentpython.vim'
Plug 'ntpeters/vim-better-whitespace'
Plug 'nvie/vim-flake8'
Plug 'christoomey/vim-tmux-navigator'
Plug 'easymotion/vim-easymotion'
Plug 'scrooloose/nerdtree'
python3 add_plugins()
call plug#end()
if exists('g:first_time')
call UpdateVimrc()
finish
endif
call CheckUpdates()
" =========================================== "
" ================ SETTINGS ================= "
filetype indent plugin on
filetype plugin on
syntax on
set autoindent
set smartindent
set hidden
set wildmenu
set showcmd
set nohlsearch
set wrap
set backspace=indent,eol,start
set nostartofline
set ruler
set laststatus=2
set confirm
set number
set ttimeoutlen=50
set shiftwidth=4
set softtabstop=4
set expandtab
set autoread
set shortmess+=c
set whichwrap+=h,l,[,]
set fileformat=unix
set encoding=utf-8
"set list
"set listchars=tab:,trail:
set breakindent
set showmode
let python_highlist_all=1
let mapleader=","
" ================= AUTOCMD ================= "
" Save all files on loss of focus
au FocusLost * :silent! wall
" Return to normal mode on loss of focus
au FocusLost * call feedkeys('\<C-\>\<C-n>')
" Disable paste when leaving insert mode
au InsertLeave * set nopaste
" Show git diff when writing a commit
au FileType gitcommit DiffGitCached | wincmd p
" Jump to the last position when reopening file
au BufReadPost * if line("'\"") > 1 && line("'\"") <= line("$") | exe "normal! g'\"" | endif
" =============== HIGHLIGHTS ================ "
highlight Visual term=reverse ctermbg=237 guibg=#575b61
"highlight! link Search CursorLine
" ================ KEYBINDS ================= "
" Binds kj and jk to Esc for easily exiting insert mode without reaching for
" the escape button. Also rebinds F1 to Esc to disable built-in help.
imap jk <Esc>
imap kj <Esc>
noremap <F1> <Esc>
vnoremap <F1> <Esc>
inoremap <F1> <Esc>
" Allows smooth movement through a line spanning multiple visual lines.
" This is good for editing LaTeX, as some of the lines can be quite long.
" Up & Down
nnoremap <S-j> gj
nnoremap <S-k> gk
vnoremap <S-j> gj
vnoremap <S-k> gk
" Right & Left
nnoremap <S-l> $
nnoremap <S-h> ^
vnoremap <S-l> $
vnoremap <S-h> ^
" Because of the above lines, it is no longer possible to join two lines. This
" bind fixes that.
nnoremap <leader>j J
" Easy motion between splits. Also allows for some clever tmux usage where the
" same binds can be used to move effortlessly between tmux splits and Vim splits.
map <C-j> <C-W>j
map <C-k> <C-W>k
map <C-h> <C-W>h
map <C-l> <C-W>l
" Easily toggle spell checker.
map <leader>ss :setlocal spell!<cr>
" Sort selection
vnoremap <leader>s :sort<cr>
" Allows for easy indentation of selected lines in visual mode.
vnoremap < <gv
vnoremap > >gv
" Force write using sudo.
cmap w!! %!sudo tee > /dev/null %
" Center view when iterating through matches in a search.
nnoremap <silent> n nzz
nnoremap <silent> N Nzz
nnoremap <silent> * *zz
nnoremap <silent> # #zz
" Adds a # sign in front of current line, and move to beginning of next line
" (comment line).
map <leader>c I#<space><esc>j^
" Remove first two characters and current line, and move to beginning of
" previous line (uncomment line).
map <leader>C ^xxj^
" Replace standard jump motions with easymotion (sooo good).
map b <Plug>(easymotion-b)
map B <Plug>(easymotion-B)
map e <Plug>(easymotion-e)
map E <Plug>(easymotion-E)
map w <Plug>(easymotion-w)
map W <Plug>(easymotion-W)
map <leader>f <Plug>(easymotion-overwin-f2)
nmap <C-n> :NERDTreeToggle<cr>
" Disable Arrow keys in Escape mode
map <up> <nop>
map <down> <nop>
" Use left and right arrow to switch between buffers
map <left> :bprev<CR>
map <right> :bnext<CR>
" Disable Arrow keys in Insert mode
imap <up> <nop>
imap <down> <nop>
imap <left> <nop>
imap <right> <nop>
" Disable Arrow keys in Insert mode
vmap <up> <nop>
vmap <down> <nop>
vmap <left> <nop>
vmap <right> <nop>
python3 load_cmds()
python3 source_vimfiles()