summaryrefslogtreecommitdiff
path: root/.vim
diff options
context:
space:
mode:
Diffstat (limited to '.vim')
-rw-r--r--.vim/feat/code_terminal.vim98
-rw-r--r--.vim/feat/spell_check_mode.vim11
-rw-r--r--.vim/feat/statusline.vim116
-rw-r--r--.vim/feat/tabline.vim91
-rw-r--r--.vim/feat/term_scroll.vim19
5 files changed, 335 insertions, 0 deletions
diff --git a/.vim/feat/code_terminal.vim b/.vim/feat/code_terminal.vim
new file mode 100644
index 0000000..5db8797
--- /dev/null
+++ b/.vim/feat/code_terminal.vim
@@ -0,0 +1,98 @@
+" Program in which build actions are executed. If no value, build commands are executes as bash commands.
+" This is only really useful in languages with interpreters
+let g:codeenvs = {
+\ 'scheme' : 'racket',
+\ 'lisp' : 'rlwrap sbcl --noinform',
+\ }
+
+" The following two dictionaries support certain substitutions:
+" %F - location of current file (relative path)
+" %D - directory of current file (full path)
+
+" Building the current file only
+let g:codebuildsingle = {
+\ 'scheme' : '(enter! "%F")',
+\ 'cpp' : "g++ -g -pedantic '%F' && ./a.out",
+\ 'c' : "gcc -g '%F' && ./a.out",
+\ 'yacc' : 'bison -t -d %F',
+\ 'lex' : 'flex %F',
+\ 'haskell' : 'runhaskell "%F"',
+\ 'lisp' : '(load "%F")',
+\ }
+" Building all files in the directory (and subdirectories) of the current file
+let g:codebuildproject = {
+\ 'cpp' : "g++ -g -pedantic '%D/'**/*.cpp && ./a.out"
+\ }
+let g:codebuildinproject = 0
+
+ noremap <F3> :call CodeTerminal()<CR>
+ noremap <F4> :call RepeatLastCommand()<CR>
+inoremap <F3> <C-O>:call CodeTerminal()<CR>
+inoremap <F4> <C-O>:call RepeatLastCommand()<CR>
+" We assume that the last accessed window is the one with the source code, otherwise it gets complicated
+tnoremap <F3> <C-W><C-P>:call CodeTerminal()<CR><C-W><C-P>
+tnoremap <F4> <C-W><C-P>:call RepeatLastCommand()<CR><C-W><C-P>
+
+au TabNew * call CTCreateTabVars()
+
+function! CTCreateTabVars()
+ let t:codetermbufnr = -1
+ let t:codetermft = ""
+ let t:codetermhadenv = 0
+endfunction
+call CTCreateTabVars()
+
+function! OpenCodeTerminal()
+ if !bufexists(t:codetermbufnr)
+ topleft term
+ " Latest buffer is the terminal buffer we just opened
+ let t:codetermbufnr = bufnr("$")
+ " We go back to the file from which this was called
+ wincmd p
+ let t:codetermft = ""
+ let t:codetermhadenv = 0
+ endif
+
+ if &filetype != t:codetermft
+ if t:codetermhadenv
+ " This is kinda bad, since certain environments might not close with this only
+ call term_sendkeys(t:codetermbufnr, "\<C-D>")
+ " The sleep is kinda bad, but it fixes the next term_sendkeys not working properly
+ sleep 500m
+ endif
+
+ let t:codetermft = &filetype
+ if has_key(g:codeenvs, &filetype)
+ call term_sendkeys(t:codetermbufnr, g:codeenvs[&filetype] . "\<CR>")
+ let t:codetermhadenv = 1
+ else
+ let t:codetermhadenv = 0
+ endif
+ endif
+endfunction
+
+function! RepeatLastCommand()
+ call term_sendkeys(t:codetermbufnr, "\<Up>\<CR>")
+endfunction
+
+let s:ran = 0
+
+function! CodeTerminal()
+ call OpenCodeTerminal()
+
+ let builddict = (g:codebuildinproject == 1 ? g:codebuildproject : g:codebuildsingle)
+ if has_key(builddict, &filetype)
+ let buildcomm = builddict[&filetype] . "\<CR>"
+ let buildcomm = substitute(buildcomm, "%F", @%, "")
+ let buildcomm = substitute(buildcomm, "%D", expand('%:p:h'), "")
+ call term_sendkeys(t:codetermbufnr, buildcomm)
+ echo "[CodeTerminal] Sent build command!"
+ else
+ if s:ran == 0
+ let s:ran = 1
+ else
+ call RepeatLastCommand()
+ endif
+ echo "[CodeTerminal] No value in build dictionary!"
+ endif
+endfunction
diff --git a/.vim/feat/spell_check_mode.vim b/.vim/feat/spell_check_mode.vim
new file mode 100644
index 0000000..4b35add
--- /dev/null
+++ b/.vim/feat/spell_check_mode.vim
@@ -0,0 +1,11 @@
+nnoremap <F6> :call SpellCheckModeToggle()<CR>
+
+function! SpellCheckModeToggle()
+ if g:colors_name == 'gruvbox'
+ set spell
+ colorscheme darkblue
+ else
+ set nospell
+ colorscheme gruvbox
+ endif
+endfunction
diff --git a/.vim/feat/statusline.vim b/.vim/feat/statusline.vim
new file mode 100644
index 0000000..d568c87
--- /dev/null
+++ b/.vim/feat/statusline.vim
@@ -0,0 +1,116 @@
+" Needed settings
+set laststatus=2
+set timeoutlen=1000 ttimeoutlen=50
+set noshowmode
+
+" Logic
+
+let leftcap = ''
+let rightcap = ''
+let leftmcap = ''
+let rightmcap = ''
+
+let g:activesl = ''
+let g:inactivesl = ''
+
+" Colors {{{
+ autocmd ColorScheme * call SLCreateHighlightGroups()
+
+ function! SLCreateHighlightGroups()
+ hi SLMode ctermfg=1 ctermbg=0
+ hi SLModeC ctermfg=1 ctermbg=0
+
+ hi SLRowCol ctermfg=238 ctermbg=244
+ hi SLRowColC ctermfg=244 ctermbg=239
+ endfunction
+ call SLCreateHighlightGroups()
+" }}}
+
+" Mode {{{
+ " Values are, in order, for: normal (default), insert, replace, visual modes
+ " [ctermfg, ctermbg]
+ let s:modecolors = [
+ \ ['236', '117'],
+ \ ['236', '119'],
+ \ ['236', '203'],
+ \ ['236', '216'],
+ \]
+
+ let g:modestring = ''
+
+ function! SLModeSetter()
+ let cm = mode()
+ let ind = 0
+
+ if cm == 'i'
+ let ind = 1
+ elseif cm == 'R'
+ let ind = 2
+ let cm = 'r'
+ elseif cm == 'v'
+ let ind = 3
+ endif
+
+ call hlset([#{name: 'SLMode', ctermfg: s:modecolors[l:ind][0], ctermbg: s:modecolors[l:ind][1]}])
+ call hlset([#{name: 'SLModeC', ctermfg: s:modecolors[l:ind][1], ctermbg: '239'}])
+ let g:modestring = l:cm
+
+ return ''
+ endfunction
+
+ let g:activesl ..= '%#StatusLine#%{SLModeSetter()}%#SLModeC#%{leftcap}%#SLMode#%{modestring}%#SLModeC#%{rightcap}%<'
+ " \______leftcap______/\________mode_______/\______rightcap_____/
+ let g:inactivesl ..= '%#StatusLineNC# %<'
+" }}}
+
+" Filename {{{
+ let g:_filename = ' %f %{rightmcap}'
+ let g:activesl ..= '%#StatusLine#'..g:_filename
+ let g:inactivesl ..= '%#StatusLineNC#'..g:_filename
+" }}}
+
+" File stat {{{
+ function! SLReadonly()
+ return (&ft !~? 'vimfiler' && &readonly) ? ' ' : ''
+ endfunction
+
+ function! SLModified()
+ return (&ft =~ 'vimfiler') ? '' : (&modified ? '' : (&modifiable ? '' : ''))
+ endfunction
+
+ let g:_filestat = ' %{SLReadonly()}%{SLModified()} '
+ let g:activesl ..= g:_filestat
+ let g:inactivesl ..= g:_filestat
+" }}}
+
+" Middle separator {{{
+ let g:activesl ..= '%='
+ let g:inactivesl ..= '%='
+" }}}
+
+" Character under cursor {{{
+ let g:activesl ..= ' %b '
+ let g:inactivesl ..= ' %b '
+" }}}
+
+" Filetype {{{
+ let g:_filetype = '%{leftmcap} %{WebDevIconsGetFileTypeSymbol()} %{&ft} '
+ let g:activesl ..= g:_filetype
+ let g:inactivesl ..= g:_filetype
+" }}}
+
+" Line and column count {{{
+ let g:_linecol = '%#SLRowColC#%{leftcap}%#SLRowCol#%l:%c%#SLRowColC#%{rightcap}'
+ let g:activesl ..= g:_linecol
+ let g:inactivesl ..= g:_linecol
+" }}}
+
+" Statusline setting {{{
+ set statusline=
+
+ augroup SLModeAU
+ au!
+ au WinEnter,BufEnter * setlocal statusline=%!g:activesl
+ au WinLeave,BufLeave * setlocal statusline=%!g:inactivesl
+ augroup end
+" }}}
diff --git a/.vim/feat/tabline.vim b/.vim/feat/tabline.vim
new file mode 100644
index 0000000..bb6fe57
--- /dev/null
+++ b/.vim/feat/tabline.vim
@@ -0,0 +1,91 @@
+let tabcap = ''
+let tabmiddlecap = ''
+
+set tabline=%!TablineGenerator()
+
+" Tab data/helper functions {{{
+ function! TabFilename(n)
+ let buflist = tabpagebuflist(a:n)
+ let winnr = tabpagewinnr(a:n)
+ let _ = (expand('#'..buflist[winnr - 1]..':t') !=# '') ? expand('#'..buflist[winnr - 1]..':t') : '[No Name]'
+
+ " Limit the width of tabs, so they don't go out of the screen
+ let tabNameLengthMax = &columns/(((tabpagenr('$') > 0) ? tabpagenr('$') : 0) + 5)
+
+ return WebDevIconsGetFileTypeSymbol(_) .. ' ' .. _[0:tabNameLengthMax]
+ endfunction
+
+ function! TabReadonly(n)
+ let winnr = tabpagewinnr(a:n)
+ return gettabwinvar(a:n, winnr, '&readonly') ? ' ' : ''
+ endfunction
+
+ function! TabModified(n)
+ let winnr = tabpagewinnr(a:n)
+ return gettabwinvar(a:n, winnr, '&modified') ? ' ' : (gettabwinvar(a:n, winnr, '&modifiable') ? '' : ' ')
+ endfunction
+" }}}
+
+" Colors {{{
+ autocmd ColorScheme * call TLCreateHighlightGroups()
+
+ " Colorscheme clears highlights https://vi.stackexchange.com/a/3356
+ function! TLCreateHighlightGroups()
+ hi TLTab ctermfg=252 ctermbg=242
+ hi TLTabSel ctermfg=252 ctermbg=235
+ hi TLRest ctermfg=248 ctermbg=238
+
+ let s:hi_tltab = hlget('TLTab')[0]
+ let s:hi_tltabsel = hlget('TLTabSel')[0]
+ let s:hi_tlrest = hlget('TLRest')[0]
+ call hlset([#{name: 'TLTabSelLC', ctermfg: s:hi_tltab['ctermbg'], ctermbg: s:hi_tltabsel['ctermbg'] },
+ \ #{name: 'TLTabSelRC', ctermfg: s:hi_tltabsel['ctermbg'], ctermbg: s:hi_tltab['ctermbg'] },
+ \ #{name: 'TLTabSelRCF', ctermfg: s:hi_tltabsel['ctermbg'], ctermbg: s:hi_tlrest['ctermbg'] },
+ \ #{name: 'TLTabRCF', ctermfg: s:hi_tltab['ctermbg'], ctermbg: s:hi_tlrest['ctermbg'] }])
+ endfunction
+ call TLCreateHighlightGroups()
+" }}}
+
+function! TablineGenerator()
+ let s = ''
+
+ " For each tab i
+ for i in range(1, tabpagenr('$'))
+ " Sets the tab page number, so that mouse clicks work
+ let s ..= '%' .. i .. 'T'
+
+ let innerText = '%{TabFilename(' .. i .. ')}%{TabReadonly(' .. i .. ')}%{TabModified(' .. i .. ')} '
+
+ " If tab is the selected one
+ if i == tabpagenr()
+ " If tab isn't the left most
+ if i > 1
+ let s ..= '%#TLTabSelLC#%{tabcap}'
+ endif
+
+ let s ..= '%#TLTabSel# ' .. l:innerText
+
+ " If tab is the last one, right cap bg color has to be different
+ let s ..= (i == tabpagenr('$') ? '%#TLTabSelRCF#' : '%#TLTabSelRC#') .. '%{tabcap}'
+
+ else
+ let s ..= '%#TLTab#'
+ " If tab isn't to the right of selected and isn't the left most
+ if (i-1 != tabpagenr()) && (i > 1)
+ let s ..= '%{tabmiddlecap}'
+ endif
+
+ let s ..= ' ' .. l:innerText
+
+ " Last tab has to have a tabcap
+ if i == tabpagenr('$')
+ let s ..= '%#TLTabRCF#%{tabcap}'
+ endif
+ endif
+ endfor
+
+ " After last tab, fill with TLRest
+ let s ..= '%#TLRest#%T'
+
+ return s
+endfunction
diff --git a/.vim/feat/term_scroll.vim b/.vim/feat/term_scroll.vim
new file mode 100644
index 0000000..d01fe4c
--- /dev/null
+++ b/.vim/feat/term_scroll.vim
@@ -0,0 +1,19 @@
+" Scrolling (shows history) in terminal (except in lazygit)
+" Scroll up to activate it, and press right mouse button to deactivate it
+" Slightly modified version of: https://github.com/vim/vim/issues/2490#issuecomment-393973253
+tmap <silent> <ScrollWheelUp> <c-w>:call EnterNormalMode()<CR>
+
+function! ExitNormalMode()
+ unmap <buffer> <silent> <RightMouse>
+ call feedkeys("a")
+endfunction
+
+function! EnterNormalMode()
+ if @% == '!lazygit'
+ tunmap <buffer> <silent> <ScrollWheelUp>
+ elseif &buftype == 'terminal' && mode('') == 't'
+ call feedkeys("\<c-w>N")
+ call feedkeys("\<c-y>")
+ map <buffer> <silent> <RightMouse> :call ExitNormalMode()<CR>
+ endif
+endfunction