-
Notifications
You must be signed in to change notification settings - Fork 1
Expand file tree
/
Copy pathvimrc
More file actions
283 lines (271 loc) · 9.37 KB
/
vimrc
File metadata and controls
283 lines (271 loc) · 9.37 KB
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
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""
" general
""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""
" color scheme
colorscheme elflord
" colorscheme solarized
" colorscheme desert
" allow switching between buffers without writing them
set hidden
" how many line of history
set history=5000
" re-load file when modified from outisde
set autoread
" encoding
set encoding=utf-8
" enable syntax highighting
syntax enable
" custom leader / localleader
let mapleader = ","
let maplocalleader = ","
" 256 colours
set t_Co=256
" start scrolling slightly before the cursor reaches an edge
set scrolloff=10
set sidescrolloff=10
" scroll sideways a character at a time, rather than a screen at a time
set sidescroll=1
" allow motions and back-spacing over line-endings etc
set backspace=indent,eol,start
set whichwrap=h,l,b,<,>
" underscores denote words
set iskeyword+=-
" :W sudo saves the file
command! W w !sudo tee % > /dev/null
" enable filetype plugins
filetype plugin on
filetype indent on
" backup, undo and swap files (in another directory)
if !isdirectory($HOME."/.vim/tmp/undo-dir")
call mkdir($HOME."/.vim/tmp/undo-dir", "p", 0750)
endif
set backupdir=~/.vim/tmp
set directory=~/.vim/tmp
set undodir=~/.vim/tmp/undo-dir
set backup
set swapfile
set undofile
" show file title in terminal tab
set title
" rename pane with file name
if exists('$TMUX')
autocmd BufEnter * call system("tmux rename-window '" . expand("%:t") . "'")
autocmd VimLeave * call system("tmux setw automatic-rename")
endif
" restore cursor position
function! ResCur()
if line("'\"") <= line("$")
normal! g`"
return 1
endif
endfunction
augroup resCur
autocmd!
autocmd BufWinEnter * call ResCur()
augroup END
""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""
" Line number
""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""
set number
highlight LineNr ctermfg=grey
set cursorline
highlight clear CursorLine
""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""
" text, tab and indent
""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""
" insert spaces instead of tab characters
set expandtab
" display special char for weird space (fighting yaml o/)
set listchars=nbsp:☠,tab:▸␣
" size of an indent measured in spaces
set shiftwidth=2
set tabstop=2
set softtabstop=2
" auto indent
set autoindent
" wrap lines
set wrap
" don't insert space after J
set nojoinspaces
" language specific
autocmd Filetype python setlocal expandtab tabstop=4 shiftwidth=4
autocmd FileType yaml setlocal keywordprg=ansible-doc autoindent tabstop=2 shiftwidth=2 expandtab
autocmd FileType vim setlocal keywordprg=:help
autocmd FileType python setlocal keywordprg=pydoc autoindent tabstop=4 shiftwidth=4 expandtab
autocmd FileType perl setlocal keywordprg=perldoc autoindent tabstop=2 shiftwidth=2 expandtab
""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""
" tags navigation
""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""
" navigate between tags
nnoremap <leader>t :tnext<cr>
nnoremap <leader>T :tprevious<cr>
""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""
" status line
""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""
" show status line
set laststatus=2
" format satus line
set statusline=%F%m%r%h\ %w\ \ CWD:\ %r%{getcwd()}%h\ \ \ Line:\ %l\ \ Column:\ %c
" show what mode you're currently in
set showmode
" show what commands you're typing
set showcmd
" allow modelines
set modeline
" show current line and column position in file
""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""
" search related
""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""
" keep results highlighted after a search
set hlsearch
" highlight as we type
set incsearch
" ignore case when searching...
set ignorecase
" except if we type a capital letter
set smartcase
" For autocompletion ctrl-x ctrl-k
" ctrl-n / ctrl-p for word completion
set dictionary=/usr/share/dict/words
""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""
" tab, buffer and window configuration (TO DO)
""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""
" always open new windows on the right
set splitright
" tab style
highlight TabLineSel cterm=underline,bold ctermfg=White ctermbg=DarkGrey
highlight TabLine cterm=None
highlight TabLineFill ctermfg=Black
" close all the buffers
nnoremap <leader>ba :bufdo bd<cr>
" next buffer
nnoremap <tab> :bnext<cr>
" previous buffer
nnoremap <s-tab> :bprevious<cr>
" close buffer
nnoremap <leader>d :bd<cr>
" navigate between windows
noremap <c-h> <c-w>h
noremap <c-j> <c-w>j
noremap <c-k> <c-w>k
noremap <c-l> <c-w>l
" all new buffers go into a separate tab
" autocmd BufAdd,BufNewFile,BufRead * nested tab sball
"
""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""
" quickfix interaction
""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""
" search word under cursor and open a quickfix list
nnoremap <leader>s :execute "vimgrep /" . expand("<cword>") . "/j **" <Bar> cw<CR>
noremap <C-j> :cnext<CR>
noremap <C-k> :cprevious<CR>
""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""
" useful mapping
""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""
" delete previous word in insert mode
noremap! <c-bs> <c-w>
noremap! <c-h> <c-w>
" exit insert mode with jk
inoremap jk <esc>
" edit vimrc
nnoremap <leader>ev :vsplit $MYVIMRC<cr>
" reload vimrc
nnoremap <leader>sv :source $MYVIMRC<cr>
" single quote the current word
nnoremap <leader>' viw<esc>a'<esc>bi'<esc>lel
" double quote the current word
nnoremap <leader>" viw<esc>a"<esc>bi"<esc>lel
" current word lower case
nnoremap <leader>l evbu
" current word upper case
nnoremap <leader>u evbU
" current line lower case
nnoremap <leader>L ^V$u
" current line upper case
nnoremap <leader>U ^V$U
" shift tab to insert tab char
inoremap <s-tab> <c-v><tab>
" operate inside parantheses (dp delete function parameter)
onoremap p i(
" shift H to clear search highlighting
nnoremap <s-h> :let @/ = ""<cr>
" open an explorer
nnoremap <leader>e :Vexplore!<cr>
" map <Space> to /
nnoremap <space> /
" limit line-length to 80 columns by highlighting col 81 onward
nnoremap <leader>m :set colorcolumn=81<cr>
nnoremap <leader>M :set colorcolumn=0<cr>
" strip white space
function! StripWhitespace()
let save_cursor = getpos(".")
let old_query = getreg('/')
:%s/\s\+$//e
call setpos('.', save_cursor)
call setreg('/', old_query)
endfunction
nnoremap <leader>ss :call StripWhitespace()<cr>
" comment / uncomment selection
vnoremap <leader>c :s/^/#/<cr>:let @/ = ""<cr>
vnoremap <leader>C :s/^#//<cr>:let @/ = ""<cr>
" execute (run) current file
nnoremap <leader>r :w<cr>:!./%
" ctrl + j to break line
" nnoremap <nl> i<cr><esc>
" convert to human json
nnoremap <leader>j :%!python3 -m json.tool<cr>
" convert yaml to json
nnoremap <leader>jy :%!python3 -c 'import sys, yaml, json; y=yaml.load(sys.stdin.read(), Loader=yaml.FullLoader); print(json.dumps(y, indent=4))'<cr>
" toggle line number
nnoremap <leader>n :set number!<cr>
" :%s//g shortcut
nnoremap S :%s//g<left><left>
vnoremap S :s//g<left><left>
" french keyboard... ' is preferred over ` when it comes to marks
nnoremap ' `
let g:vimwiki_list = [{'path': '~/doc/',
\ 'syntax': 'markdown', 'ext': '.md'}]
let g:vimwiki_global_ext=0
" synchronize scrolling over mutliple windows
" nnoremap <leader>s :set scrollbind!<cr>
" copy full buffer into X11 clipboard (requires vimx)
nnoremap <leader>y mygg"+yG`y
" do not use arrows
nnoremap <up> <nop>
nnoremap <down> <nop>
nnoremap <left> <nop>
nnoremap <right> <nop>
" gf create the file under the cursor if it doesn't exist
map gf :e <cfile><cr>
" change working dir to current file path
map <leader>cd :cd %:h<cr>
" replace visual selection by content of unamed register
vmap r "_dP
" find out which commit modified the current line
nmap <silent><leader>g :call setbufvar(winbufnr(popup_atcursor(split(system("git log -n 1 -L " . line(".") . ",+1:" . expand("%:p")), "\n"), { "padding": [1,1,1,1], "pos": "botleft", "wrap": 0 })), "&filetype", "git")<cr>
" append to register a after adding a coma
noremap <silent> <leader>a :call setreg('A', ',')<CR>"AyW
" base64 decode visual selection
vnoremap <leader>bb <esc><c-o>:set paste<cr>gvc<c-r>=system('base64 --decode -w0', @")<cr><esc>
" base64 encode visual selection
vnoremap <leader>b <esc><c-o>:set paste<cr>gvc<c-r>=system('base64 -w0', @")<cr><esc>
" ctrl bacskspace to delete word
inoremap <c-bs> <c-w>
" plugins
" highligth next/previous occurence of pattern
let g:qs_highlight_on_keys = ['f', 'F', 't', 'T']
" highlight DiffText cterm=bold ctermfg=10 ctermbg=88 gui=none guifg=bg guibg=Red
if &diff
syntax off
endif
" auto commit vimwiki
function! AutoGitCommit()
execute '!cd ' . expand("<amatch>:p:h") . ' && git add "' . expand("%:t") . '" && git commit -m "Auto commit of ' . expand("<afile>:t") . '" && git push origin'
endfunction
autocmd! BufWritePost ~/doc/* call AutoGitCommit()
xnoremap "+y y:call system("wl-copy", @")<cr>
" make ctrl-j/k works in popup
inoremap <expr> <C-j> pumvisible() ? "\<C-n>" : "\<C-j>"
inoremap <expr> <C-k> pumvisible() ? "\<C-p>" : "\<C-k>"
" source local settings
source ~/.vimrc_local