Browse code

vimrc - v1.1 - See Versions section for details

Fred authored on16/08/2020 23:30:31
Showing1 changed files
... ...
@@ -1,8 +1,9 @@
1 1
 """""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""
2 2
 " Versions
3 3
 "
4
-" v1.0 - 2020-03-15: Backup, undo and swap improved / text duplication mapping / search and replace mapping / plugins added / code cleaned
5
-" v0.4 - 2019-11-20: Backup, undo and swap added
4
+" v1.1 - 2020-08-16: status line improved / comment symbol for R filetype added / comment shortcut improved / replacement shortcut improved / tabedit shortcut improved
5
+" v1.0 - 2020-03-15: backup, undo and swap improved / text duplication mapping / search and replace mapping / plugins added / code cleaned
6
+" v0.4 - 2019-11-20: backup, undo and swap added
6 7
 " v0.3 - 2019-07-07: Vundle installation detection
7 8
 " v0.2 - 2015-02-19: Vundle added
8 9
 " v0.1 - 2014-10-19: variable for screen integration set / commands for (un)commenting block added / no backup behavior
... ...
@@ -172,6 +173,9 @@ set novisualbell
172 173
 set t_vb=
173 174
 set tm=500
174 175
 
176
+" Set time out between keystroke
177
+set timeoutlen=300
178
+
175 179
 
176 180
 """""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""
177 181
 " => Colors and Fonts
... ...
@@ -252,6 +256,9 @@ set ai "Auto indent
252 256
 set si "Smart indent
253 257
 set wrap "Wrap lines
254 258
 
259
+" Comment symbol for filetype
260
+autocmd FileType r setlocal commentstring=#\ %s
261
+
255 262
 
256 263
 """"""""""""""""""""""""""""""
257 264
 " => Visual mode related
... ...
@@ -296,7 +303,7 @@ map <leader>tm :tabmove
296 303
 
297 304
 " Opens a new tab with the current buffer's path
298 305
 " Super useful when editing files in the same directory
299
-map <leader>te :tabedit <c-r>=expand("%:p:h")<cr>/
306
+map <leader>te :tabedit <c-r>=fnameescape(expand("%:p:h"))<cr>/
300 307
 
301 308
 " Switch CWD to the directory of the open buffer
302 309
 map <leader>cd :cd %:p:h<cr>:pwd<cr>
... ...
@@ -323,6 +330,14 @@ set viminfo^=%
323 330
 " Always show the status line
324 331
 set laststatus=2
325 332
 
333
+" Change the status line based on mode
334
+au InsertEnter * call InsertStatuslineColor(v:insertmode)
335
+au InsertChange * call InsertStatuslineColor(v:insertmode)
336
+au InsertLeave * hi statusline term=reverse ctermfg=15 ctermbg=0
337
+
338
+" Default the statusline when entering Vim
339
+hi statusline term=reverse ctermfg=15 ctermbg=0
340
+
326 341
 " Format the status line
327 342
 set statusline=\ %{HasPaste()}%F%m%r%h\ %w\ \ CWD:\ %r%{getcwd()}%h\ \ \ Line:\ %l\ \ \ Col.:\ %c
328 343
 
... ...
@@ -344,8 +359,11 @@ vmap <C-d> :'<,'>t'><cr>'[O<Esc>
344 359
 nmap <C-d> yyp
345 360
 
346 361
 " Search and replace
347
-nnoremap <leader>h y:<C-U>let replacement = input('Enter replacement string: ') <bar> %s//\=replacement/gc<CR>
348
-xnoremap <leader>h y:<C-U>let replacement = input('Enter replacement string: ') <bar> %s/<C-R>"/\=replacement/gc<CR>
362
+nnoremap <leader>h y:<C-U>let replacement = input('Enter replacement string: ') <bar> s//\=replacement/gc<CR>
363
+xnoremap <leader>h y:<C-U>let replacement = input('Enter replacement string: ') <bar> s/<C-R>"/\=replacement/gc<CR>
364
+
365
+nnoremap <leader>hh y:<C-U>let replacement = input('Enter replacement string: ') <bar> %s//\=replacement/gc<CR>
366
+xnoremap <leader>hh y:<C-U>let replacement = input('Enter replacement string: ') <bar> %s/<C-R>"/\=replacement/gc<CR>
349 367
 
350 368
 " Delete trailing white space on save, useful for Python and CoffeeScript ;)
351 369
 func! DeleteTrailingWS()
... ...
@@ -420,8 +438,9 @@ nnoremap <f8> :set hlsearch!\|set hlsearch?<cr>
420 438
 " Clear search
421 439
 map <leader>c :let @/=""<CR>
422 440
 
423
-" (Un)comment block of text (depend on commentary-vim plugin)
424
-vmap <C-M> gc
441
+" (Un)comment block of text (depends on commentary-vim plugin) (works with C-/)
442
+vmap <C-_> gc
443
+nmap <C-_> gcc
425 444
 
426 445
 
427 446
 """""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""
... ...
@@ -483,3 +502,14 @@ function! <SID>BufcloseCloseIt()
483 502
      execute("bdelete! ".l:currentBufNum)
484 503
    endif
485 504
 endfunction
505
+
506
+" Status line color on mode
507
+function! InsertStatuslineColor(mode)
508
+  if a:mode == 'i'
509
+    hi statusline term=reverse ctermfg=166 ctermbg=0
510
+  elseif a:mode == 'r'
511
+    hi statusline term=reverse ctermfg=160 ctermbg=0
512
+  else
513
+    hi statusline term=reverse ctermfg=5 ctermbg=0
514
+  endif
515
+endfunction