From 0e6163dff702417c329c6794b9bd4cf43914b85e Mon Sep 17 00:00:00 2001 From: ray Date: Thu, 19 Mar 2020 16:17:53 +0000 Subject: [PATCH] incorporate settings into init.vim and modularise --- init.auto-window.vim | 27 +++ init.fold-text.vim | 44 ++++ init.settings.vim | 529 ------------------------------------------- init.vim | 497 ++++++++++++++++++++++++++++++++++++++-- 4 files changed, 543 insertions(+), 554 deletions(-) create mode 100644 init.auto-window.vim create mode 100644 init.fold-text.vim delete mode 100644 init.settings.vim diff --git a/init.auto-window.vim b/init.auto-window.vim new file mode 100644 index 0000000..1d7c3a2 --- /dev/null +++ b/init.auto-window.vim @@ -0,0 +1,27 @@ +"auto_window_settings {{{ +function! WinEnterColorColumn() abort"{{{ + if &buftype != '' + setlocal colorcolumn=0 + elseif exists('b:colorcolumn_restore') + execute 'setlocal colorcolumn=' . b:colorcolumn_restore + endif +endfunction + +"}}} +function! WinLeaveColorColumn() abort"{{{ + let b:colorcolumn_restore = &colorcolumn + setlocal colorcolumn=0 +endfunction + +"}}} +augroup auto_window_settings "{{{ + autocmd! + autocmd WinEnter * call WinEnterColorColumn() + autocmd WinEnter * set cursorline | set cursorcolumn + " autocmd WinLeave * setlocal colorcolumn=0 + autocmd WinLeave * call WinLeaveColorColumn() + autocmd WinLeave * set nocursorline | set nocursorcolumn +augroup END +"}}} augroup auto_window_settings +" }}} auto_window_settings + diff --git a/init.fold-text.vim b/init.fold-text.vim new file mode 100644 index 0000000..a80b900 --- /dev/null +++ b/init.fold-text.vim @@ -0,0 +1,44 @@ +function! MyFoldText() + if !exists('g:foldtext_column') + let g:foldtext_column = 80 " column to right align foldtext with + endif + + if !exists('b:foldtext_column') + let b:foldtext_column = g:foldtext_column " column to right align foldtext with + endif + + if !exists('g:foldtext_maxcolumn') + let g:foldtext_maxcolumn = 120 + endif + + let l:linecount = v:foldend - v:foldstart + " don't display foldmarker braces + " put one of the braces in brackets so vim doesn't treat + " it as an actual fold marker + let l:line = substitute(getline(v:foldstart), '"\?{\({\){', '', '') + " don't display vim comment quotation marks + " TODO other comment markers + let l:line = substitute(l:line, "\^\"\\s\\?", '', '') + + " let l:postfix = l:linecount . ' ' . substitute(v:folddashes, '-', '•', 'g') + let l:postfix = l:linecount . ' ' . substitute(v:folddashes, '-', '↓', 'g') + while strchars(l:postfix) < 7 + let l:postfix = ' ' . l:postfix + endwhile + " let l:postfix = ' ↓ ' . l:postfix + + let l:len_line = len(l:line) + let l:len_postfix = strchars(l:postfix) + + if l:len_line + l:len_postfix <= b:foldtext_column + let l:padding = ' '[l:len_line + l:len_postfix + 0:b:foldtext_column - 1] + let l:foldtext = l:line . l:padding . l:postfix + else + let l:sniptext = ' ⋯' + let l:foldtext = l:line[:b:foldtext_column - 1 - strchars(l:sniptext) - l:len_postfix] . l:sniptext . l:postfix + endif + + return l:foldtext +endfunction + +set foldtext=MyFoldText() diff --git a/init.settings.vim b/init.settings.vim deleted file mode 100644 index 3372d9c..0000000 --- a/init.settings.vim +++ /dev/null @@ -1,529 +0,0 @@ -" ● - -" #functions {{{ - -function! MyFoldText() "{{{ - if !exists('g:foldtext_column') - let g:foldtext_column = 80 " column to right align foldtext with - endif - - if !exists('b:foldtext_column') - let b:foldtext_column = g:foldtext_column " column to right align foldtext with - endif - - if !exists('g:foldtext_maxcolumn') - let g:foldtext_maxcolumn = 120 - endif - - let l:linecount = v:foldend - v:foldstart - " don't display foldmarker braces - " put one of the braces in brackets so vim doesn't treat - " it as an actual fold marker - let l:line = substitute(getline(v:foldstart), '"\?{\({\){', '', '') - " don't display vim comment quotation marks - " TODO other comment markers - let l:line = substitute(l:line, "\^\"\\s\\?", '', '') - - " let l:postfix = l:linecount . ' ' . substitute(v:folddashes, '-', '•', 'g') - let l:postfix = l:linecount . ' ' . substitute(v:folddashes, '-', '↓', 'g') - while strchars(l:postfix) < 7 - let l:postfix = ' ' . l:postfix - endwhile - " let l:postfix = ' ↓ ' . l:postfix - - let l:len_line = len(l:line) - let l:len_postfix = strchars(l:postfix) - - if l:len_line + l:len_postfix <= b:foldtext_column - let l:padding = ' '[l:len_line + l:len_postfix + 0:b:foldtext_column - 1] - let l:foldtext = l:line . l:padding . l:postfix - else - let l:sniptext = ' ⋯' - let l:foldtext = l:line[:b:foldtext_column - 1 - strchars(l:sniptext) - l:len_postfix] . l:sniptext . l:postfix - endif - - return l:foldtext -endfunction - -"}}} -function! SynStack()"{{{ - if !exists('*synstack') - return - endif - echo map(synstack(line('.'), col('.')), 'synIDattr(v:val,"name")') '-> ' . synIDattr(synIDtrans(synID(line('.'),col('.'),1)), 'name' ) -endfunc -nmap pp :call SynStack() -"}}} - -function! s:RunShellCommand(cmdline) abort"{{{ -" Shell command -" http://vim.wikia.com/wiki/VimTip1599 - - let l:expanded_cmdline = a:cmdline - for l:part in split(a:cmdline, ' ') - if l:part[0] =~ '\v[%#<]' - let l:expanded_part = fnameescape(expand(l:part)) - let l:expanded_cmdline = substitute(l:expanded_cmdline, l:part, l:expanded_part, '') - endif - endfor - - if g:shell_scratch_buffer_nr > -1 - let l:win_nr = bufwinnr(g:shell_scratch_buffer_nr) - if l:win_nr < 0 - execute 'bdelete' g:shell_scratch_buffer_nr - top new - let g:shell_scratch_buffer_nr = bufnr('%') - else - execute l:win_nr. ' wincmd w' - setlocal modifiable - %delete _ - endif - else - top new - let g:shell_scratch_buffer_nr = bufnr('%') - endif - - setlocal buftype=nofile bufhidden=wipe nobuflisted noswapfile nowrap - nnoremap q :bdelete - augroup ResetShellBufferNr - autocmd! * - autocmd BufUnload let g:shell_scratch_buffer_nr = -1 - augroup END - - " call setline(1, 'You entered: ' . a:cmdline) - " call setline(2, 'Expanded Form: ' .l:expanded_cmdline) - " call setline(3,substitute(getline(2),'.','=','g')) - execute '$read !'. l:expanded_cmdline - 1 - - setlocal nomodifiable - if !exists('b:shell_line_count') - let b:shell_line_count = line('$') - if b:shell_line_count > 25 - let b:shell_line_count = 20 - endif - execute 'resize' b:shell_line_count + 1 - endif - - wincmd p -endfunction - -command! -complete=shellcmd -nargs=+ Shell call s:RunShellCommand() -let g:shell_scratch_buffer_nr = -1 - -"}}} -function! SaveAndExecute(ex_command) abort "{{{ -" https://stackoverflow.com/a/40195855 -" ex_command: command to run to execute file - " SOURCE [reusable window]: https://github.com/fatih/vim-go/blob/master/autoload/go/ui.vim - - " save and reload current file - silent execute 'update | edit' - - " get file path of current file - let s:current_buffer_file_path = expand('%') - - let s:output_buffer_name = 'Output' - let s:output_buffer_filetype = 'output' - - " reuse existing buffer window if it exists otherwise create a new one - if !exists('c:buf_nr') || !bufexists(s:buf_nr) || bufwinnr(s:buf_nr) == -1 - silent execute 'top new ' . s:output_buffer_name - let s:buf_nr = bufnr('%') - elseif bufwinnr(s:buf_nr) != bufwinnr('%') - silent execute bufwinnr(s:buf_nr) . 'wincmd w' - endif - - silent execute 'setlocal filetype=' . s:output_buffer_filetype - setlocal bufhidden=delete - setlocal buftype=nofile - setlocal noswapfile - setlocal nobuflisted - setlocal winfixheight - setlocal cursorline " make it easy to distinguish - " setlocal nonumber - " setlocal norelativenumber - setlocal showbreak="" - - nnoremap q :bdelete!'.zz - - " clear the buffer - setlocal noreadonly - " setlocal modifiable - %delete _ - - " add the console output - silent execute '.!'. a:ex_command . ' ' . shellescape(s:current_buffer_file_path, 1) - - " resize window to content length - " Note: This is annoying because if you print a lot of lines then your code buffer is forced to a height of one line every time you run this function. - " However without this line the buffer starts off as a default size and if you resize the buffer then it keeps that custom size after repeated runs of this function. - " But if you close the output buffer then it returns to using the default size when its recreated - "execute 'resize' . line('$') - - " make the buffer non modifiable - setlocal readonly - " setlocal nomodifiable -endfunction - -"}}} -function! JsIncludeExpr(file)"{{{ - " substitute(substitute(v:fname,'^[\\~@]\/','./',''),'^[\\~@]','./node_modules/','') - return substitute(substitute(a:file,'^[\\~@]\/','./',''),'^[\\~@]','./node_modules/','') - -endfunction - -"}}} -function! Redir(cmd) "{{{ - for win in range(1, winnr('$')) - if getwinvar(win, 'scratch') - execute win . 'windo close' - endif - endfor - if a:cmd =~ '^!' - let output = system(matchstr(a:cmd, '^!\zs.*')) - else - redir => output - execute a:cmd - redir END - endif - vnew - let w:scratch = 1 - setlocal buftype=nofile bufhidden=wipe nobuflisted noswapfile - call setline(1, split(output, "\n")) -endfunction - -command! -nargs=1 -complete=command Redir silent call Redir() -" Usage: -" :Redir hi ............. show the full output of command ':hi' in a scratch window -" :Redir !ls -al ........ show the full output of command ':!ls -al' in a scratch window -"}}} -"----------------------------------------------------------------------------}}} -"#commands{{{ -" TrimWhitespace{{{ -command! -range=% TrimWhitespace let b:wv = winsaveview() | - \ keeppattern ,s/\s\+$// | - \ call winrestview(b:wv) -"}}} -" Scratch, ScratchVertical{{{ -command! Scratch new | setlocal buftype=nofile | setlocal bufhidden=hide | setlocal noswapfile -command! ScratchVertical vnew | setlocal buftype=nofile | setlocal bufhidden=hide | setlocal noswapfile -"}}} -"}}} -" #settings {{{ - -scriptencoding utf-8 -set ttyfast - -set dictionary+=/usr/share/dict/brit-a-z.txt,/usr/share/dict/britcaps.txt -set thesaurus+=/usr/share/dict/mthesaur.txt - -" disable background color erase -" https://sunaku.github.io/vim-256color-bce.html -set t_ut= - -syntax on -set fillchars=stl:\ ,stlnc:\ ,vert:\|,fold:\ - -set guioptions-=mTrLb -set guioptions+=c - -if exists('+termguicolors') - let &t_8f = "\[38;2;%lu;%lu;%lum" - let &t_8b = "\[48;2;%lu;%lu;%lum" - set termguicolors -endif - -colorscheme monotonous-dark - -set updatetime=100 -set timeoutlen=500 -set lazyredraw - -" the ;/home/ray tells vim to stop searching at /home/ray -set tags+=./.tags,.tags,./tags-py,.tags-py;/home/ray/ - -" persisitent undo file -set undofile -set undodir=~/.vim/.vimtmp -set backupdir=~/.vim/.vimtmp -set directory=~/.vim/.vimtmp - -set viewoptions-=options - -set ignorecase -set smartcase - -set wildmenu -set wildmode=longest:full,full -set wildignore+=/node_modules/,dist/ - -" Use ag over grep -if executable('ag') - set grepprg=ag\ --nogroup\ --nocolor\ --ignore\ node_modules -endif - -set hidden - -set hlsearch - -set completeopt=menuone - -set nospell -set spelllang=en_gb - -set diffopt+=vertical - -set rnu nu - -set tabstop=8 -set softtabstop=2 -set shiftwidth=2 -set shiftround -set expandtab -set autoindent - -set textwidth=120 -set formatoptions=cq -set wrapmargin=0 - -set cursorline - -set foldcolumn=2 -if has('patch-7-4-2201') - set signcolumn=yes -endif -set colorcolumn=80,120 - -set iskeyword+=- -set scrolloff=10 -set showcmd -set incsearch - -set laststatus=2 -set shortmess=aoOT -set cmdheight=3 - -set foldmethod=indent -set foldnestmax=3 -set foldlevelstart=2 - -set showmode - -set autoindent -set breakindent -set showbreak=\ \ ↳\ - -set mouse=a - -set listchars=eol:¬,tab:>-,trail:~,extends:>,precedes:<,space:· - -set foldtext=MyFoldText() -set conceallevel=0 -"----------------------------------------------------------------------------}}} -" #mappings {{{ -let g:mapleader = ' ' -" search and replace {{{ -nnoremap rr :%s/\<=expand('')\>//g -"}}} -" #syntax -nnoremap s :syntax on -nnoremap S :syntax off -" miscallaneous {{{ -nnoremap l :colorscheme monotonous-light -nnoremap d :colorscheme monotonous-dark -nnoremap 0 ^ -nnoremap cs :let @/="" -nnoremap : :setlocal number: -nnoremap rc :so $MYVIMRC -nnoremap nh (&hls && v:hlsearch ? ':nohls' : ':set hls')."\n" -nnoremap sl :set invlist -nnoremap aa A -nnoremap a2 A -nnoremap ab AB -nnoremap co :!clear; -nnoremap ;; A; -nnoremap ;j jA; -nnoremap ,, A, -nnoremap ,j jA, -" Focus on current fold, close the rest -nnoremap zz zMzvzt -" replace current word with last yanked/deleted text -nnoremap rw "_diwP -" replace current word with last yanked text -nnoremap ry diw"0P -" quick grep of visual selection -vnoremap gr y:grep! -R " . -" open quickfix window of TODOs -" FIXME i want fixme!!! -nnoremap td :grep -RE '(TODO\\|FIXME)' .:botright cwindow:echo len(getqflist()) 'TODOs' -" devdocs mapping -nnoremap dd :DD -" write and delete current buffer -nnoremap bx :w\|bd -" sync highlighting from start -nnoremap ss :syntax sync fromstart - -"}}} -" terminal{{{ -if has('terminal') - tnoremap -endif -"}}} -" windows{{{ - nnoremap ww :resize:vertical resize - -" }}} -" git mappings {{{ -" also see vim-fugitive plugin section -nnoremap gD :!clear; echo 'git diff'; git diff -nnoremap ga :!clear; git add %; git status -nnoremap gA :!clear; git add .; git status -nnoremap gg :!clear; git add %; git commit -m '' -nnoremap gP :!clear; echo 'git push'; git push - -"}}} -" movement/navigation{{{ -nnoremap j :resize -5 -nnoremap k :resize +5 -nnoremap l :vertical resize +5 -nnoremap h :vertical resize -5 -" alias for :tjump -nnoremap tj g -" alias for :ptjump -nnoremap tp g} - -"}}} -" location list and quickfix mappings {{{ -nnoremap lo :botright lwindow -nnoremap :lprevzv -nnoremap :lnextzv -nnoremap lc :lclose -nnoremap lh :lhistory -nnoremap lp :lolder -nnoremap ln :lnewer - -nnoremap qo :botright cwindow -nnoremap :cprevzv -nnoremap :cnextzv -nnoremap qc :cclose -nnoremap qh :chistory -nnoremap qp :colder -nnoremap qn :cnewer - -"}}} -" insert mode mappings {{{ -inoremap jkrg :reg -inoremap :w :w -inoremap [:w :w -inoremap {:w :w -" Chain multiple path completions with / key. Selects the first suggestion if -" no current selection. Use ctrl-y to finish completion as normal. -inoremap / pumvisible() - \ ? len(v:completed_item) ? '' : '' - \ : '/' - -"}}} -" working_with_underscores{{{ -nnoremap w f_l -nnoremap b hT_ -nnoremap e lt_ -onoremap u t_ -onoremap U f_ -"}}} -"----------------------------------------------------------------------------}}} -" #abbreviations {{{ - -" spelling"{{{ -iabbrev adn and -iabbrev waht what -iabbrev tehn then -iabbrev functin function -iabbrev positin position - -"}}} -" css{{{ -iabbrev pabs; position: absolute; -iabbrev pfix; position: fixed; -iabbrev prel; position: relative; -iabbrev fdr; flex-direction: row; -iabbrev fdc; flex-direction: column; -iabbrev jcc; justify-content: center; -iabbrev aic; align-items: center; -iabbrev t0; top: 0; -iabbrev b0; bottom: 0; -iabbrev l0; left: 0; -iabbrev r0; right: 0; - -iabbrev ct'' content-type: ''; - -"}}} - -"----------------------------------------------------------------------------}}} -" #autocommands {{{ - -" persistent folds {{{ - augroup AutoSaveFolds - autocmd! - autocmd BufWrite ?* mkview - autocmd BufRead ?* silent! loadview - augroup END - -" }}} -" Show trailing whitepace and spaces before a tab: {{{ - augroup whitespaceerrors - autocmd! - autocmd Syntax * syn match ExtraWhitespace /\s\+$\| \+\ze\t/ containedin=ALL - augroup END - -" }}} -" automatically reload if color scheme file written {{{ -" augroup coloreload -" autocmd! -" autocmd BufWritePost customred256.vim so $MYVIMRC -" augroup end -" - -" }}} -" line numbering {{{ -" if exists('##CmdlineEnter') -" augroup linenumbering -" autocmd! -" autocmd CmdlineEnter * :redraw | :set number -" autocmd CmdlineLeave * :set nonumber -" augroup END - " endif - -" }}} -" Automatically reload .vimrc if changed {{{ - augroup myvimrc - autocmd! - autocmd BufWritePost .vimrc,_vimrc,vimrc,.gvimrc,_gvimrc,gvimrc so $MYVIMRC | if has('gui_running') | so $MYGVIMRC | endif - augroup END - -" }}} -" Open quickfix window{{{ - augroup QuickFixAutoload - autocmd! - autocmd QuickFixCmdPost [^l]* nested botright cwindow - autocmd QuickFixCmdPost l* nested botright lwindow - augroup END - -" }}} - -"----------------------------------------------------------------------------}}} -" #statusline {{{ - set statusline=\ - set statusline+=[%n]\ \ - set statusline+=%l\ of\ %L\ - set statusline+=(%p%%) - set statusline+=%= - set statusline+=%y\ - set statusline+=%r\ %m\ %F - set statusline+=\ - -"----------------------------------------------------------------------------}}} - - - -" vim: set foldmethod=marker: diff --git a/init.vim b/init.vim index 0eb2c5e..e986977 100644 --- a/init.vim +++ b/init.vim @@ -4,38 +4,485 @@ let g:ruby_host_prog = '~/.gem/ruby/2.6.0/bin/neovim-ruby-host' source ~/.config/nvim/init.plugins.vim source ~/.config/nvim/init.tabline.vim -source ~/.config/nvim/init.settings.vim +source ~/.config/nvim/init.auto-window.vim +source ~/.config/nvim/init.fold-text.vim -set statusline+=\ nvim\ +" TODO - maybe separate some of these into own files too +" #functions {{{ +function! SynStack()"{{{ + if !exists('*synstack') + return + endif + echo map(synstack(line('.'), col('.')), 'synIDattr(v:val,"name")') '-> ' . synIDattr(synIDtrans(synID(line('.'),col('.'),1)), 'name' ) +endfunc +nmap pp :call SynStack() +"}}} -" set foldtext=foldtext() +function! s:RunShellCommand(cmdline) abort"{{{ +" Shell command +" http://vim.wikia.com/wiki/VimTip1599 + + let l:expanded_cmdline = a:cmdline + for l:part in split(a:cmdline, ' ') + if l:part[0] =~ '\v[%#<]' + let l:expanded_part = fnameescape(expand(l:part)) + let l:expanded_cmdline = substitute(l:expanded_cmdline, l:part, l:expanded_part, '') + endif + endfor + + if g:shell_scratch_buffer_nr > -1 + let l:win_nr = bufwinnr(g:shell_scratch_buffer_nr) + if l:win_nr < 0 + execute 'bdelete' g:shell_scratch_buffer_nr + top new + let g:shell_scratch_buffer_nr = bufnr('%') + else + execute l:win_nr. ' wincmd w' + setlocal modifiable + %delete _ + endif + else + top new + let g:shell_scratch_buffer_nr = bufnr('%') + endif + + setlocal buftype=nofile bufhidden=wipe nobuflisted noswapfile nowrap + nnoremap q :bdelete + augroup ResetShellBufferNr + autocmd! * + autocmd BufUnload let g:shell_scratch_buffer_nr = -1 + augroup END + + " call setline(1, 'You entered: ' . a:cmdline) + " call setline(2, 'Expanded Form: ' .l:expanded_cmdline) + " call setline(3,substitute(getline(2),'.','=','g')) + execute '$read !'. l:expanded_cmdline + 1 + + setlocal nomodifiable + if !exists('b:shell_line_count') + let b:shell_line_count = line('$') + if b:shell_line_count > 25 + let b:shell_line_count = 20 + endif + execute 'resize' b:shell_line_count + 1 + endif + + wincmd p +endfunction + +command! -complete=shellcmd -nargs=+ Shell call s:RunShellCommand() +let g:shell_scratch_buffer_nr = -1 + +"}}} +function! SaveAndExecute(ex_command) abort "{{{ +" https://stackoverflow.com/a/40195855 +" ex_command: command to run to execute file + " SOURCE [reusable window]: https://github.com/fatih/vim-go/blob/master/autoload/go/ui.vim + + " save and reload current file + silent execute 'update | edit' + + " get file path of current file + let s:current_buffer_file_path = expand('%') + + let s:output_buffer_name = 'Output' + let s:output_buffer_filetype = 'output' + + " reuse existing buffer window if it exists otherwise create a new one + if !exists('c:buf_nr') || !bufexists(s:buf_nr) || bufwinnr(s:buf_nr) == -1 + silent execute 'top new ' . s:output_buffer_name + let s:buf_nr = bufnr('%') + elseif bufwinnr(s:buf_nr) != bufwinnr('%') + silent execute bufwinnr(s:buf_nr) . 'wincmd w' + endif + + silent execute 'setlocal filetype=' . s:output_buffer_filetype + setlocal bufhidden=delete + setlocal buftype=nofile + setlocal noswapfile + setlocal nobuflisted + setlocal winfixheight + setlocal cursorline " make it easy to distinguish + " setlocal nonumber + " setlocal norelativenumber + setlocal showbreak="" + + nnoremap q :bdelete!'.zz + + " clear the buffer + setlocal noreadonly + " setlocal modifiable + %delete _ + + " add the console output + silent execute '.!'. a:ex_command . ' ' . shellescape(s:current_buffer_file_path, 1) + + " resize window to content length + " Note: This is annoying because if you print a lot of lines then your code buffer is forced to a height of one line every time you run this function. + " However without this line the buffer starts off as a default size and if you resize the buffer then it keeps that custom size after repeated runs of this function. + " But if you close the output buffer then it returns to using the default size when its recreated + "execute 'resize' . line('$') + + " make the buffer non modifiable + setlocal readonly + " setlocal nomodifiable +endfunction + +"}}} +function! JsIncludeExpr(file)"{{{ + " substitute(substitute(v:fname,'^[\\~@]\/','./',''),'^[\\~@]','./node_modules/','') + return substitute(substitute(a:file,'^[\\~@]\/','./',''),'^[\\~@]','./node_modules/','') + +endfunction + +"}}} +function! Redir(cmd) "{{{ + for win in range(1, winnr('$')) + if getwinvar(win, 'scratch') + execute win . 'windo close' + endif + endfor + if a:cmd =~ '^!' + let output = system(matchstr(a:cmd, '^!\zs.*')) + else + redir => output + execute a:cmd + redir END + endif + vnew + let w:scratch = 1 + setlocal buftype=nofile bufhidden=wipe nobuflisted noswapfile + call setline(1, split(output, "\n")) +endfunction + +command! -nargs=1 -complete=command Redir silent call Redir() +" Usage: +" :Redir hi ............. show the full output of command ':hi' in a scratch window +" :Redir !ls -al ........ show the full output of command ':!ls -al' in a scratch window +"}}} +"----------------------------------------------------------------------------}}} +"#commands{{{ +" TrimWhitespace{{{ +command! -range=% TrimWhitespace let b:wv = winsaveview() | + \ keeppattern ,s/\s\+$// | + \ call winrestview(b:wv) +"}}} +" Scratch, ScratchVertical{{{ +command! Scratch new | setlocal buftype=nofile | setlocal bufhidden=hide | setlocal noswapfile +command! ScratchVertical vnew | setlocal buftype=nofile | setlocal bufhidden=hide | setlocal noswapfile +"}}} +"}}} +" #settings {{{ + +scriptencoding utf-8 +set ttyfast + +set dictionary+=/usr/share/dict/brit-a-z.txt,/usr/share/dict/britcaps.txt +set thesaurus+=/usr/share/dict/mthesaur.txt + +" disable background color erase +" https://sunaku.github.io/vim-256color-bce.html +set t_ut= + +syntax on +set fillchars=stl:\ ,stlnc:\ ,vert:\|,fold:\ + +set guioptions-=mTrLb +set guioptions+=c + +if exists('+termguicolors') + let &t_8f = "\[38;2;%lu;%lu;%lum" + let &t_8b = "\[48;2;%lu;%lu;%lum" + set termguicolors +endif + +colorscheme monotonous-dark + +set updatetime=100 +set timeoutlen=500 +set lazyredraw + +" the ;/home/ray tells vim to stop searching at /home/ray +set tags+=./.tags,.tags,./tags-py,.tags-py;/home/ray/ + +" persisitent undo file +set undofile +set undodir=~/.vim/.vimtmp +set backupdir=~/.vim/.vimtmp +set directory=~/.vim/.vimtmp + +set viewoptions-=options + +set ignorecase +set smartcase + +set wildmenu +set wildmode=longest:full,full +set wildignore+=/node_modules/,dist/ + +" Use ag over grep +if executable('ag') + set grepprg=ag\ --nogroup\ --nocolor\ --ignore\ node_modules +endif + +set hidden + +set hlsearch + +set completeopt=menuone + +set nospell +set spelllang=en_gb + +set diffopt+=vertical + +set rnu nu + +set tabstop=8 +set softtabstop=2 +set shiftwidth=2 +set shiftround +set expandtab +set autoindent + +set textwidth=120 +set formatoptions=cq +set wrapmargin=0 + +set cursorline + +set foldcolumn=2 +if has('patch-7-4-2201') + set signcolumn=yes +endif +set colorcolumn=80,120 + +set iskeyword+=- +set scrolloff=10 +set showcmd +set incsearch + +set laststatus=2 +set shortmess=aoOT +set cmdheight=3 + +set foldmethod=indent +set foldnestmax=3 +set foldlevelstart=2 + +set showmode + +set autoindent +set breakindent +set showbreak=\ \ ↳\ + +set mouse=a + +set listchars=eol:¬,tab:>-,trail:~,extends:>,precedes:<,space:· set fillchars=stl:\ ,stlnc:\ ,vert:┃,fold:\ -"auto_window_settings {{{ -function! WinEnterColorColumn() abort"{{{ - if &buftype != '' - setlocal colorcolumn=0 - elseif exists('b:colorcolumn_restore') - execute 'setlocal colorcolumn=' . b:colorcolumn_restore - endif -endfunction +set statusline=\ +set statusline+=[%n]\ \ +set statusline+=%l\ of\ %L\ +set statusline+=(%p%%) +set statusline+=%= +set statusline+=%y\ +set statusline+=%r\ %m\ %F +set statusline+=\ + +set conceallevel=0 +"----------------------------------------------------------------------------}}} +" #mappings {{{ +let g:mapleader = ' ' +" search and replace {{{ +nnoremap rr :%s/\<=expand('')\>//g +"}}} +" #syntax +nnoremap s :syntax on +nnoremap S :syntax off +" miscallaneous {{{ +nnoremap l :colorscheme monotonous-light +nnoremap d :colorscheme monotonous-dark +nnoremap 0 ^ +nnoremap cs :let @/="" +nnoremap : :setlocal number: +nnoremap rc :so $MYVIMRC +nnoremap nh (&hls && v:hlsearch ? ':nohls' : ':set hls')."\n" +nnoremap sl :set invlist +nnoremap aa A +nnoremap a2 A +nnoremap ab AB +nnoremap co :!clear; +nnoremap ;; A; +nnoremap ;j jA; +nnoremap ,, A, +nnoremap ,j jA, +" Focus on current fold, close the rest +nnoremap zz zMzvzt +" replace current word with last yanked/deleted text +nnoremap rw "_diwP +" replace current word with last yanked text +nnoremap ry diw"0P +" quick grep of visual selection +vnoremap gr y:grep! -R " . +" open quickfix window of TODOs +" FIXME i want fixme!!! +nnoremap td :grep -RE '(TODO\\|FIXME)' .:botright cwindow:echo len(getqflist()) 'TODOs' +" devdocs mapping +nnoremap dd :DD +" write and delete current buffer +nnoremap bx :w\|bd +" sync highlighting from start +nnoremap ss :syntax sync fromstart "}}} -function! WinLeaveColorColumn() abort"{{{ - let b:colorcolumn_restore = &colorcolumn - setlocal colorcolumn=0 -endfunction +" terminal{{{ +if has('terminal') + tnoremap +endif +"}}} +" windows{{{ + nnoremap ww :resize:vertical resize + +" }}} +" git mappings {{{ +" also see vim-fugitive plugin section +nnoremap gD :!clear; echo 'git diff'; git diff +nnoremap ga :!clear; git add %; git status +nnoremap gA :!clear; git add .; git status +nnoremap gg :!clear; git add %; git commit -m '' +nnoremap gP :!clear; echo 'git push'; git push "}}} -augroup auto_window_settings "{{{ - autocmd! - autocmd WinEnter * call WinEnterColorColumn() - autocmd WinEnter * set cursorline | set cursorcolumn - " autocmd WinLeave * setlocal colorcolumn=0 - autocmd WinLeave * call WinLeaveColorColumn() - autocmd WinLeave * set nocursorline | set nocursorcolumn -augroup END -"}}} augroup auto_window_settings -" }}} auto_window_settings +" movement/navigation{{{ +nnoremap j :resize -5 +nnoremap k :resize +5 +nnoremap l :vertical resize +5 +nnoremap h :vertical resize -5 +" alias for :tjump +nnoremap tj g +" alias for :ptjump +nnoremap tp g} + +"}}} +" location list and quickfix mappings {{{ +nnoremap lo :botright lwindow +nnoremap :lprevzv +nnoremap :lnextzv +nnoremap lc :lclose +nnoremap lh :lhistory +nnoremap lp :lolder +nnoremap ln :lnewer + +nnoremap qo :botright cwindow +nnoremap :cprevzv +nnoremap :cnextzv +nnoremap qc :cclose +nnoremap qh :chistory +nnoremap qp :colder +nnoremap qn :cnewer + +"}}} +" insert mode mappings {{{ +inoremap jkrg :reg +inoremap :w :w +inoremap [:w :w +inoremap {:w :w +" Chain multiple path completions with / key. Selects the first suggestion if +" no current selection. Use ctrl-y to finish completion as normal. +inoremap / pumvisible() + \ ? len(v:completed_item) ? '' : '' + \ : '/' + +"}}} +" working_with_underscores{{{ +nnoremap w f_l +nnoremap b hT_ +nnoremap e lt_ +onoremap u t_ +onoremap U f_ +"}}} +"----------------------------------------------------------------------------}}} +" #abbreviations {{{ + +" spelling"{{{ +iabbrev adn and +iabbrev waht what +iabbrev tehn then +iabbrev functin function +iabbrev positin position + +"}}} +" css{{{ +iabbrev pabs; position: absolute; +iabbrev pfix; position: fixed; +iabbrev prel; position: relative; +iabbrev fdr; flex-direction: row; +iabbrev fdc; flex-direction: column; +iabbrev jcc; justify-content: center; +iabbrev aic; align-items: center; +iabbrev t0; top: 0; +iabbrev b0; bottom: 0; +iabbrev l0; left: 0; +iabbrev r0; right: 0; + +iabbrev ct'' content-type: ''; + +"}}} + +"----------------------------------------------------------------------------}}} +" #autocommands {{{ + +" persistent folds {{{ + augroup AutoSaveFolds + autocmd! + autocmd BufWrite ?* mkview + autocmd BufRead ?* silent! loadview + augroup END + +" }}} +" Show trailing whitepace and spaces before a tab: {{{ + augroup whitespaceerrors + autocmd! + autocmd Syntax * syn match ExtraWhitespace /\s\+$\| \+\ze\t/ containedin=ALL + augroup END + +" }}} +" automatically reload if color scheme file written {{{ +" augroup coloreload +" autocmd! +" autocmd BufWritePost customred256.vim so $MYVIMRC +" augroup end +" + +" }}} +" line numbering {{{ +" if exists('##CmdlineEnter') +" augroup linenumbering +" autocmd! +" autocmd CmdlineEnter * :redraw | :set number +" autocmd CmdlineLeave * :set nonumber +" augroup END + " endif + +" }}} +" Automatically reload .vimrc if changed {{{ + augroup myvimrc + autocmd! + autocmd BufWritePost .vimrc,_vimrc,vimrc,.gvimrc,_gvimrc,gvimrc so $MYVIMRC | if has('gui_running') | so $MYGVIMRC | endif + augroup END + +" }}} +" Open quickfix window{{{ + augroup QuickFixAutoload + autocmd! + autocmd QuickFixCmdPost [^l]* nested botright cwindow + autocmd QuickFixCmdPost l* nested botright lwindow + augroup END + +" }}} + +"----------------------------------------------------------------------------}}} " vim: set foldmethod=marker: