refactoring
This commit is contained in:
		
							parent
							
								
									2da8339c12
								
							
						
					
					
						commit
						0b5b97042a
					
				| 
						 | 
				
			
			@ -5,5 +5,5 @@ set expandtab
 | 
			
		|||
set shiftround
 | 
			
		||||
set autoindent
 | 
			
		||||
 | 
			
		||||
nnoremap <silent> <buffer> <F5> :call SaveAndExecutePython()<CR> 
 | 
			
		||||
nnoremap <silent> <buffer> <F5> :call SaveAndExecute('python')<CR> 
 | 
			
		||||
" vnoremap <silent> <buffer> <F5> :<C-u>call SaveAndExecutePython()<CR> 
 | 
			
		||||
| 
						 | 
				
			
			
 | 
			
		|||
| 
						 | 
				
			
			@ -1,30 +1,34 @@
 | 
			
		|||
" TODO better name
 | 
			
		||||
function! GetStatusFrag(condition, colorname, conditionprefix, text) abort "{{{
 | 
			
		||||
  let l:frag='%#' . a:colorname . '#'
 | 
			
		||||
function! GetStatusFrag(condition, colorname, conditionprefix, text) abort 
 | 
			
		||||
  let l:frag='%#' . a:colorname . '#'"{{{
 | 
			
		||||
  let l:frag.=a:conditionprefix
 | 
			
		||||
  let l:frag.='%{(' . a:condition . ")?'" . a:text . "':''}"
 | 
			
		||||
  return l:frag
 | 
			
		||||
endfunction"}}}
 | 
			
		||||
endfunction
 | 
			
		||||
"}}}
 | 
			
		||||
 | 
			
		||||
function! CheckLineEnding() abort "{{{
 | 
			
		||||
  :normal $
 | 
			
		||||
function! CheckLineEnding() abort 
 | 
			
		||||
  :normal $"{{{
 | 
			
		||||
  if getline('.')[col('.')-1] == ';' || getline('.')[col('.')-1] == ','
 | 
			
		||||
    :startinsert
 | 
			
		||||
  else
 | 
			
		||||
    :startinsert!
 | 
			
		||||
  endif
 | 
			
		||||
endfunction"}}}
 | 
			
		||||
endfunction
 | 
			
		||||
"}}}
 | 
			
		||||
 | 
			
		||||
" get name of syntax item
 | 
			
		||||
function! SyntaxItem() abort "{{{
 | 
			
		||||
function! SyntaxItem() abort 
 | 
			
		||||
"{{{
 | 
			
		||||
  return synIDattr(synID(line('.'),col('.'),1),'name') . ' -> ' . synIDattr(synIDtrans(synID(line('.'),col('.'),1)), 'name' )
 | 
			
		||||
endfunction
 | 
			
		||||
nnoremap <space>p :echom SyntaxItem()<CR>"}}}
 | 
			
		||||
nnoremap <space>p :echom SyntaxItem()<CR>
 | 
			
		||||
"}}}
 | 
			
		||||
 | 
			
		||||
" devdocs DD
 | 
			
		||||
" https://gist.github.com/romainl/8d3b73428b4366f75a19be2dad2f0987#file-devdocs-vim
 | 
			
		||||
function! s:Get_env() abort "{{{
 | 
			
		||||
    if has('win64') || has('win32') || has('win16')
 | 
			
		||||
function! s:Get_env() abort 
 | 
			
		||||
    if has('win64') || has('win32') || has('win16')"{{{
 | 
			
		||||
        return 'WINDOWS'
 | 
			
		||||
    else
 | 
			
		||||
        return toupper(substitute(system('uname'), '\n', '', ''))
 | 
			
		||||
