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
|
||||
" #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' )
|
||||
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
|
||||
" 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
|
||||
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
|
||||
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
|
||||
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
|
||||
" 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
|
||||
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
|
||||
wincmd p
|
||||
endfunction
|
||||
|
||||
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 "{{{
|
||||
" 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
|
||||
" 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'
|
||||
" save and reload current file
|
||||
silent execute 'update | edit'
|
||||
|
||||
" get file path of current file
|
||||
let s:current_buffer_file_path = expand('%')
|
||||
" 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'
|
||||
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
|
||||
" 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=""
|
||||
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
|
||||
nnoremap <silent> <buffer> q :bdelete!<CR>'.zz
|
||||
|
||||
" clear the buffer
|
||||
setlocal noreadonly
|
||||
" setlocal modifiable
|
||||
%delete _
|
||||
" clear the buffer
|
||||
setlocal noreadonly
|
||||
" setlocal modifiable
|
||||
%delete _
|
||||
|
||||
" add the console output
|
||||
silent execute '.!'. a:ex_command . ' ' . shellescape(s:current_buffer_file_path, 1)
|
||||
" 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('$')
|
||||
" 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
|
||||
" 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/','')
|
||||
" 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"))
|
||||
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>)
|
||||
|
@ -165,8 +165,8 @@ command! -nargs=1 -complete=command Redir silent call Redir(<q-args>)
|
|||
"#commands{{{
|
||||
" TrimWhitespace{{{
|
||||
command! -range=% TrimWhitespace let b:wv = winsaveview() |
|
||||
\ keeppattern <line1>,<line2>s/\s\+$// |
|
||||
\ call winrestview(b:wv)
|
||||
\ keeppattern <line1>,<line2>s/\s\+$// |
|
||||
\ call winrestview(b:wv)
|
||||
"}}}
|
||||
" Scratch, ScratchVertical{{{
|
||||
command! Scratch new | setlocal buftype=nofile | setlocal bufhidden=hide | setlocal noswapfile
|
||||
|
@ -192,9 +192,9 @@ 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
|
||||
let &t_8f = "\<Esc>[38;2;%lu;%lu;%lum"
|
||||
let &t_8b = "\<Esc>[48;2;%lu;%lu;%lum"
|
||||
set termguicolors
|
||||
endif
|
||||
|
||||
colorscheme paper-custom
|
||||
|
@ -230,7 +230,7 @@ set wildignore+=**/node_modules/**,**/dist/**,**/.git/**,**/build/**
|
|||
|
||||
" Use ag over grep
|
||||
if executable('ag')
|
||||
set grepprg=ag\ --nogroup\ --nocolor\ --ignore\ node_modules
|
||||
set grepprg=ag\ --nogroup\ --nocolor\ --ignore\ node_modules
|
||||
endif
|
||||
|
||||
set hidden
|
||||
|
@ -291,20 +291,35 @@ set fillchars=stl:\ ,stlnc:\ ,vert:┃,fold:\
|
|||
set statusline=\
|
||||
" buffer number
|
||||
set statusline+=[%n]\ \
|
||||
" line of total_lines
|
||||
set statusline+=%l\ of\ %L\
|
||||
" percentage through file
|
||||
set statusline+=(%p%%)\
|
||||
" column
|
||||
set statusline+=:%c\
|
||||
" virtual column
|
||||
set statusline+=%((%V)%)
|
||||
" line of total_lines and percentage through file
|
||||
set statusline+=%-20(%l\ of\ %L\ (%p%%)%)
|
||||
" column, virtual column
|
||||
set statusline+=%-7(:%c\ %((%V)%)%)
|
||||
" separator, highlight color
|
||||
set statusline+=%=%#StatusLineNC#
|
||||
" Ale errors
|
||||
set statusline+=%{AleLinterStatus()}
|
||||
" CoC status
|
||||
set statusline+=%{coc#status()}\
|
||||
" separator
|
||||
set statusline+=%=
|
||||
set statusline+=%=%#StatusLine#
|
||||
set statusline+=%y\
|
||||
set statusline+=%r\ %m\ %f
|
||||
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
|
||||
"----------------------------------------------------------------------------}}}
|
||||
" #mappings {{{
|
||||
|
@ -415,28 +430,28 @@ 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
|
||||
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
|
||||
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
|
||||
augroup whitespaceerrors
|
||||
autocmd!
|
||||
autocmd Syntax * syn match ExtraWhitespace /\s\+$\| \+\ze\t/ containedin=ALL
|
||||
augroup END
|
||||
|
||||
" }}}
|
||||
" automatically reload if color scheme file written {{{
|
||||
|
@ -454,22 +469,22 @@ iabbrev ct'' content-type: '';
|
|||
" autocmd CmdlineEnter * :redraw | :set number
|
||||
" autocmd CmdlineLeave * :set nonumber
|
||||
" augroup END
|
||||
" endif
|
||||
" 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
|
||||
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
|
||||
augroup QuickFixAutoload
|
||||
autocmd!
|
||||
autocmd QuickFixCmdPost [^l]* nested botright cwindow
|
||||
autocmd QuickFixCmdPost l* nested botright lwindow
|
||||
augroup END
|
||||
|
||||
" }}}
|
||||
|
||||
|
|
Loading…
Reference in New Issue