update
This commit is contained in:
parent
877df2f084
commit
549eb13f1c
311
init.vim
311
init.vim
|
@ -10,65 +10,65 @@ source ~/.config/nvim/init.fold-text.vim
|
||||||
" TODO - maybe separate some of these into own files too
|
" TODO - maybe separate some of these into own files too
|
||||||
" #functions {{{
|
" #functions {{{
|
||||||
function! <SID>SynStack()"{{{
|
function! <SID>SynStack()"{{{
|
||||||
if !exists('*synstack')
|
if !exists('*synstack')
|
||||||
return
|
return
|
||||||
endif
|
endif
|
||||||
echo map(synstack(line('.'), col('.')), 'synIDattr(v:val,"name")') '-> ' . synIDattr(synIDtrans(synID(line('.'),col('.'),1)), 'name' )
|
echo map(synstack(line('.'), col('.')), 'synIDattr(v:val,"name")') '-> ' . synIDattr(synIDtrans(synID(line('.'),col('.'),1)), 'name' )
|
||||||
endfunc
|
endfunc
|
||||||
nmap <space>pp :call <SID>SynStack()<CR>
|
nmap <space>pp :call <SID>SynStack()<CR>
|
||||||
"}}}
|
"}}}
|
||||||
|
|
||||||
function! s:RunShellCommand(cmdline) abort"{{{
|
function! s:RunShellCommand(cmdline) abort"{{{
|
||||||
" Shell command
|
" Shell command
|
||||||
" http://vim.wikia.com/wiki/VimTip1599
|
" http://vim.wikia.com/wiki/VimTip1599
|
||||||
|
|
||||||
let l:expanded_cmdline = a:cmdline
|
let l:expanded_cmdline = a:cmdline
|
||||||
for l:part in split(a:cmdline, ' ')
|
for l:part in split(a:cmdline, ' ')
|
||||||
if l:part[0] =~ '\v[%#<]'
|
if l:part[0] =~ '\v[%#<]'
|
||||||
let l:expanded_part = fnameescape(expand(l:part))
|
let l:expanded_part = fnameescape(expand(l:part))
|
||||||
let l:expanded_cmdline = substitute(l:expanded_cmdline, l:part, l:expanded_part, '')
|
let l:expanded_cmdline = substitute(l:expanded_cmdline, l:part, l:expanded_part, '')
|
||||||
endif
|
endif
|
||||||
endfor
|
endfor
|
||||||
|
|
||||||
if g:shell_scratch_buffer_nr > -1
|
if g:shell_scratch_buffer_nr > -1
|
||||||
let l:win_nr = bufwinnr(g:shell_scratch_buffer_nr)
|
let l:win_nr = bufwinnr(g:shell_scratch_buffer_nr)
|
||||||
if l:win_nr < 0
|
if l:win_nr < 0
|
||||||
execute 'bdelete' g:shell_scratch_buffer_nr
|
execute 'bdelete' g:shell_scratch_buffer_nr
|
||||||
top new
|
top new
|
||||||
let g:shell_scratch_buffer_nr = bufnr('%')
|
let g:shell_scratch_buffer_nr = bufnr('%')
|
||||||
else
|
else
|
||||||
execute l:win_nr. ' wincmd w'
|
execute l:win_nr. ' wincmd w'
|
||||||
setlocal modifiable
|
setlocal modifiable
|
||||||
%delete _
|
%delete _
|
||||||
endif
|
endif
|
||||||
else
|
else
|
||||||
top new
|
top new
|
||||||
let g:shell_scratch_buffer_nr = bufnr('%')
|
let g:shell_scratch_buffer_nr = bufnr('%')
|
||||||
endif
|
endif
|
||||||
|
|
||||||
setlocal buftype=nofile bufhidden=wipe nobuflisted noswapfile nowrap
|
setlocal buftype=nofile bufhidden=wipe nobuflisted noswapfile nowrap
|
||||||
nnoremap <buffer> q :bdelete<CR>
|
nnoremap <buffer> q :bdelete<CR>
|
||||||
augroup ResetShellBufferNr
|
augroup ResetShellBufferNr
|
||||||
autocmd! * <buffer>
|
autocmd! * <buffer>
|
||||||
autocmd BufUnload <buffer> let g:shell_scratch_buffer_nr = -1
|
autocmd BufUnload <buffer> let g:shell_scratch_buffer_nr = -1
|
||||||
augroup END
|
augroup END
|
||||||
|
|
||||||
" call setline(1, 'You entered: ' . a:cmdline)
|
" call setline(1, 'You entered: ' . a:cmdline)
|
||||||
" call setline(2, 'Expanded Form: ' .l:expanded_cmdline)
|
" call setline(2, 'Expanded Form: ' .l:expanded_cmdline)
|
||||||
" call setline(3,substitute(getline(2),'.','=','g'))
|
" call setline(3,substitute(getline(2),'.','=','g'))
|
||||||
execute '$read !'. l:expanded_cmdline
|
execute '$read !'. l:expanded_cmdline
|
||||||
1
|
1
|
||||||
|
|
||||||
setlocal nomodifiable
|
setlocal nomodifiable
|
||||||
if !exists('b:shell_line_count')
|
if !exists('b:shell_line_count')
|
||||||
let b:shell_line_count = line('$')
|
let b:shell_line_count = line('$')
|
||||||
if b:shell_line_count > 25
|
if b:shell_line_count > 25
|
||||||
let b:shell_line_count = 20
|
let b:shell_line_count = 20
|
||||||
endif
|
endif
|
||||||
execute 'resize' b:shell_line_count + 1
|
execute 'resize' b:shell_line_count + 1
|
||||||
endif
|
endif
|
||||||
|
|
||||||
wincmd p
|
wincmd p
|
||||||
endfunction
|
endfunction
|
||||||
|
|
||||||
command! -complete=shellcmd -nargs=+ Shell call s:RunShellCommand(<q-args>)
|
command! -complete=shellcmd -nargs=+ Shell call s:RunShellCommand(<q-args>)
|
||||||
|
@ -76,84 +76,84 @@ let g:shell_scratch_buffer_nr = -1
|
||||||
|
|
||||||
"}}}
|
"}}}
|
||||||
function! SaveAndExecute(ex_command) abort "{{{
|
function! SaveAndExecute(ex_command) abort "{{{
|
||||||
" https://stackoverflow.com/a/40195855
|
" https://stackoverflow.com/a/40195855
|
||||||
" ex_command: command to run to execute file
|
" ex_command: command to run to execute file
|
||||||
" SOURCE [reusable window]: https://github.com/fatih/vim-go/blob/master/autoload/go/ui.vim
|
" SOURCE [reusable window]: https://github.com/fatih/vim-go/blob/master/autoload/go/ui.vim
|
||||||
|
|
||||||
" save and reload current file
|
" save and reload current file
|
||||||
silent execute 'update | edit'
|
silent execute 'update | edit'
|
||||||
|
|
||||||
" get file path of current file
|
" get file path of current file
|
||||||
let s:current_buffer_file_path = expand('%')
|
let s:current_buffer_file_path = expand('%')
|
||||||
|
|
||||||
let s:output_buffer_name = 'Output'
|
let s:output_buffer_name = 'Output'
|
||||||
let s:output_buffer_filetype = 'output'
|
let s:output_buffer_filetype = 'output'
|
||||||
|
|
||||||
" reuse existing buffer window if it exists otherwise create a new one
|
" 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
|
if !exists('c:buf_nr') || !bufexists(s:buf_nr) || bufwinnr(s:buf_nr) == -1
|
||||||
silent execute 'top new ' . s:output_buffer_name
|
silent execute 'top new ' . s:output_buffer_name
|
||||||
let s:buf_nr = bufnr('%')
|
let s:buf_nr = bufnr('%')
|
||||||
elseif bufwinnr(s:buf_nr) != bufwinnr('%')
|
elseif bufwinnr(s:buf_nr) != bufwinnr('%')
|
||||||
silent execute bufwinnr(s:buf_nr) . 'wincmd w'
|
silent execute bufwinnr(s:buf_nr) . 'wincmd w'
|
||||||
endif
|
endif
|
||||||
|
|
||||||
silent execute 'setlocal filetype=' . s:output_buffer_filetype
|
silent execute 'setlocal filetype=' . s:output_buffer_filetype
|
||||||
setlocal bufhidden=delete
|
setlocal bufhidden=delete
|
||||||
setlocal buftype=nofile
|
setlocal buftype=nofile
|
||||||
setlocal noswapfile
|
setlocal noswapfile
|
||||||
setlocal nobuflisted
|
setlocal nobuflisted
|
||||||
setlocal winfixheight
|
setlocal winfixheight
|
||||||
setlocal cursorline " make it easy to distinguish
|
setlocal cursorline " make it easy to distinguish
|
||||||
" setlocal nonumber
|
" setlocal nonumber
|
||||||
" setlocal norelativenumber
|
" setlocal norelativenumber
|
||||||
setlocal showbreak=""
|
setlocal showbreak=""
|
||||||
|
|
||||||
nnoremap <silent> <buffer> q :bdelete!<CR>'.zz
|
nnoremap <silent> <buffer> q :bdelete!<CR>'.zz
|
||||||
|
|
||||||
" clear the buffer
|
" clear the buffer
|
||||||
setlocal noreadonly
|
setlocal noreadonly
|
||||||
" setlocal modifiable
|
" setlocal modifiable
|
||||||
%delete _
|
%delete _
|
||||||
|
|
||||||
" add the console output
|
" add the console output
|
||||||
silent execute '.!'. a:ex_command . ' ' . shellescape(s:current_buffer_file_path, 1)
|
silent execute '.!'. a:ex_command . ' ' . shellescape(s:current_buffer_file_path, 1)
|
||||||
|
|
||||||
" resize window to content length
|
" 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.
|
" 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.
|
" 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
|
" But if you close the output buffer then it returns to using the default size when its recreated
|
||||||
"execute 'resize' . line('$')
|
"execute 'resize' . line('$')
|
||||||
|
|
||||||
" make the buffer non modifiable
|
" make the buffer non modifiable
|
||||||
setlocal readonly
|
setlocal readonly
|
||||||
" setlocal nomodifiable
|
" setlocal nomodifiable
|
||||||
endfunction
|
endfunction
|
||||||
|
|
||||||
"}}}
|
"}}}
|
||||||
function! JsIncludeExpr(file)"{{{
|
function! JsIncludeExpr(file)"{{{
|
||||||
" substitute(substitute(v:fname,'^[\\~@]\/','./',''),'^[\\~@]','./node_modules/','')
|
" substitute(substitute(v:fname,'^[\\~@]\/','./',''),'^[\\~@]','./node_modules/','')
|
||||||
return substitute(substitute(a:file,'^[\\~@]\/','./',''),'^[\\~@]','./node_modules/','')
|
return substitute(substitute(a:file,'^[\\~@]\/','./',''),'^[\\~@]','./node_modules/','')
|
||||||
|
|
||||||
endfunction
|
endfunction
|
||||||
|
|
||||||
"}}}
|
"}}}
|
||||||
function! Redir(cmd) "{{{
|
function! Redir(cmd) "{{{
|
||||||
for win in range(1, winnr('$'))
|
for win in range(1, winnr('$'))
|
||||||
if getwinvar(win, 'scratch')
|
if getwinvar(win, 'scratch')
|
||||||
execute win . 'windo close'
|
execute win . 'windo close'
|
||||||
endif
|
endif
|
||||||
endfor
|
endfor
|
||||||
if a:cmd =~ '^!'
|
if a:cmd =~ '^!'
|
||||||
let output = system(matchstr(a:cmd, '^!\zs.*'))
|
let output = system(matchstr(a:cmd, '^!\zs.*'))
|
||||||
else
|
else
|
||||||
redir => output
|
redir => output
|
||||||
execute a:cmd
|
execute a:cmd
|
||||||
redir END
|
redir END
|
||||||
endif
|
endif
|
||||||
vnew
|
vnew
|
||||||
let w:scratch = 1
|
let w:scratch = 1
|
||||||
setlocal buftype=nofile bufhidden=wipe nobuflisted noswapfile
|
setlocal buftype=nofile bufhidden=wipe nobuflisted noswapfile
|
||||||
call setline(1, split(output, "\n"))
|
call setline(1, split(output, "\n"))
|
||||||
endfunction
|
endfunction
|
||||||
|
|
||||||
command! -nargs=1 -complete=command Redir silent call Redir(<q-args>)
|
command! -nargs=1 -complete=command Redir silent call Redir(<q-args>)
|
||||||
|
@ -165,8 +165,8 @@ command! -nargs=1 -complete=command Redir silent call Redir(<q-args>)
|
||||||
"#commands{{{
|
"#commands{{{
|
||||||
" TrimWhitespace{{{
|
" TrimWhitespace{{{
|
||||||
command! -range=% TrimWhitespace let b:wv = winsaveview() |
|
command! -range=% TrimWhitespace let b:wv = winsaveview() |
|
||||||
\ keeppattern <line1>,<line2>s/\s\+$// |
|
\ keeppattern <line1>,<line2>s/\s\+$// |
|
||||||
\ call winrestview(b:wv)
|
\ call winrestview(b:wv)
|
||||||
"}}}
|
"}}}
|
||||||
" Scratch, ScratchVertical{{{
|
" Scratch, ScratchVertical{{{
|
||||||
command! Scratch new | setlocal buftype=nofile | setlocal bufhidden=hide | setlocal noswapfile
|
command! Scratch new | setlocal buftype=nofile | setlocal bufhidden=hide | setlocal noswapfile
|
||||||
|
@ -192,9 +192,9 @@ set guioptions-=mTrLb
|
||||||
set guioptions+=c
|
set guioptions+=c
|
||||||
|
|
||||||
if exists('+termguicolors')
|
if exists('+termguicolors')
|
||||||
let &t_8f = "\<Esc>[38;2;%lu;%lu;%lum"
|
let &t_8f = "\<Esc>[38;2;%lu;%lu;%lum"
|
||||||
let &t_8b = "\<Esc>[48;2;%lu;%lu;%lum"
|
let &t_8b = "\<Esc>[48;2;%lu;%lu;%lum"
|
||||||
set termguicolors
|
set termguicolors
|
||||||
endif
|
endif
|
||||||
|
|
||||||
colorscheme paper-custom
|
colorscheme paper-custom
|
||||||
|
@ -230,7 +230,7 @@ set wildignore+=**/node_modules/**,**/dist/**,**/.git/**,**/build/**
|
||||||
|
|
||||||
" Use ag over grep
|
" Use ag over grep
|
||||||
if executable('ag')
|
if executable('ag')
|
||||||
set grepprg=ag\ --nogroup\ --nocolor\ --ignore\ node_modules
|
set grepprg=ag\ --nogroup\ --nocolor\ --ignore\ node_modules
|
||||||
endif
|
endif
|
||||||
|
|
||||||
set hidden
|
set hidden
|
||||||
|
@ -291,20 +291,35 @@ set fillchars=stl:\ ,stlnc:\ ,vert:┃,fold:\
|
||||||
set statusline=\
|
set statusline=\
|
||||||
" buffer number
|
" buffer number
|
||||||
set statusline+=[%n]\ \
|
set statusline+=[%n]\ \
|
||||||
" line of total_lines
|
" line of total_lines and percentage through file
|
||||||
set statusline+=%l\ of\ %L\
|
set statusline+=%-20(%l\ of\ %L\ (%p%%)%)
|
||||||
" percentage through file
|
" column, virtual column
|
||||||
set statusline+=(%p%%)\
|
set statusline+=%-7(:%c\ %((%V)%)%)
|
||||||
" column
|
" separator, highlight color
|
||||||
set statusline+=:%c\
|
set statusline+=%=%#StatusLineNC#
|
||||||
" virtual column
|
" Ale errors
|
||||||
set statusline+=%((%V)%)
|
set statusline+=%{AleLinterStatus()}
|
||||||
|
" CoC status
|
||||||
|
set statusline+=%{coc#status()}\
|
||||||
" separator
|
" separator
|
||||||
set statusline+=%=
|
set statusline+=%=%#StatusLine#
|
||||||
set statusline+=%y\
|
set statusline+=%y\
|
||||||
set statusline+=%r\ %m\ %f
|
set statusline+=%r\ %m\ %f
|
||||||
set statusline+=\
|
set statusline+=\
|
||||||
|
|
||||||
|
function! AleLinterStatus() abort
|
||||||
|
let l:counts = ale#statusline#Count(bufnr(''))
|
||||||
|
|
||||||
|
let l:all_errors = l:counts.error + l:counts.style_error
|
||||||
|
let l:all_non_errors = l:counts.total - l:all_errors
|
||||||
|
|
||||||
|
return l:counts.total == 0 ? '' : printf(
|
||||||
|
\ '[ %dW %dE ]',
|
||||||
|
\ all_non_errors,
|
||||||
|
\ all_errors
|
||||||
|
\)
|
||||||
|
endfunction
|
||||||
|
|
||||||
set conceallevel=0
|
set conceallevel=0
|
||||||
"----------------------------------------------------------------------------}}}
|
"----------------------------------------------------------------------------}}}
|
||||||
" #mappings {{{
|
" #mappings {{{
|
||||||
|
@ -415,28 +430,28 @@ iabbrev ct'' content-type: '';
|
||||||
" #autocommands {{{
|
" #autocommands {{{
|
||||||
|
|
||||||
" template files {{{
|
" template files {{{
|
||||||
augroup templates
|
augroup templates
|
||||||
autocmd!
|
autocmd!
|
||||||
autocmd BufNewFile *.sh 0read ~/.config/nvim/templates/template.sh | normal G
|
autocmd BufNewFile *.sh 0read ~/.config/nvim/templates/template.sh | normal G
|
||||||
autocmd BufNewFile *.html 0read ~/.config/nvim/templates/template.html | normal gg
|
autocmd BufNewFile *.html 0read ~/.config/nvim/templates/template.html | normal gg
|
||||||
autocmd BufNewFile *.css 0read ~/.config/nvim/templates/template.css | normal G
|
autocmd BufNewFile *.css 0read ~/.config/nvim/templates/template.css | normal G
|
||||||
autocmd BufNewFile *.scss 0read ~/.config/nvim/templates/template.css | normal G
|
autocmd BufNewFile *.scss 0read ~/.config/nvim/templates/template.css | normal G
|
||||||
augroup END
|
augroup END
|
||||||
|
|
||||||
" }}}
|
" }}}
|
||||||
" persistent folds {{{
|
" persistent folds {{{
|
||||||
augroup AutoSaveFolds
|
augroup AutoSaveFolds
|
||||||
autocmd!
|
autocmd!
|
||||||
autocmd BufWrite ?* mkview
|
autocmd BufWrite ?* mkview
|
||||||
autocmd BufRead ?* silent! loadview
|
autocmd BufRead ?* silent! loadview
|
||||||
augroup END
|
augroup END
|
||||||
|
|
||||||
" }}}
|
" }}}
|
||||||
" Show trailing whitepace and spaces before a tab: {{{
|
" Show trailing whitepace and spaces before a tab: {{{
|
||||||
augroup whitespaceerrors
|
augroup whitespaceerrors
|
||||||
autocmd!
|
autocmd!
|
||||||
autocmd Syntax * syn match ExtraWhitespace /\s\+$\| \+\ze\t/ containedin=ALL
|
autocmd Syntax * syn match ExtraWhitespace /\s\+$\| \+\ze\t/ containedin=ALL
|
||||||
augroup END
|
augroup END
|
||||||
|
|
||||||
" }}}
|
" }}}
|
||||||
" automatically reload if color scheme file written {{{
|
" automatically reload if color scheme file written {{{
|
||||||
|
@ -454,22 +469,22 @@ iabbrev ct'' content-type: '';
|
||||||
" autocmd CmdlineEnter * :redraw | :set number
|
" autocmd CmdlineEnter * :redraw | :set number
|
||||||
" autocmd CmdlineLeave * :set nonumber
|
" autocmd CmdlineLeave * :set nonumber
|
||||||
" augroup END
|
" augroup END
|
||||||
" endif
|
" endif
|
||||||
|
|
||||||
" }}}
|
" }}}
|
||||||
" Automatically reload .vimrc if changed {{{
|
" Automatically reload .vimrc if changed {{{
|
||||||
augroup myvimrc
|
augroup myvimrc
|
||||||
autocmd!
|
autocmd!
|
||||||
autocmd BufWritePost .vimrc,_vimrc,vimrc,.gvimrc,_gvimrc,gvimrc so $MYVIMRC | if has('gui_running') | so $MYGVIMRC | endif
|
autocmd BufWritePost .vimrc,_vimrc,vimrc,.gvimrc,_gvimrc,gvimrc so $MYVIMRC | if has('gui_running') | so $MYGVIMRC | endif
|
||||||
augroup END
|
augroup END
|
||||||
|
|
||||||
" }}}
|
" }}}
|
||||||
" Open quickfix window{{{
|
" Open quickfix window{{{
|
||||||
augroup QuickFixAutoload
|
augroup QuickFixAutoload
|
||||||
autocmd!
|
autocmd!
|
||||||
autocmd QuickFixCmdPost [^l]* nested botright cwindow
|
autocmd QuickFixCmdPost [^l]* nested botright cwindow
|
||||||
autocmd QuickFixCmdPost l* nested botright lwindow
|
autocmd QuickFixCmdPost l* nested botright lwindow
|
||||||
augroup END
|
augroup END
|
||||||
|
|
||||||
" }}}
|
" }}}
|
||||||
|
|
||||||
|
|
Loading…
Reference in New Issue