| 
						 | 
				
			
			@ -42,8 +46,8 @@ command! -nargs=* DD silent! call system(len(split(<q-args>, ' ')) == 0 ?
 | 
			
		|||
"}}}
 | 
			
		||||
 | 
			
		||||
" use ranger as file manager
 | 
			
		||||
if !exists('*RangerExplorer') "{{{
 | 
			
		||||
	function RangerExplorer() abort
 | 
			
		||||
if !exists('*RangerExplorer') 
 | 
			
		||||
	function RangerExplorer() abort"{{{
 | 
			
		||||
			exec 'silent !ranger --choosefile=/tmp/vim_ranger_current_file ' . expand('%:p:h')
 | 
			
		||||
			if filereadable('/tmp/vim_ranger_current_file')
 | 
			
		||||
					exec 'edit ' . system('cat /tmp/vim_ranger_current_file')
 | 
			
		||||
| 
						 | 
				
			
			@ -52,26 +56,26 @@ if !exists('*RangerExplorer') "{{{
 | 
			
		|||
			redraw!
 | 
			
		||||
	endfun
 | 
			
		||||
	map <space>ra :call RangerExplorer()<CR>
 | 
			
		||||
endif"}}}
 | 
			
		||||
endif
 | 
			
		||||
"}}}
 | 
			
		||||
 | 
			
		||||
function! SetColorColumn()"{{{
 | 
			
		||||
  if &buftype == ''
 | 
			
		||||
function! SetColorColumn() abort
 | 
			
		||||
  if &buftype == ''"{{{
 | 
			
		||||
    setlocal colorcolumn=80
 | 
			
		||||
  endif
 | 
			
		||||
endfunction
 | 
			
		||||
"}}}
 | 
			
		||||
 | 
			
		||||
function! GetLinterStatus(key) abort "{{{
 | 
			
		||||
  let l:linter = ale#statusline#Count(bufnr(''))
 | 
			
		||||
function! GetLinterStatus(key) abort 
 | 
			
		||||
  let l:linter = ale#statusline#Count(bufnr(''))"{{{
 | 
			
		||||
 | 
			
		||||
  return l:linter[a:key]
 | 
			
		||||
endfunction
 | 
			
		||||
 | 
			
		||||
"}}}
 | 
			
		||||
 | 
			
		||||
" old linter status function
 | 
			
		||||
function! LinterStatus() abort "{{{
 | 
			
		||||
  let l:counts = ale#statusline#Count(bufnr(''))
 | 
			
		||||
function! LinterStatus() 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
 | 
			
		||||
| 
						 | 
				
			
			@ -81,11 +85,7 @@ endfunction
 | 
			
		|||
"}}}
 | 
			
		||||
 | 
			
		||||
" Shell command
 | 
			
		||||
" based on
 | 
			
		||||
" http://vim.wikia.com/wiki/VimTip1599
 | 
			
		||||
command! -complete=shellcmd -nargs=+ Shell call s:RunShellCommand(<q-args>)
 | 
			
		||||
let g:shell_scratch_buffer_nr = -1
 | 
			
		||||
 | 
			
		||||
function! s:RunShellCommand(cmdline) abort
 | 
			
		||||
"{{{
 | 
			
		||||
  let l:expanded_cmdline = a:cmdline 
 | 
			
		||||
| 
						 | 
				
			
			@ -136,11 +136,16 @@ function! s:RunShellCommand(cmdline) abort
 | 
			
		|||
 | 
			
		||||
  wincmd p
 | 
			
		||||
endfunction
 | 
			
		||||
 | 
			
		||||
command! -complete=shellcmd -nargs=+ Shell call s:RunShellCommand(<q-args>)
 | 
			
		||||
let g:shell_scratch_buffer_nr = -1
 | 
			
		||||
"}}}
 | 
			
		||||
 | 
			
		||||
 | 
			
		||||
" https://stackoverflow.com/a/40195855
 | 
			
		||||
function! SaveAndExecutePython()
 | 
			
		||||
    " SOURCE [reusable window]: https://github.com/fatih/vim-go/blob/master/autoload/go/ui.vim
 | 
			
		||||
" ex_command: command to run to execute file
 | 
			
		||||
function! SaveAndExecute(ex_command) abort
 | 
			
		||||
    " SOURCE [reusable window]: https://github.com/fatih/vim-go/blob/master/autoload/go/ui.vim{{{
 | 
			
		||||
 | 
			
		||||
    " save and reload current file
 | 
			
		||||
    silent execute "update | edit"
 | 
			
		||||
| 
						 | 
				
			
			@ -181,7 +186,7 @@ function! SaveAndExecutePython()
 | 
			
		|||
    %delete _
 | 
			
		||||
 | 
			
		||||
    " add the console output
 | 
			
		||||
    silent execute ".!python " . shellescape(s:current_buffer_file_path, 1)
 | 
			
		||||
    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.
 | 
			
		||||
| 
						 | 
				
			
			@ -193,5 +198,6 @@ function! SaveAndExecutePython()
 | 
			
		|||
    setlocal readonly
 | 
			
		||||
    " setlocal nomodifiable
 | 
			
		||||
endfunction
 | 
			
		||||
"}}}
 | 
			
		||||
 | 
			
		||||
" vim: foldmethod=marker
 | 
			
		||||
| 
						 | 
				
			
			
 | 
			
		|||
		Loading…
	
		Reference in New Issue