472 lines
12 KiB
VimL
472 lines
12 KiB
VimL
" set ruby program to global one. Need to investigate if this will cause
|
||
" problems if I ever use ruby virtual environments or RVM or similar.
|
||
let g:ruby_host_prog = '~/.gem/ruby/2.7.0/bin/neovim-ruby-host'
|
||
|
||
source ~/.config/nvim/init.plugins.vim
|
||
source ~/.config/nvim/init.tabline.vim
|
||
source ~/.config/nvim/init.auto-window.vim
|
||
source ~/.config/nvim/init.fold-text.vim
|
||
|
||
" TODO - maybe separate some of these into own files too
|
||
" #functions {{{
|
||
function! <SID>SynStack()"{{{
|
||
if !exists('*synstack')
|
||
return
|
||
endif
|
||
echo map(synstack(line('.'), col('.')), 'synIDattr(v:val,"name")') '-> ' . synIDattr(synIDtrans(synID(line('.'),col('.'),1)), 'name' )
|
||
endfunc
|
||
nmap <space>pp :call <SID>SynStack()<CR>
|
||
"}}}
|
||
|
||
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 <buffer> q :bdelete<CR>
|
||
augroup ResetShellBufferNr
|
||
autocmd! * <buffer>
|
||
autocmd BufUnload <buffer> 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(<q-args>)
|
||
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 <silent> <buffer> q :bdelete!<CR>'.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(<q-args>)
|
||
" 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 <line1>,<line2>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 = "\<Esc>[38;2;%lu;%lu;%lum"
|
||
let &t_8b = "\<Esc>[48;2;%lu;%lu;%lum"
|
||
set termguicolors
|
||
endif
|
||
|
||
colorscheme paper-custom
|
||
|
||
set updatetime=100
|
||
set timeoutlen=500
|
||
set lazyredraw
|
||
|
||
" https://parceljs.org/hmr.html#safe-write
|
||
set backupcopy=yes
|
||
|
||
set title
|
||
|
||
" the ;/home/* tells vim to stop searching at /home/* (I hope!)
|
||
set tags=./.tags,.tags,./tags-external,.tags-external;/home/*
|
||
|
||
" persisitent undo file
|
||
set undofile
|
||
set undodir=~/.vim/.vimtmp
|
||
set backupdir=~/.vim/.vimtmp
|
||
set directory=~/.vim/.vimtmp
|
||
|
||
set viewoptions-=options
|
||
|
||
set splitbelow splitright
|
||
|
||
set ignorecase
|
||
set smartcase
|
||
|
||
set wildmenu
|
||
set wildmode=longest:full,full
|
||
set wildignore+=**/node_modules/**,**/dist/**,**/.git/**,**/build/**
|
||
|
||
" 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=4
|
||
set softtabstop=-1
|
||
set shiftwidth=4
|
||
set shiftround
|
||
set noexpandtab
|
||
set autoindent
|
||
|
||
set formatoptions=cq
|
||
set wrapmargin=0
|
||
|
||
setlocal cursorline
|
||
|
||
set foldcolumn=2
|
||
set signcolumn=yes
|
||
set colorcolumn=80,120
|
||
|
||
set iskeyword+=-
|
||
set scrolloff=10
|
||
set showcmd
|
||
|
||
set incsearch
|
||
set inccommand=nosplit
|
||
|
||
set laststatus=2
|
||
set shortmess=aoOT
|
||
set cmdheight=3
|
||
|
||
set foldmethod=indent
|
||
set foldnestmax=9
|
||
set foldlevelstart=99
|
||
|
||
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:\
|
||
|
||
set statusline=\
|
||
set statusline+=[%n]\ \
|
||
set statusline+=%l\ of\ %L\
|
||
set statusline+=(%p%%)
|
||
set statusline+=%=
|
||
set statusline+=%y\
|
||
set statusline+=%r\ %m\ %t
|
||
set statusline+=\
|
||
|
||
set conceallevel=0
|
||
"----------------------------------------------------------------------------}}}
|
||
" #mappings {{{
|
||
let g:mapleader = ' '
|
||
" image capable file browser
|
||
nnoremap <silent><space>rs :!VIMRUNTIME= st -t WM_FORCE_FULLSCREEN ranger<CR>
|
||
" search and replace {{{
|
||
nnoremap <space>rr :%s/\<<Ckr>=expand('<cword>')<CR>\>//g<left><left>
|
||
"}}}
|
||
" #syntax
|
||
nnoremap <silent> <cr>s :syntax on<cr>
|
||
nnoremap <silent> <cr>S :syntax off<cr>
|
||
" miscallaneous {{{
|
||
nnoremap <cr>l :colorscheme paper-custom<cr>
|
||
nnoremap <cr>d :colorscheme monotonous-dark<cr>
|
||
nnoremap 0 ^
|
||
nnoremap <silent><space>cs :let @/=""<cr>
|
||
nnoremap <space>: :setlocal number<CR>:
|
||
nnoremap <silent> <space>rc :so $MYVIMRC<CR>
|
||
nnoremap <silent><expr> <space>nh (&hls && v:hlsearch ? ':nohls' : ':set hls')."\n"
|
||
" Focus on current fold, close the rest
|
||
nnoremap <silent> <space>zz zMzvzt
|
||
" exit from terminal insert mode with escape
|
||
tnoremap <Esc> <C-\><C-n>
|
||
" open quickfix window of TODOs
|
||
nnoremap <space>td :grep -RE '(TODO\\|FIXME)' .<CR>:botright cwindow<CR>:echo len(getqflist()) 'TODOs'<CR>
|
||
" sync highlighting from start
|
||
nnoremap <silent><space>ss :syntax sync fromstart<CR>
|
||
|
||
"}}}
|
||
" git mappings {{{
|
||
nnoremap <space>ga :!clear; git add %; git status<CR>
|
||
nnoremap <space>gg :!clear; git add %; git commit -m ''<Left>
|
||
nnoremap <silent><space>gs :!VIMRUNTIME= st -t WM_FORCE_FLOATING -g 230x62 tig status<CR>
|
||
|
||
"}}}
|
||
" movement/navigation{{{
|
||
" alias for :tjump <cword>
|
||
nnoremap <space>tj g<C-]>
|
||
" alias for :ptjump <cword>
|
||
nnoremap <space>tp <C-w>g}
|
||
|
||
"}}}
|
||
" location list and quickfix mappings {{{
|
||
nnoremap <space>lo :botright lwindow<CR>
|
||
nnoremap <up> :lprev<CR>zv
|
||
nnoremap <down> :lnext<CR>zv
|
||
nnoremap <space>lc :lclose<CR>
|
||
nnoremap <space>lh :lhistory<CR>
|
||
nnoremap <space>lp :lolder<CR>
|
||
nnoremap <space>ln :lnewer<CR>
|
||
|
||
nnoremap <space>qo :botright cwindow<CR>
|
||
nnoremap <left> :cprev<CR>zv
|
||
nnoremap <right> :cnext<CR>zv
|
||
nnoremap <space>qc :cclose<CR>
|
||
nnoremap <space>qh :chistory<CR>
|
||
nnoremap <space>qp :colder<CR>
|
||
nnoremap <space>qn :cnewer<CR>
|
||
|
||
"}}}
|
||
" insert mode mappings {{{
|
||
inoremap jj; <Esc>A;<Esc>
|
||
inoremap jj, <Esc>A,<Esc>
|
||
inoremap jjrg <c-o>:reg<cr>
|
||
inoremap :w<cr> :w<cr>
|
||
inoremap [:w<cr> :w<cr>
|
||
inoremap {:w<cr> :w<cr>
|
||
nnoremap ''; '';<left><left>
|
||
|
||
"}}}
|
||
" working_with_underscores{{{
|
||
nnoremap <space>w f_l
|
||
nnoremap <space>b hT_
|
||
nnoremap <space>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{{{
|
||
" TODO move these into autocommand to just load in css, scss, jsx, files
|
||
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 ovh overflow: hidden;
|
||
iabbrev ovv overflow: visible;
|
||
iabbrev ova overflow: auto;
|
||
|
||
iabbrev ct'' content-type: '';
|
||
|
||
"}}}
|
||
|
||
"----------------------------------------------------------------------------}}}
|
||
" #autocommands {{{
|
||
|
||
" template files {{{
|
||
augroup templates
|
||
autocmd!
|
||
autocmd BufNewFile *.sh 0read ~/.config/nvim/templates/template.sh | normal G
|
||
autocmd BufNewFile *.html 0read ~/.config/nvim/templates/template.html | normal gg
|
||
autocmd BufNewFile *.css 0read ~/.config/nvim/templates/template.css | normal G
|
||
autocmd BufNewFile *.scss 0read ~/.config/nvim/templates/template.css | normal G
|
||
augroup END
|
||
|
||
" }}}
|
||
" 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:
|