2019-04-10 09:54:25 +00:00
" 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.
2020-03-19 18:05:18 +00:00
let g :ruby_host_prog = '~/.gem/ruby/2.7.0/bin/neovim-ruby-host'
2019-04-20 10:57:27 +00:00
2021-09-06 12:01:43 +00:00
set rtp + = '~/nvim-paper-tonic'
2021-09-06 11:47:57 +00:00
2020-03-19 15:56:18 +00:00
source ~ /.config/ nvim /init .plugins .vim
2019-09-13 14:27:38 +00:00
source ~ /.config/ nvim /init .tabline .vim
2020-03-19 16:17:53 +00:00
source ~ /.config/ nvim /init .auto - window .vim
source ~ /.config/ nvim /init .fold - text .vim
2019-09-13 14:27:38 +00:00
2020-03-19 16:17:53 +00:00
" TODO - maybe separate some of these into own files too
" #functions {{{
function ! < SID > SynStack ( ) "{{{
2020-07-31 13:27:19 +00:00
if ! exists ( '*synstack' )
return
endif
echo map ( synstack ( line ( '.' ) , col ( '.' ) ) , 'synIDattr(v:val,"name")' ) '-> ' . synIDattr ( synIDtrans ( synID ( line ( '.' ) , col ( '.' ) , 1 ) ) , 'name' )
2020-03-19 16:17:53 +00:00
endfunc
2021-09-04 12:37:48 +00:00
" nmap <space>pp :call <SID>SynStack()<CR>
nmap < silent > < space > pp :TSHighlightCapturesUnderCursor < CR >
2020-03-19 16:17:53 +00:00
"}}}
function ! s :RunShellCommand ( cmdline ) abort "{{{
2020-07-31 13:27:19 +00:00
" 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
2020-03-19 16:17:53 +00:00
endfunction
command ! - complete = shellcmd - nargs = + Shell call s :RunShellCommand ( < q - args > )
let g :shell_scratch_buffer_nr = -1
"}}}
function ! SaveAndExecute ( ex_command ) abort "{{{
2020-07-31 13:27:19 +00:00
" 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
2020-03-19 16:17:53 +00:00
endfunction
"}}}
function ! JsIncludeExpr ( file ) "{{{
2020-07-31 13:27:19 +00:00
" substitute(substitute(v:fname,'^[\\~@]\/','./',''),'^[\\~@]','./node_modules/','')
return substitute ( substitute ( a :file , '^[\\~@]\/' , './' , '' ) , '^[\\~@]' , './node_modules/' , '' )
2020-03-19 16:17:53 +00:00
2019-09-13 14:27:38 +00:00
endfunction
"}}}
2020-03-19 16:17:53 +00:00
function ! Redir ( cmd ) "{{{
2020-07-31 13:27:19 +00:00
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" ) )
2019-09-13 14:27:38 +00:00
endfunction
2020-03-19 16:17:53 +00:00
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
"}}}
2020-07-31 14:22:03 +00:00
"}}}
2020-07-31 14:42:06 +00:00
function ! ToggleHighlights ( ) abort "{{{
if ! exists ( 'b:toggle_highlights_state' )
" state 1 is normal, state 0 is faded
let b :toggle_highlights_state = 1
else
let b :toggle_highlights_state = ! b :toggle_highlights_state
endif
if b :toggle_highlights_state = = 1
2020-07-31 15:03:54 +00:00
hi ! link Comment None
2020-07-31 14:42:06 +00:00
else
2020-07-31 15:03:54 +00:00
hi ! link Comment CommentDim
2020-07-31 14:42:06 +00:00
endif
endfunction
"}}}
2020-03-19 16:17:53 +00:00
"----------------------------------------------------------------------------}}}
"#commands{{{
" TrimWhitespace{{{
command ! - range = % TrimWhitespace let b :wv = winsaveview ( ) |
2020-07-31 13:27:19 +00:00
\ keeppattern < line1 > , < line2 > s /\s\+$/ / |
\ call winrestview ( b :wv )
2020-03-19 16:17:53 +00:00
"}}}
" Scratch, ScratchVertical{{{
command ! Scratch new | setlocal buftype = nofile | setlocal bufhidden = hide | setlocal noswapfile
command ! ScratchVertical vnew | setlocal buftype = nofile | setlocal bufhidden = hide | setlocal noswapfile
2019-09-13 14:27:38 +00:00
"}}}
2020-03-19 16:17:53 +00:00
"}}}
" #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' )
2020-07-31 13:27:19 +00:00
let &t_8f = "\<Esc>[38;2;%lu;%lu;%lum"
let &t_8b = "\<Esc>[48;2;%lu;%lu;%lum"
set termguicolors
2020-03-19 16:17:53 +00:00
endif
2021-09-06 11:47:57 +00:00
colorscheme paper - tonic
2020-03-19 16:17:53 +00:00
set updatetime = 100
set timeoutlen = 500
set lazyredraw
2020-06-27 17:21:22 +00:00
" https://parceljs.org/hmr.html#safe-write
set backupcopy = yes
2020-04-01 16:25:02 +00:00
set title
2020-05-10 11:46:27 +00:00
" the ;/home/* tells vim to stop searching at /home/* (I hope!)
set tags = ./.tags,.tags,./ tags - external , .tags - external ;/home/ *
2020-03-19 16:17:53 +00:00
" persisitent undo file
set undofile
2021-07-05 13:28:37 +00:00
set undodir = ~ /.config/ nvim /undodir
set backupdir = ~ /nvim/ tmpdir
set directory = ~ /nvim/ tmpdir
2020-03-19 16:17:53 +00:00
set viewoptions - = options
2020-04-24 12:01:59 +00:00
set splitbelow splitright
2020-03-19 16:17:53 +00:00
set ignorecase
set smartcase
set wildmenu
set wildmode = longest :full , full
2020-04-27 10:53:42 +00:00
set wildignore + = **/node_modules/ **, **/dist/ **, **/.git/ **, **/build/ **
2020-03-19 16:17:53 +00:00
" Use ag over grep
if executable ( 'ag' )
2020-07-31 13:27:19 +00:00
set grepprg = ag \ - - nogroup \ - - nocolor \ - - ignore \ node_modules
2020-03-19 16:17:53 +00:00
endif
set hidden
set hlsearch
2021-09-04 11:21:35 +00:00
set completeopt = menuone , noselect
2020-03-19 16:17:53 +00:00
set nospell
set spelllang = en_gb
set diffopt + = vertical
set rnu nu
2021-09-08 14:56:41 +00:00
set tabstop = 2
2020-03-31 20:14:03 +00:00
set softtabstop = -1
2021-09-08 14:56:41 +00:00
set shiftwidth = 0
2020-03-19 16:17:53 +00:00
set shiftround
2020-03-31 20:14:03 +00:00
set noexpandtab
2020-03-19 16:17:53 +00:00
set autoindent
set formatoptions = cq
set wrapmargin = 0
2020-07-31 10:35:34 +00:00
setlocal cursorline
2020-03-19 16:17:53 +00:00
2020-07-31 15:03:54 +00:00
set foldcolumn = 0
2020-07-31 10:35:34 +00:00
set signcolumn = yes
2020-03-19 16:17:53 +00:00
set colorcolumn = 80 , 120
set iskeyword + = -
2021-02-16 12:50:46 +00:00
set scrolloff = 4
set scrolljump = 4
2020-03-19 16:17:53 +00:00
set showcmd
2020-04-06 09:22:49 +00:00
2020-03-19 16:17:53 +00:00
set incsearch
2020-04-06 09:22:49 +00:00
set inccommand = nosplit
2020-03-19 16:17:53 +00:00
set laststatus = 2
set shortmess = aoOT
set cmdheight = 3
set foldmethod = indent
2020-03-31 16:54:13 +00:00
set foldnestmax = 9
2020-03-24 12:55:04 +00:00
set foldlevelstart = 99
2020-03-19 16:17:53 +00:00
set showmode
set autoindent
set breakindent
set showbreak = \ \ ↳\
set mouse = a
2020-06-26 08:49:29 +00:00
set listchars = eol :¬, tab :│\ , trail :~ , extends :> , precedes :< , space :·
2020-03-19 16:17:53 +00:00
set fillchars = stl :\ , stlnc :\ , vert :┃, fold :\
set statusline = \
2020-07-31 11:47:26 +00:00
" buffer number
2020-03-19 16:17:53 +00:00
set statusline + = [%n ]\ \
2020-07-31 13:27:19 +00:00
" line of total_lines and percentage through file
set statusline + = %-20 ( %l \ of \ %L \ ( %p %%) %)
" column, virtual column
2020-07-31 16:23:35 +00:00
set statusline + = %-10 ( :%c \ %( ( %V ) %) %)
2020-07-31 13:27:19 +00:00
" separator, highlight color
set statusline + = %= %#StatusLineNC #
" CoC status
2020-12-30 14:58:54 +00:00
if exists ( '*coc#exists' )
set statusline + = %{coc #status ( ) }
endif
2020-07-31 11:47:26 +00:00
" separator
2020-07-31 13:27:19 +00:00
set statusline + = %= %#StatusLine #
2020-03-19 16:17:53 +00:00
set statusline + = %y \
2020-08-01 10:43:02 +00:00
set statusline + = %r \ %m \
set statusline + = %{&buftype = = '' ?expand ( '%f' ) :'' }
2020-03-19 16:17:53 +00:00
set statusline + = \
set conceallevel = 0
"----------------------------------------------------------------------------}}}
" #mappings {{{
let g :mapleader = ' '
" miscallaneous {{{
2020-07-28 21:59:06 +00:00
nnoremap < cr > l :colorscheme paper - custom < cr >
2020-03-19 16:17:53 +00:00
nnoremap < cr > d :colorscheme monotonous - dark < cr >
nnoremap 0 ^
nnoremap < silent > < space > cs :let @/= "" < 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
2020-07-16 08:43:11 +00:00
" exit from terminal insert mode with escape
tnoremap < Esc > < C - \> < C - n >
2020-03-19 16:17:53 +00:00
" 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
"}}}
" 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 {{{
2020-05-09 19:58:29 +00:00
inoremap jjrg < c - o > :reg < cr >
2020-03-19 16:17:53 +00:00
"}}}
"----------------------------------------------------------------------------}}}
" #abbreviations {{{
" spelling"{{{
iabbrev adn and
iabbrev waht what
iabbrev tehn then
iabbrev functin function
iabbrev positin position
"}}}
" css{{{
2020-04-28 14:45:02 +00:00
" 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 ;
2020-03-19 16:17:53 +00:00
iabbrev ct '' content - type : '' ;
"}}}
"----------------------------------------------------------------------------}}}
" #autocommands {{{
2020-04-24 19:49:23 +00:00
" template files {{{
2020-07-31 13:27:19 +00:00
augroup templates
autocmd !
autocmd BufNewFile *.sh 0 read ~ /.config/ nvim /templates/ template .sh | normal G
autocmd BufNewFile *.html 0 read ~ /.config/ nvim /templates/ template .html | normal gg
autocmd BufNewFile *.css 0 read ~ /.config/ nvim /templates/ template .css | normal G
autocmd BufNewFile *.scss 0 read ~ /.config/ nvim /templates/ template .css | normal G
augroup END
2020-03-21 21:33:23 +00:00
" }}}
2020-03-19 16:17:53 +00:00
" persistent folds {{{
2020-07-31 13:27:19 +00:00
augroup AutoSaveFolds
autocmd !
autocmd BufWrite ?* mkview
autocmd BufRead ?* silent ! loadview
augroup END
2020-03-19 16:17:53 +00:00
" }}}
" Show trailing whitepace and spaces before a tab: {{{
2020-08-01 11:05:46 +00:00
augroup ShowWhiteSpaceErrors
2020-07-31 13:27:19 +00:00
autocmd !
autocmd Syntax * syn match ExtraWhitespace /\s\+$\| \+\ze\t/ containedin = ALL
augroup END
2020-03-19 16:17:53 +00:00
" }}}
" Automatically reload .vimrc if changed {{{
2020-08-01 11:05:46 +00:00
augroup ReloadVimrc
2020-07-31 13:27:19 +00:00
autocmd !
autocmd BufWritePost .vimrc , _vimrc , vimrc , .gvimrc , _gvimrc , gvimrc so $MYVIMRC | if has ( 'gui_running' ) | so $MYGVIMRC | endif
augroup END
2020-03-19 16:17:53 +00:00
" }}}
" Open quickfix window{{{
2020-07-31 13:27:19 +00:00
augroup QuickFixAutoload
autocmd !
autocmd QuickFixCmdPost [^l ]* nested botright cwindow
autocmd QuickFixCmdPost l * nested botright lwindow
augroup END
2020-03-19 16:17:53 +00:00
2020-08-01 11:04:25 +00:00
augroup OnTerminalOpen
autocmd !
autocmd TermOpen * setlocal nonumber norelativenumber
augroup END
2020-03-19 16:17:53 +00:00
" }}}
"----------------------------------------------------------------------------}}}
2020-03-19 18:05:39 +00:00
"
2019-04-20 10:57:27 +00:00
" vim: set foldmethod=marker: