From 6ea45e425be52b92006e97e2caf315036542856d Mon Sep 17 00:00:00 2001 From: Syndamia Date: Fri, 24 Feb 2023 22:39:05 +0200 Subject: [.vimrc] Huge overhaul, separating contents into different files --- .vim/miniplugins/code_terminal.vim | 79 ++++++++++++++++++++++++++++++++++ .vim/miniplugins/my_statusline.vim | 81 +++++++++++++++++++++++++++++++++++ .vim/miniplugins/spell_check_mode.vim | 33 ++++++++++++++ 3 files changed, 193 insertions(+) create mode 100644 .vim/miniplugins/code_terminal.vim create mode 100644 .vim/miniplugins/my_statusline.vim create mode 100644 .vim/miniplugins/spell_check_mode.vim (limited to '.vim/miniplugins') diff --git a/.vim/miniplugins/code_terminal.vim b/.vim/miniplugins/code_terminal.vim new file mode 100644 index 0000000..86ed1e6 --- /dev/null +++ b/.vim/miniplugins/code_terminal.vim @@ -0,0 +1,79 @@ +" 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", +\ '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" +\ } + +noremap :call CodeTerminal(g:codebuildsingle) +noremap :call CodeTerminal(g:codebuildproject) +inoremap :call CodeTerminal(g:codebuildsingle) +inoremap :call CodeTerminal(g:codebuildproject) +" We assume that the last accessed window is the one with the source code, otherwise it gets complicated +tnoremap :call CodeTerminal(g:codebuildsingle) +tnoremap :call CodeTerminal(g:codebuildproject) + + +let t:codetermbufnr = -1 +let t:codetermft = "" +let t:codetermhadenv = 0 +function! OpenCodeTerminal() + if !bufexists(t:codetermbufnr) + 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, "\") + " 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] . "\") + let t:codetermhadenv = 1 + else + let t:codetermhadenv = 0 + endif + endif +endfunction + +function! CodeTerminal(builddict) + call OpenCodeTerminal() + + if has_key(a:builddict, &filetype) + let buildcomm = a:builddict[&filetype] . "\" + 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 + echo "[CodeTerminal] No value in build dictionary!" + endif +endfunction diff --git a/.vim/miniplugins/my_statusline.vim b/.vim/miniplugins/my_statusline.vim new file mode 100644 index 0000000..92b9f10 --- /dev/null +++ b/.vim/miniplugins/my_statusline.vim @@ -0,0 +1,81 @@ +" Needed settings +set laststatus=2 +set timeoutlen=1000 ttimeoutlen=10 +set noshowmode + +" call hlset([#{name: 'StatusLine', ctermfg: '252', ctermbg: '239'}]) + +" Logic + +let leftcap = '' +let rightcap = '' +let leftmcap = '' +let rightmcap = '' + +set statusline= +" 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 modestring = '' + +hi SLMode ctermfg=1 ctermbg=0 +hi SLModeC ctermfg=1 ctermbg=0 + + +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 + +set statusline+=%{SLModeSetter()}%#SLModeC#%{leftcap}%#SLMode#%{modestring}%#SLModeC#%{rightcap} +" \______leftcap______/\________mode_______/\______rightcap_____/ + +" Filename + +set statusline+=%#StatusLine#\ %f\ %{rightmcap} + +" File stat + +function! SLReadonly() + return (&ft !~? 'vimfiler' && &readonly) ? ' ' : '' +endfunction + +function! SLModified() + return (&ft =~ 'vimfiler') ? '' : (&modified ? '' : (&modifiable ? '' : '')) +endfunction + +set statusline+=\ %{SLReadonly()}%{SLModified()}\ + +" Middle separator +set statusline+=%= + +" Filetype +set statusline+=%{leftmcap}\ %{WebDevIconsGetFileTypeSymbol()}\ %{&ft}\ + +" Line and column count +hi SLRowCol ctermfg=238 ctermbg=244 +hi SLRowColC ctermfg=244 ctermbg=239 +set statusline+=%#SLRowColC#%{leftcap}%#SLRowCol#%l:%c%#SLRowColC#%{rightcap} diff --git a/.vim/miniplugins/spell_check_mode.vim b/.vim/miniplugins/spell_check_mode.vim new file mode 100644 index 0000000..cfdd46a --- /dev/null +++ b/.vim/miniplugins/spell_check_mode.vim @@ -0,0 +1,33 @@ +" When you press F6 it will toggle a "spell check mode", +" spell is activated and the colour scheme is changed +nmap :call SpellCheckModeToggle() + +function! SpellCheckModeToggle() + if g:colors_name == 'gruvbox' + set spell + colorscheme darkblue + else + set nospell + colorscheme gruvbox + endif +endfunction + +" Scrolling (shows history) in terminal (except in lazygit) +" Scroll up to activate it, and press a to deactivate it +" Slightly modified version of: https://github.com/vim/vim/issues/2490#issuecomment-393973253 +tmap :call EnterNormalMode() + +function! ExitNormalMode() + unmap + call feedkeys("a") +endfunction + +function! EnterNormalMode() + if @% == '!lazygit' + tunmap + elseif &buftype == 'terminal' && mode('') == 't' + call feedkeys("\N") + call feedkeys("\") + map :call ExitNormalMode() + endif +endfunction -- cgit v1.2.3