From 0b5b97042aa93bee02e0d486d954407fb9a50d2a Mon Sep 17 00:00:00 2001 From: ManjaroOne666 Date: Fri, 30 Mar 2018 23:43:04 +0100 Subject: [PATCH] refactoring --- vim/ftplugin/python.vim | 2 +- vimrc.functions.vim | 60 ++++++++++++++++++++++------------------- 2 files changed, 34 insertions(+), 28 deletions(-) diff --git a/vim/ftplugin/python.vim b/vim/ftplugin/python.vim index 737daac..cab3750 100644 --- a/vim/ftplugin/python.vim +++ b/vim/ftplugin/python.vim @@ -5,5 +5,5 @@ set expandtab set shiftround set autoindent -nnoremap :call SaveAndExecutePython() +nnoremap :call SaveAndExecute('python') " vnoremap :call SaveAndExecutePython() diff --git a/vimrc.functions.vim b/vimrc.functions.vim index 62b9ffe..0c2561e 100644 --- a/vimrc.functions.vim +++ b/vimrc.functions.vim @@ -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 p :echom SyntaxItem()"}}} +nnoremap p :echom SyntaxItem() +"}}} " 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(, ' ')) == 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 ra :call RangerExplorer() -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() -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() +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