| ... | ... |
@@ -1,6 +1,7 @@ |
| 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 |
|
| 4 | 5 |
" v0.4 - 2019-11-20: Backup, undo and swap added |
| 5 | 6 |
" v0.3 - 2019-07-07: Vundle installation detection |
| 6 | 7 |
" v0.2 - 2015-02-19: Vundle added |
| ... | ... |
@@ -73,10 +74,7 @@ let mapleader = "," |
| 73 | 74 |
let g:mapleader = "," |
| 74 | 75 |
|
| 75 | 76 |
" Fast saving |
| 76 |
-"nmap <leader>w :w!<cr> |
|
| 77 |
- |
|
| 78 |
-" Set 256 colors |
|
| 79 |
-set t_Co=256 |
|
| 77 |
+nmap <leader>w :w!<cr> |
|
| 80 | 78 |
|
| 81 | 79 |
|
| 82 | 80 |
"========" |
| ... | ... |
@@ -97,6 +95,8 @@ if isdirectory(expand("~/.vim/bundle/Vundle.vim"))
|
| 97 | 95 |
Plugin 'gmarik/Vundle.vim' |
| 98 | 96 |
|
| 99 | 97 |
Plugin 'scrooloose/nerdtree' |
| 98 |
+ Plugin 'chrisbra/Recover.vim' |
|
| 99 |
+ Plugin 'tpope/vim-commentary' |
|
| 100 | 100 |
" All of your Plugins must be added before the following line |
| 101 | 101 |
call vundle#end() " required |
| 102 | 102 |
filetype plugin indent on " and turn it back on! |
| ... | ... |
@@ -117,7 +117,6 @@ else |
| 117 | 117 |
endif |
| 118 | 118 |
|
| 119 | 119 |
|
| 120 |
- |
|
| 121 | 120 |
""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""" |
| 122 | 121 |
" => VIM user interface |
| 123 | 122 |
""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""" |
| ... | ... |
@@ -183,13 +182,7 @@ syntax enable |
| 183 | 182 |
colorscheme desert |
| 184 | 183 |
set background=dark |
| 185 | 184 |
|
| 186 |
-" Set extra options when running in GUI mode |
|
| 187 |
-if has("gui_running")
|
|
| 188 |
- set guioptions-=T |
|
| 189 |
- set guioptions+=e |
|
| 190 |
- set t_Co=256 |
|
| 191 |
- set guitablabel=%M\ %t |
|
| 192 |
-endif |
|
| 185 |
+set t_Co=256 |
|
| 193 | 186 |
|
| 194 | 187 |
" Set utf8 as standard encoding and en_US as the standard language |
| 195 | 188 |
set encoding=utf8 |
| ... | ... |
@@ -201,10 +194,41 @@ set ffs=unix,dos,mac |
| 201 | 194 |
""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""" |
| 202 | 195 |
" => Files, backups and undo |
| 203 | 196 |
""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""" |
| 197 |
+" Backup |
|
| 198 |
+let backupdir=$HOME . "/.vim/.backup//" |
|
| 199 |
+if !isdirectory(backupdir) |
|
| 200 |
+ call mkdir(backupdir, "p", 0700) |
|
| 201 |
+endif |
|
| 202 |
+let &backupdir=backupdir |
|
| 204 | 203 |
|
| 205 |
-set undodir=~/.vim/.undo// |
|
| 206 |
-set backupdir=~/.vim/.backup// |
|
| 207 |
-set directory=~/.vim/.swp// |
|
| 204 |
+" Undo |
|
| 205 |
+let dir=$HOME . "/.vim/.undo//" |
|
| 206 |
+let &undodir=dir |
|
| 207 |
+if !isdirectory(dir) |
|
| 208 |
+ call mkdir(dir, "p", 0700) |
|
| 209 |
+endif |
|
| 210 |
+set undofile " Save undos after file closes |
|
| 211 |
+set undolevels=1000 " How many undos |
|
| 212 |
+set undoreload=10000 " Number of lines to save for undo |
|
| 213 |
+ |
|
| 214 |
+" Swap |
|
| 215 |
+let dir=$HOME . "/.vim/.swp//" |
|
| 216 |
+let &directory=dir |
|
| 217 |
+if !isdirectory(dir) |
|
| 218 |
+ call mkdir(dir, "p", 0700) |
|
| 219 |
+endif |
|
| 220 |
+ |
|
| 221 |
+" Specific set if running sudo |
|
| 222 |
+let output = system("test $EUID -eq 0")
|
|
| 223 |
+if v:shell_error == 0 |
|
| 224 |
+ set nobackup |
|
| 225 |
+ set noundofile |
|
| 226 |
+ set noswapfile |
|
| 227 |
+endif |
|
| 228 |
+ |
|
| 229 |
+" Clean variables |
|
| 230 |
+unlet dir |
|
| 231 |
+unlet output |
|
| 208 | 232 |
|
| 209 | 233 |
|
| 210 | 234 |
""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""" |
| ... | ... |
@@ -315,12 +339,13 @@ nmap <M-k> mz:m-2<cr>`z |
| 315 | 339 |
vmap <M-j> :m'>+<cr>`<my`>mzgv`yo`z |
| 316 | 340 |
vmap <M-k> :m'<-2<cr>`>my`<mzgv`yo`z |
| 317 | 341 |
|
| 318 |
-if has("mac") || has("macunix")
|
|
| 319 |
- nmap <D-j> <M-j> |
|
| 320 |
- nmap <D-k> <M-k> |
|
| 321 |
- vmap <D-j> <M-j> |
|
| 322 |
- vmap <D-k> <M-k> |
|
| 323 |
-endif |
|
| 342 |
+" Duplicate lines using Ctrl+D |
|
| 343 |
+vmap <C-d> :'<,'>t'><cr>'[O<Esc> |
|
| 344 |
+nmap <C-d> yyp |
|
| 345 |
+ |
|
| 346 |
+" 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>
|
|
| 324 | 349 |
|
| 325 | 350 |
" Delete trailing white space on save, useful for Python and CoffeeScript ;) |
| 326 | 351 |
func! DeleteTrailingWS() |
| ... | ... |
@@ -377,7 +402,6 @@ map <leader>sa zg |
| 377 | 402 |
map <leader>s? z= |
| 378 | 403 |
|
| 379 | 404 |
|
| 380 |
- |
|
| 381 | 405 |
""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""" |
| 382 | 406 |
" => Misc |
| 383 | 407 |
""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""" |
| ... | ... |
@@ -393,12 +417,11 @@ map <leader>pp :setlocal paste!<cr> |
| 393 | 417 |
" Toggle hilight search on or or using F8 (source: http://www.developpez.net/forums/d8477/systemes/linux/applications/enlever-surbrillance-lors-recherche-vi/) |
| 394 | 418 |
nnoremap <f8> :set hlsearch!\|set hlsearch?<cr> |
| 395 | 419 |
|
| 396 |
-" visually select block of text to comment (modified from http://vim.wikia.com/wiki/Commenting_out_a_range_of_lines) |
|
| 397 |
-vmap <C-M> :s/^/#/<CR>:noh<CR> |
|
| 398 |
- |
|
| 399 |
-" uncomment visually selected text, with Ctrl-N,N(modified from http://vim.wikia.com/wiki/Commenting_out_a_range_of_lines) |
|
| 400 |
-vmap <C-N> :s/^#//<CR>:noh<CR> |
|
| 420 |
+" Clear search |
|
| 421 |
+map <leader>c :let @/=""<CR> |
|
| 401 | 422 |
|
| 423 |
+" (Un)comment block of text (depend on commentary-vim plugin) |
|
| 424 |
+vmap <C-M> gc |
|
| 402 | 425 |
|
| 403 | 426 |
|
| 404 | 427 |
""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""" |