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
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
|
"===============================================================================
" Mappings/Keybindings/Commands
"===============================================================================
let mapleader = ";" " map leader to Semi colon
inoremap jk <Esc> " Use <jk> to escape
" Easier split navigations, just ctrl-j instead of ctrl-w then j
nnoremap <C-J> <C-W><C-J>
nnoremap <C-K> <C-W><C-K>
nnoremap <C-L> <C-W><C-L>
nnoremap <C-H> <C-W><C-H>
" Recent files (MRU)
nnoremap <leader>m :browse old<cr>
" Search files by name
nnoremap <leader>p :find **/**<left>
" browse files from same dir as current file
nnoremap <leader>e :e %:p:h<CR>
" Combine buffers list with buffer name
"nnoremap <Leader>b :buffers<CR>:buffer<Space>
" Jump to a buffer
nnoremap <leader>b :ls t<cr>:b
" Map buffer next, prev and delete to <leader+(n/p/d)>
map <leader>n :bn<cr>
map <leader>p :bp<cr>
map <leader>d :bd<cr>
"" Set alt + j/k to switch lines of texts or simply move them
":nnoremap <silent><A-k> :let save_a=@a<Cr><Up>"add"ap<Up>:let @a=save_a<Cr>
":nnoremap <silent><A-j> :let save_a=@a<Cr>"add"ap:let @a=save_a<Cr>
" Swap two pieces of text, use x to cut in visual mode, then use Ctrl-x in
" visual mode to select text to swap with
:vnoremap <C-X> <Esc>`.``gvP``P
" To resize in different steps, you can create maps that will adjust the window
" size differently. For example to increase the window size by a factor of 1.5
" and decrease the window size by 0.67, you can map this:
"nnoremap <silent> <Leader>+ :exe "resize " . (winheight(0) * 3/2)<CR>
"nnoremap <silent> <Leader>- :exe "resize " . (winheight(0) * 2/3)<CR>
nnoremap <Leader>+ :resize +5<CR>
nnoremap <Leader>- :resize -5<CR>
nnoremap <Leader>> :vertical resize +5<CR>
nnoremap <Leader>< :vertical resize -5<CR>
" Toggle set number
"nnoremap <leader>$ :NumbersToggle<CR>
"nnoremap <leader>% :NumbersOnOff<CR>
" Copy and Paste with <C-c> and <C-v>
"vmap <C-c> y:call system("xclip -i -selection clipboard", getreg("\""))<CR>:call system("xclip -i", getreg("\""))<CR>
"nmap <C-v> :call setreg("\"",system("xclip -o -selection clipboard"))<CR>p
nnoremap <expr> p (v:register == '"' && &clipboard =~ 'unnamed' ? '"*p' : '"' . v:register . 'p')
" Use command :Vb for Visual Block or <C-q> since <C-v> is used for Copy
command! Vb normal! <C-v>
" Map <w!!> to save/edit a root permission/read-only file, only works in
" traditional vim and not neovim
cmap w!! %!sudo tee > /dev/null
nnoremap <leader>x :silent !chmod +x %<CR>
"nnoremap <[-p> m`o<ESC>p``
" Paste on next line
"nnoremap <]-p> m`O<ESC>p``
"inoremap <C-CR> <C-R>"
"set keywordprg=:help
"runtime ftplugin/man.vim
"===============================================================================
" Settings
"===============================================================================
" enable syntax, plugins (for netrw) and indentation
syntax enable
"set shell=zsh
set termguicolors
set guicursor=
let &t_SI = "\e[6 q"
let &t_EI = "\e[2 q"
" Neovim requires xclip, check if normal vim has +clipboard by
" <:echo has('clipboard')> from within Vim (if the output is 1, good to
" go otherwise 0 then need a build that has it
" Next two commands make vim use X11 clipboard
set clipboard+=unnamedplus
let g:clipbrdDefaultReg = '+'
"let g:loaded_clipboard_provider = 1
" <:e %:h/filename> will create a new file named filename in the same
" directory as the currently open file, and write it.
set autochdir " or use this to use <:e> to create a file in current directory
set splitright " make vsplit put the new buffer on the right of the current buffer
set splitbelow " make split put the new buffer below the current buffer
" :Bclose script (delete a buffer without closing the window) sourced as a
" plugin in ~/.config/nvim/plugin/bclose.vim | keymap: <leader>bd
let bclose_multiple = 1
"set syntax
" Compute syntax highlighting from beginning of file. (By default, vim only
" looks 200 lines back, which can make it highlight code incorrectly in some
" long files.)
autocmd BufEnter * :syntax sync fromstart
" Don't syntax highlight markdown because it's often wrong
autocmd! FileType mkd setlocal syn=off
"set ttyfast
"set lazyredraw
set timeout timeoutlen=1000 ttimeoutlen=100 " fix slow O inserts
set scrolloff=8 sidescrolloff=8
set tabstop=4 softtabstop=4 shiftwidth=4 expandtab
set autoindent
set smartindent
" Also load indent files, to automatically do language-dependent indenting.
filetype plugin indent on
set exrc
set number
set hidden
set noerrorbells
set nowrap
set ignorecase
set smartcase
set noswapfile
set nobackup
set incsearch
set cursorline
set showmatch
set showcmd
set incsearch
set hlsearch
set laststatus=2
let g:python3_host_prog = '/usr/bin/python3'
"let g:loaded_python3_provider = 1
let g:sh_noisk=1
set modeline
set modelines=3 " modelines (comments that set vim options on a per-file basis)
set foldmethod=manual
set nofoldenable " turn folding off
" Insert only one space when joining lines that contain sentence-terminating
" punctuation like `.`.
set nojoinspaces
set autoread " if a file is changed outside of vim, automatically reload it without asking
set diffopt=vertical " diffs are shown side-by-side not above/below
set signcolumn=no " always show the sign column
set textwidth=80
" FILE BROWSING:
let g:netrw_banner=0 " disable annoying banner
let g:netrw_browse_split=4 " open in prior window
let g:netrw_altv=1 " open splits to the right
let g:netrw_liststyle=3 " tree view
let g:netrw_fastbrowse = 0
autocmd FileType netrw setl bufhidden=wipe
" Faster vimgrep/grep via ripgrep
if executable("rg")
set grepprg=rg\ --vimgrep\ --no-heading
set grepformat=%f:%l:%c:%m,%f:%l:%m
endif
"-------------------------------------------------------------------------------
"===============================================================================
" Plugins
"===============================================================================
" Auto-Install vim-plug
"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
" "autocmd VimEnter * PlugInstall | source $MYVIMRC
"endif
"
"" :so % :PlugInstall
"call plug#begin('~/.vim/autoload/plugged')
""Plug 'glepnir/dashboard-nvim'
"Plug 'christoomey/vim-tmux-navigator'
"Plug 'preservim/vimux'
"Plug 'myusuf3/numbers.vim'
"Plug 'romainl/vim-cool'
""Plug 'ervandew/supertab'
""Plug 'neoclide/coc.nvim', {'branch': 'release'}
"Plug 'sheerun/vim-polyglot'
"Plug 'vim-airline/vim-airline'
"Plug 'ryanoasis/vim-devicons'
"Plug 'rbgrouleff/bclose.vim'
""Plug 'ms-jpq/chadtree', {'branch': 'chad', 'do': 'python3 -m chadtree deps'}
"Plug 'lambdalisue/fern.vim'
"Plug 'junegunn/fzf', { 'do': { -> fzf#install() } }
"Plug 'junegunn/fzf.vim'
"Plug 'airblade/vim-rooter'
""Plug 'SirVer/ultisnips'
""Plug 'honza/vim-snippets'
"Plug 'airblade/vim-gitgutter'
"Plug 'tpope/vim-eunuch'
"Plug 'tpope/vim-fugitive'
"Plug 'tpope/vim-surround'
"Plug 'tpope/vim-obsession'
"Plug 'tpope/vim-unimpaired'
"Plug 'scrooloose/syntastic'
"Plug 'w0rp/ale'
"Plug 'davidhalter/jedi-vim'
""Plug 'valloric/youcompleteme' " vim needs to be compiled with python/ compiled with install.py in plugin directory
"Plug 'Lenovsky/nuake'
"Plug 'voldikss/vim-floaterm'
"Plug 'gruvbox-community/gruvbox'
"Plug 'srcery-colors/srcery-vim'
"Plug 'tomasr/molokai'
"Plug 'ayu-theme/ayu-vim'
"Plug 'sjl/badwolf'
"Plug 'joshdick/onedark.vim'
"call plug#end()
"source $HOME/.vim/plug-config/coc.vim
"-------------------------------------------------------------------------------
"===============================================================================
" Plugin Settings
"===============================================================================
"" Fugitive statusline
""---------------------------------------
""set statusline=%{fugitive#statusline()}%F%m%r%h%w\ (%{&ff}){%Y}\ [%l,%v][%p%%]
""-------------------------------------------------------------------------------
""" Show the buffer number in the status line.
""set statusline=%02n:%<%f\ %h%m%r%=%-14.(%l,%c%V%)\ %P
""set statusline=%{fugitive#statusline()}02n:%<%f\ %h%m%r%=%-14.(%l,%c%V%)\ %P
""-------------------------------------------------------------------------------
"
"" Airline
""---------------------------------------
"let g:airline#extensions#tabline#enabled = 1
"let g:airline#extensions#tabline#show_buffers = 1
"let g:airline_powerline_fonts = 1
"let g:airline#extensions#tabline#buffer_nr_show = 1
"let g:airline_theme='onedark'
"
""-------------------------------------------------------------------------------
"
"" Float Term
""---------------------------------------
"" Configuration example
"let g:floaterm_keymap_new = '<Leader>t'
"let g:floaterm_keymap_prev = '<Leader>tn'
"let g:floaterm_keymap_next = '<Leader>tp'
"let g:floaterm_keymap_toggle = '<Leader>tt'
"
""-------------------------------------------------------------------------------
"
"" Nuake
""---------------------------------------
"" Toggle Nuake terminal panel
"nnoremap <A-t> :Nuake<CR>
"inoremap <A-t> <C-\><C-n>:Nuake<CR>
"tnoremap <A-t> <C-\><C-n>:Nuake<CR>
"let g:nuake_per_tab = 1 " Enable the Nuake instance per tab page. (default 1)
"let g:close_if_last_standing = 1 " Close the editor if the Nuake window is the last one. (default 1)
"let g:nuake_position = 'right'
""let g:nuake_size = 0.2
""-------------------------------------------------------------------------------
"
"" Vimux
""---------------------------------------
"" Prompt for a command to run
"map <Leader>vp :VimuxPromptCommand<CR>
"" Run last command executed by VimuxRunCommand
"map <Leader>vl :VimuxRunLastCommand<CR>
"" Inspect runner pane
"map <Leader>vi :VimuxInspectRunner<CR>
"" Zoom the tmux runner pane
"map<leader>vz :VimuxZoomRunner<CR>
""-------------------------------------------------------------------------------
"
"" Snippets
""---------------------------------------
"" Snippets — code snippets allow you to quickly write some boilerplate code
"" that is often repetitive. To add code snippets support, you will have to add
"" UltiSnips.
"let g:UltiSnipsExpandTrigger = "<c-tab>"
""let g:UltiSnipsJumpForwardTrigger = "<tab>"
""let g:UltiSnipsJumpBackwardTrigger = "<s-tab>"
""-------------------------------------------------------------------------------
"
"" Youcompleteme
""---------------------------------------
""let g:ycm_global_ycm_extra_conf = '~/.config/nvim/autoload/plugged/youcompleteme/.ycm_extra_conf.py'
"" ---> compatibility with another plugin (ultisnips) <---
""let g:ycm_key_list_select_completion = [ '<C-n>', '<Down>' ]
""let g:ycm_key_list_previous_completion = [ '<C-p>', '<Up>' ]
""let g:SuperTabDefaultCompletionType = '<C-n>'
"" ---> disable preview window <---
""set completeopt-=preview
"" ---> navigating to the definition of a a symbol <---
""map <leader>g :YcmCompleter GoToDefinitionElseDeclaration<CR>
""-------------------------------------------------------------------------------
"
"
""===============================================================================
"" File Manager & FZF
""===============================================================================
"
"" CHADTree Filemanager/project drawer (NerdTree killer)
""---------------------------------------
""" to toggle CHADTree run command :CHADopen or use hotkey <leader>v :
""nnoremap <leader>f <cmd>CHADopen<cr>
"""nnoremap <leader>v <cmd>CHADopen<cr> " Default Behaviour
""nnoremap <A-f> <cmd>CHADopen<cr>
""" :CHADhelp to view documentation
""" Add a hotkey to clear quickfix list:
"""nnoremap <leader>qk <cmd>call setqflist([])<cr>
""let g:chadtree_settings = { 'view.width': 25 }
""-------------------------------------------------------------------------------
"
"" FZF fuzzy finder
""---------------------------------------
"" Enable per-command history.
"" CTRL-N and CTRL-P will be automatically bound to next-history and
"" previous-history instead of down and up. If you don't like the change,
"" explicitly bind the keys to down and up in your $FZF_DEFAULT_OPTS.
"let g:fzf_history_dir = '~/.local/share/fzf-history'
"map <leader>z :FZF<CR>
"map <leader>a :Files<CR>
"map <leader>l :Lines<CR>
"map <leader>L :BLines<CR>
"map <leader>B :Buffers<CR>
"map <leader>h :History:<CR>
"nnoremap <leader>g :Rg<CR>
""nnoremap <leader>t :Tags<CR>
"nnoremap <leader>m :Marks<CR>
"" This is the default extra key bindings
"let g:fzf_action = {
" \ 'ctrl-t': 'tab split',
" \ 'ctrl-x': 'split',
" \ 'ctrl-y': 'vsplit' }
"let g:fzf_tags_command = 'ctags -R'
"" Border color
"let g:fzf_layout = {'up':'~90%', 'window': { 'width': 0.8, 'height': 0.8,'yoffset':0.5,'xoffset': 0.5, 'highlight': 'Todo', 'border': 'sharp' } }
"let $FZF_DEFAULT_OPTS = '--layout=reverse --info=inline'
"let $FZF_DEFAULT_COMMAND="rg --files --hidden"
"" Customize fzf colors to match your color scheme
"let g:fzf_colors =
" \ { 'fg': ['fg', 'Normal'],
" \ 'bg': ['bg', 'Normal'],
" \ 'hl': ['fg', 'Comment'],
" \ 'fg+': ['fg', 'CursorLine', 'CursorColumn', 'Normal'],
" \ 'bg+': ['bg', 'CursorLine', 'CursorColumn'],
" \ 'hl+': ['fg', 'Statement'],
" \ 'info': ['fg', 'PreProc'],
" \ 'border': ['fg', 'Ignore'],
" \ 'prompt': ['fg', 'Conditional'],
" \ 'pointer': ['fg', 'Exception'],
" \ 'marker': ['fg', 'Keyword'],
" \ 'spinner': ['fg', 'Label'],
" \ 'header': ['fg', 'Comment'] }
"" Get Files
"command! -bang -nargs=? -complete=dir Files
" \ call fzf#vim#files(<q-args>, fzf#vim#with_preview({'options': ['--layout=reverse', '--info=inline']}), <bang>0)
"" Get text in files with Rg
"command! -bang -nargs=* Rg
" \ call fzf#vim#grep(
" \ 'rg --column --line-number --no-heading --color=always --smart-case '.shellescape(<q-args>), 1,
" \ fzf#vim#with_preview(), <bang>0)
"" Ripgrep advanced
"function! RipgrepFzf(query, fullscreen)
" let command_fmt = 'rg --column --line-number --no-heading --color=always --smart-case %s || true'
" let initial_command = printf(command_fmt, shellescape(a:query))
" let reload_command = printf(command_fmt, '{q}')
" let spec = {'options': ['--phony', '--query', a:query, '--bind', 'change:reload:'.reload_command]}
" call fzf#vim#grep(initial_command, 1, fzf#vim#with_preview(spec), a:fullscreen)
"endfunction
"command! -nargs=* -bang RG call RipgrepFzf(<q-args>, <bang>0)
"" Git grep
"command! -bang -nargs=* GGrep
" \ call fzf#vim#grep(
" \ 'git grep --line-number '.shellescape(<q-args>), 0,
" \ fzf#vim#with_preview({'dir': systemlist('git rev-parse --show-toplevel')[0]}), <bang>0)
"command! -bang FM call fzf#run(fzf#wrap({'source': 'cat ~/.fzf-marks | sed "s/.*: \(.*\)$/\1/" | sed "s#~#${HOME}#"', 'sink': 'lcd'}, <bang>0))
"
"-------------------------------------------------------------------------------
"===============================================================================
" Colorscheme
"===============================================================================
"colorscheme gruvbox
"colorscheme srcery
"colorscheme molokai
"colorscheme ayu
"let ayucolor="light" " for light version of theme
"let ayucolor="mirage" " for mirage version of theme
"let ayucolor="dark" " for dark version of theme
"colorscheme badwolf
"let g:badwolf_darkgutter = 0 " Make the gutters darker than the background. Default 0.
"let g:badwolf_tabline = 1 " 1 is default, 0 is lighter and 2 or 3 is darker a tabline
" Try to use a colorscheme plugin
" but fallback to a default one
colorscheme desert
highlight Normal guibg=NONE
"set background=dark
"
"-------------------------------------------------------------------------------
"===============================================================================
" Functions/Scripts
"===============================================================================
" Enable mouse scrollback
"---------------------------------------
set mouse=a
tnoremap <Esc> <C-\><C-n>
tnoremap <c-b> <c-\><c-n>
function! ClearTerminal()
set scrollback=1
let &g:scrollback=1
echo &scrollback
call feedkeys("\i")
call feedkeys("clear\<CR>")
call feedkeys("\<C-\>\<C-n>")
call feedkeys("\i")
sleep 100m
let &scrollback=s:scroll_value
endfunction
"-------------------------------------------------------------------------------
" :Rename {newname}
"---------------------------------------
function! RenameFile()
let old_name = expand('%')
let new_name = input('New file name: ', expand('%'), 'file')
if new_name != '' && new_name != old_name
exec ':saveas ' . new_name
exec ':silent !rm ' . old_name
redraw!
endif
endfunction
map <leader>r :call RenameFile()<cr>
"-------------------------------------------------------------------------------
" Return to the same line when we reopen a file
"---------------------------------------
augroup line_return
au!
au BufReadPost *
\ if line("'\"") > 0 && line("'\"") <= line("$") |
\ execute 'normal! g`"zvzz' |
\ endif
augroup END
"-------------------------------------------------------------------------------
"
" Function to update tmux status
function! UpdateTmuxStatus()
if &filetype == "man"
return
endif
let mode = mode()
let mode_name = ''
if mode ==# 'n'
let mode_name = "-- NORMAL --"
elseif mode ==# 'i' || mode ==# 'ic'
let mode_name = "-- INSERT --"
else
let mode_name = "-- NORMAL --"
endif
let file = $HOME . "/.vi-mode"
call writefile([mode_name], file)
if exists('*nvim_running')
let VI_MODE = "" " Clear VI_MODE to show vim mode
silent execute "!tmux refresh-client -S"
endif
silent execute "!tmux refresh-client -S"
endfunction
" Set up autocommands for tmux status update
if !empty($TMUX) && system('command -v tmux >/dev/null 2>&1') == 0
augroup TmuxStatus
autocmd!
autocmd InsertLeave,InsertEnter,VimEnter,BufEnter,ModeChanged,WinEnter,WinLeave * call UpdateTmuxStatus()
augroup END
endif
"-------------------------------------------------------------------------------
"===============================================================================
" Statusline Configuration
"===============================================================================
" Load statusline script
if filereadable(expand("~/.vim/autoload/statusline.vim"))
source ~/.vim/autoload/statusline.vim
endif
" Call the statusline activation function
call autoload#statusline#ActivateStatusline()
|