From 1280549be01e3ce72d9e0aeef6254a1ff14a25a3 Mon Sep 17 00:00:00 2001 From: Sergey Matveev Date: Tue, 29 Jun 2021 12:11:53 +0300 Subject: [PATCH] Vim scripts refactoring --- vim/.vim/autoload/buftabline.vim | 18 +++ vim/.vim/autoload/chnglstnav.vim | 4 + vim/.vim/autoload/ctags.vim | 35 ++++++ vim/.vim/autoload/defsplit.vim | 92 +++++++++++++++ .../file_line.vim => autoload/fileline.vim} | 7 +- vim/.vim/autoload/go/getdoc.vim | 34 ++++++ vim/.vim/autoload/python/importcompl.vim | 70 ++++++++++++ .../pylint.vim => autoload/python/lint.vim} | 33 +++--- vim/.vim/autoload/python/pep8.vim | 18 +++ vim/.vim/autoload/python/testname.vim | 22 ++++ vim/.vim/autoload/python/unused.vim | 6 + vim/.vim/autoload/whereami.vim | 14 +++ vim/.vim/ftdetect/mutt.vim | 2 +- vim/.vim/ftplugin/c/autos.vim | 6 +- vim/.vim/ftplugin/go/autos.vim | 4 +- vim/.vim/ftplugin/go/fmt.vim | 4 +- vim/.vim/ftplugin/go/gogetdoc.vim | 38 +------ vim/.vim/ftplugin/html/autos.vim | 2 +- vim/.vim/ftplugin/python/autos.vim | 20 ++-- vim/.vim/ftplugin/python/ignores.vim | 2 +- vim/.vim/ftplugin/python/importcompl.vim | 77 +------------ vim/.vim/ftplugin/python/lint.vim | 6 + vim/.vim/ftplugin/python/pep8.vim | 22 +--- vim/.vim/ftplugin/python/testname.vim | 26 +---- vim/.vim/ftplugin/python/unused_remover.vim | 4 - vim/.vim/ftplugin/texinfo/autos.vim | 2 +- vim/.vim/plugin/bracketedpaste.vim | 4 + vim/.vim/plugin/buftabline.vim | 30 +---- vim/.vim/plugin/chnglstnav.vim | 11 +- vim/.vim/plugin/ctags.vim | 45 +------- vim/.vim/plugin/defsplit.vim | 106 +----------------- vim/.vim/plugin/exted.vim | 2 +- vim/.vim/plugin/fileline.vim | 3 + vim/.vim/plugin/ggrep.vim | 2 +- vim/.vim/plugin/grep.vim | 2 +- vim/.vim/plugin/lsp.vim | 2 +- vim/.vim/plugin/pastemode.vim | 16 --- vim/.vim/plugin/whereami.vim | 31 +---- vim/.vim/plugin/zshfe.vim | 2 +- vim/.vimrc | 5 +- 40 files changed, 393 insertions(+), 436 deletions(-) create mode 100644 vim/.vim/autoload/buftabline.vim create mode 100644 vim/.vim/autoload/chnglstnav.vim create mode 100644 vim/.vim/autoload/ctags.vim create mode 100644 vim/.vim/autoload/defsplit.vim rename vim/.vim/{plugin/file_line.vim => autoload/fileline.vim} (79%) create mode 100644 vim/.vim/autoload/go/getdoc.vim create mode 100644 vim/.vim/autoload/python/importcompl.vim rename vim/.vim/{ftplugin/python/pylint.vim => autoload/python/lint.vim} (74%) create mode 100644 vim/.vim/autoload/python/pep8.vim create mode 100644 vim/.vim/autoload/python/testname.vim create mode 100644 vim/.vim/autoload/python/unused.vim create mode 100644 vim/.vim/autoload/whereami.vim create mode 100644 vim/.vim/ftplugin/python/lint.vim delete mode 100644 vim/.vim/ftplugin/python/unused_remover.vim create mode 100644 vim/.vim/plugin/bracketedpaste.vim create mode 100644 vim/.vim/plugin/fileline.vim delete mode 100644 vim/.vim/plugin/pastemode.vim diff --git a/vim/.vim/autoload/buftabline.vim b/vim/.vim/autoload/buftabline.vim new file mode 100644 index 0000000..7098d7b --- /dev/null +++ b/vim/.vim/autoload/buftabline.vim @@ -0,0 +1,18 @@ +function! buftabline#do() + let bufsRaw = execute("buffers", "silent") + let bufs = [] + for buf in split(bufsRaw, "\n")[:16] + let leftIdx = stridx(buf, '"') + let rightIdx = strridx(buf, '"') + let filename = substitute(buf[leftIdx + 1 : rightIdx - 1], "%", "%%", "g") + let linenum = split(buf[rightIdx:], " ")[-1] + let attrs = split(buf[:leftIdx-1], '\s\+') + let attrs = map(attrs, 'substitute(v:val, "%", "%%", "g")') + let attrs = (len(attrs) == 1) ? attrs[0] : attrs[0] . ":" . join(attrs[1:], "") + let attrs = "%#TabLine#" . attrs . "%*" + if len(filename) > 20 | let filename = "<" . filename[-(20-1):] | endif + let hl = (match(attrs, "%%") == -1) ? "%#TabLine#:" : "%#TabLineSel#" + let bufs = add(bufs, attrs . hl . filename . ":" . linenum . "%*") + endfor + return join(bufs, " ") +endfunction diff --git a/vim/.vim/autoload/chnglstnav.vim b/vim/.vim/autoload/chnglstnav.vim new file mode 100644 index 0000000..9bdf840 --- /dev/null +++ b/vim/.vim/autoload/chnglstnav.vim @@ -0,0 +1,4 @@ +function! chnglstnav#do(...) + if a:0 == 0 | return | endif + execute "normal " . a:1 . (a:1 > 0 ? "g;" : "g,") +endfunction diff --git a/vim/.vim/autoload/ctags.vim b/vim/.vim/autoload/ctags.vim new file mode 100644 index 0000000..dc6f90e --- /dev/null +++ b/vim/.vim/autoload/ctags.vim @@ -0,0 +1,35 @@ +" Universal Ctags creator +" Maintainer: Sergey Matveev +" License: GNU General Public License version 3 of the License or later +" +" Create "tags" file in your project's root first. +" Then :Ctags LANG to fill it. + +function! ctags#do(lang, onlyCmd, verbose) abort + let dst = tagfiles() + if len(dst) == 0 + echohl WarningMsg | echomsg "No tagfiles" | echohl None + return + endif + let dst = sort(dst, {a, b -> len(a) > len(b) ? 1 : len(a) == len(b) ? 0 : -1})[0] + let src = "/" . join(split(dst, "/")[:-3], "/") + if dst[0] != "/" + let dst = getcwd() . "/.tags/tags" + let src = getcwd() + endif + let cmdline = [ + \"uctags", + \"--languages=" . a:lang, + \"--python-kinds=-i", + \"--c++-kinds=+p", + \"--recurse", + \] + if a:verbose == v:true | let cmdline += ["--verbose"] | endif + let cmdline += ["-f", dst, src] + if a:onlyCmd == v:true + echo join(cmdline, " ") + return + endif + execute "!" . join(cmdline, " ") + if a:verbose != v:true | redraw! | endif +endfunction diff --git a/vim/.vim/autoload/defsplit.vim b/vim/.vim/autoload/defsplit.vim new file mode 100644 index 0000000..a159007 --- /dev/null +++ b/vim/.vim/autoload/defsplit.vim @@ -0,0 +1,92 @@ +" Python function call splitter +" Maintainer: Sergey Matveev +" License: GNU General Public License version 3 of the License or later +" +" This plugin splits Python function call on several lines. +" +" def foobar(self, foo: str, bar: Some[thing, too]) -> None: +" to +" def foobar( +" self, +" foo: str, +" bar: Some[thing, too], +" ) -> None: +" +" foo(bar, baz)[0] +" to +" foo( +" bar, +" baz, +" )[0] +" +" You can un-split it using :Undefsplit command on the line where +" splitting starts. +" +" :Defsplit has optional argument specifying how many opening round +" parenthesis must be skipped. +" :Defsplit 1 on foo(baz(baz(...))) produces +" foo(baz( +" baz(...), +" )) +" +" Also there is :Brsplit command behaving similarly, but it splits other +" types of brackets: "{}", "[]". + +function! s:bracket_find(brs_allowable, line, offset) + let possible = [] + for bracket in a:brs_allowable + let found = stridx(a:line, bracket, a:offset) + if found != -1 | let possible += [found] | endif + endfor + return min(possible) +endfunction + +function! defsplit#do(brs_allowable, single_line_comma, ...) abort + if a:0 == 0 | let skip = 0 | else | let skip = str2nr(a:1) | endif + let shift = get(b:, "defsplit_shift", " ") + let line = getline(".") + for i in range(len(line)) + if line[i] != shift[0] + let prfx = strpart(line, 0, i) + if line[i : i+3] ==# "def " || + \line[i : i+5] ==# "class " || + \line[i : i+9] ==# "async def " + let shift .= shift + endif + break + endif + endfor + let brs = {"(": ")", "[": "]", "{": "}"} + let brfirst = s:bracket_find(a:brs_allowable, line, 0) + let brlast = strridx(line, brs[line[brfirst]]) + while skip > 0 + let brfirst = s:bracket_find(a:brs_allowable, line, brfirst + 1) + let brlast = strridx(line, brs[line[brfirst]], brlast - 1) + let skip -= 1 + endwhile + let [curly, round, squar, outbuf] = [0, 0, 0, ""] + let ready = [strpart(line, 0, brfirst + 1)] + let trailing_comma = 1 + for c in split(line[brfirst + 1 : brlast-1], '\zs') + if c ==# "*" | let trailing_comma = 0 | endif + if outbuf ==# "" && c ==# " " | continue | endif + let outbuf .= c + if c ==# "," && !curly && !round && !squar + let ready = add(ready, prfx . shift . outbuf) + let outbuf = "" + elseif c ==# "[" | let squar += 1 + elseif c ==# "]" | let squar -= 1 + elseif c ==# "(" | let round += 1 + elseif c ==# ")" | let round -= 1 + elseif c ==# "{" | let curly += 1 + elseif c ==# "}" | let curly -= 1 + endif + endfor + if trailing_comma && !(a:single_line_comma == v:true && len(ready) == 1) + let outbuf = outbuf . "," + endif + let ready = add(ready, prfx . shift . outbuf) + let ready = add(ready, prfx . strpart(line, brlast)) + call append(line("."), ready) + normal "_dd +endfunction diff --git a/vim/.vim/plugin/file_line.vim b/vim/.vim/autoload/fileline.vim similarity index 79% rename from vim/.vim/plugin/file_line.vim rename to vim/.vim/autoload/fileline.vim index 8d7c429..193328c 100644 --- a/vim/.vim/plugin/file_line.vim +++ b/vim/.vim/autoload/fileline.vim @@ -1,9 +1,7 @@ " Simplified version of http://www.vim.org/scripts/script.php?script_id=2184 " that does not replace current window -if exists('*gotoline') | finish | endif - -function! s:gotoline() +function! fileline#goto() abort let file = bufname("%") if filereadable(file) | return | endif let names = matchlist(file, '\(.\{-1,}\):\%(\(\d\+\)\%(:\(\d*\):\?\)\?\)\?$') @@ -17,6 +15,3 @@ function! s:gotoline() exec "normal! " . col_num . "|" exec "bdelete " . nr endfunction - -autocmd! BufNewFile *:* nested call s:gotoline() -autocmd! BufRead *:* nested call s:gotoline() diff --git a/vim/.vim/autoload/go/getdoc.vim b/vim/.vim/autoload/go/getdoc.vim new file mode 100644 index 0000000..922c9cd --- /dev/null +++ b/vim/.vim/autoload/go/getdoc.vim @@ -0,0 +1,34 @@ +" Popup documentation of specified object under the cursor +" Requires github.com/zmb3/gogetdoc in the $PATH + +function! go#getdoc#status() + if exists("b:gogetdoc_job") && job_status(b:gogetdoc_job) == "run" | return "GD" | endif + return "" +endfunction + +function! go#getdoc#got(ch) abort + let msgs = [] + while ch_status(a:ch) == "buffered" + let msgs = add(msgs, ch_read(a:ch)) + endwhile + if exists("b:godocid") | call popup_close(b:godocid) | endif + if len(msgs) == 0 + echohl WarningMsg | echomsg "No go doc" | echohl None + return + endif + let msgs = msgs[2:] + let b:godocid = popup_atcursor(msgs[2:-2], + \ {"wrap": 0, "title": msgs[0], "move": "word"}) +endfunction + +function! go#getdoc#do() abort + if exists("b:gogetdoc_job") && job_status(b:gogetdoc_job) == "run" | return | endif + let pos = line2byte(line(".")) + col(".") - 2 + let cmdline = "gogetdoc -pos " . expand("%p") . ":#" . pos + echomsg cmdline + let b:gogetdoc_job = job_start(cmdline, { + \"in_mode": "nl", + \"err_io": "null", + \"close_cb": "go#getdoc#got", + \}) +endfunction diff --git a/vim/.vim/autoload/python/importcompl.vim b/vim/.vim/autoload/python/importcompl.vim new file mode 100644 index 0000000..017d91a --- /dev/null +++ b/vim/.vim/autoload/python/importcompl.vim @@ -0,0 +1,70 @@ +" Python imports insert completion +" Maintainer: Sergey Matveev +" License: GNU General Public License version 3 of the License or later +" +" This plugin is intended for quick import-line insertion. +" For example you have got "from foo.bar import Baz" import somewhere in +" your Git-versioned code. In another file you can write "Baz" and then +" press in insert mode. Completion menu will show you suggestions +" of all import lines from your code containing Baz import. +" +" If you have Pylint or Pyflakes output in quickfix window, containing +" unfedined variables errors, then you can you :call AllImportCompl() +" function. It will go through the quickfix list and find all possible +" imports, sort them and insert under current cursor position. +" +" It uses external "git grep" call and assumes that "canonical" Python +" import format is used (single import per line). +" You can use http://www.git.stargrave.org/?p=pyimportcan.git;a=blob;f=pyimportcan.pl +" utility to convert existing imports to that format. + +let s:git_grep_cmd = "git grep -H --line-number --ignore-case --no-color " + +function! python#importcompl#sortByLen(s1, s2) + if len(a:s1) == len(a:s2) | return a:s1 > a:s2 | endif + return 1 ? len(a:s1) > len(a:s2) : -1 +endfunction + +function! python#importcompl#do() abort + normal diw + let output = system(s:git_grep_cmd . '"^from .* import .*' . @" . '" -- "*.py" "**/*.py"') + let suggestions = [] + for line in split(output, "\n") + if stridx(line, "unused-import") != -1 | continue | endif + let m = matchlist(line, '^.*:\d\+:\(.*\)$') + if len(m) == 0 | continue | endif + call insert(suggestions, m[1]) + endfor + call sort(suggestions, "python#importcompl#sortByLen") + call uniq(suggestions) + call reverse(suggestions) + call complete(col('.'), suggestions) + return '' +endfunction + +function! python#importcompl#all() abort + let output = system(s:git_grep_cmd . '"^from .* import" -- "*.py" "**/*.py"') + let imports = {} + for line in split(output, "\n") + if stridx(line, "unused-import") != -1 | continue | endif + for regexp in [ + \'^.*:\d\+:\(from .* import \(\w\+\).*\)$', + \'^.*:\d\+:\(from .* import \w\+ as \(\w\+\).*\)$', + \] + let m = matchlist(line, regexp) + if len(m) == 0 | break | endif + let imports[m[2]] = m[1] + endfor + endfor + let lines = getloclist(winnr()) + if len(lines) == 0 | let lines = getqflist() | endif + let result = [] + for line in lines + let m = matchlist(line.text, '\(E0602\|F821\).*' . "'" . '\(\w\+\)' . "'$") + if len(m) == 0 || !has_key(imports, m[2]) | continue | endif + call insert(result, imports[m[2]]) + endfor + call sort(result, "i") + call uniq(result) + call append(".", result) +endfunction diff --git a/vim/.vim/ftplugin/python/pylint.vim b/vim/.vim/autoload/python/lint.vim similarity index 74% rename from vim/.vim/ftplugin/python/pylint.vim rename to vim/.vim/autoload/python/lint.vim index f0dd0a7..dade81e 100644 --- a/vim/.vim/ftplugin/python/pylint.vim +++ b/vim/.vim/autoload/python/lint.vim @@ -4,7 +4,6 @@ " " This plugin allows you to asynchronously call pylint. " -" * Add %{LintStatus()} to your statusline to see if pylint is running " * Press to start pylint on current file " * Press to open quickfix window with messages from pylint " * All lines with corresponding pylint existing warning will be highlighted @@ -13,15 +12,12 @@ " Start pylint manually () to force its filling " * After Python file is saved, pylint is automatically started -if exists('g:loaded_pylint') | finish | endif -let g:loaded_pylint = 1 - -function! LintStatus() - if exists("b:lint_job") && job_status(b:lint_job) == "run" | return "LN" | endif +function! python#lint#status() + if exists("b:pylint_job") && job_status(b:pylint_job) == "run" | return "LN" | endif return "" endfunction -function! s:qffill(ch) +function! s:qffill(ch) abort let msgs = [] while ch_status(a:ch) == 'buffered' let msgs = add(msgs, ch_read(a:ch)) @@ -31,7 +27,7 @@ endfunction sign define LN text=LN texthl=Error -function! PylintFinish(ch) +function! python#lint#finish(ch) abort let l:errorformat_bak = &errorformat set errorformat=%f:%l:\ [%t]%m,%f:%l:%m call s:qffill(a:ch) @@ -50,8 +46,10 @@ function! PylintFinish(ch) endif endfunction -function! PylintStart() - if exists("g:pylint_disable") || (exists("b:lint_job") && job_status(b:lint_job) == "run") +function! python#lint#start() abort + if exists("g:pylint_disable") || + \ (exists("b:pylint_job") && + \ job_status(b:pylint_job) == "run") return endif let ignores = [ @@ -67,8 +65,8 @@ function! PylintStart() \"too-many-public-methods", \"no-value-for-parameter", \] - if !exists("g:pylint_linter") | let g:pylint_linter = "pylint" | endif - if g:pylint_linter == "flake8" + let linter = get(g:, "pylint_linter", "pylint") + if linter == "flake8" let cmdline = [ \"flake8", \"--ignore=E501", @@ -76,7 +74,7 @@ function! PylintStart() \"--max-line-length=90", \expand("%p") \] - elseif g:pylint_linter == "pylint" + elseif linter == "pylint" let cmdline = [ \"pylint", \"--jobs=4", @@ -91,9 +89,6 @@ function! PylintStart() echohl WarningMsg | echomsg "Unknown linter specified" | echohl None return endif - let b:lint_job = job_start(cmdline, {"in_mode": "nl", "err_io": "null", "close_cb": "PylintFinish"}) -endfunction() - -map :unlet! g:pylint_disable:call PylintStart() -map [32~ :redraw!:copen -autocmd BufWritePost *.py call PylintStart() + let b:pylint_job = job_start(cmdline, + \ {"in_mode": "nl", "err_io": "null", "close_cb": "python#lint#finish"}) +endfunction diff --git a/vim/.vim/autoload/python/pep8.vim b/vim/.vim/autoload/python/pep8.vim new file mode 100644 index 0000000..389e2ec --- /dev/null +++ b/vim/.vim/autoload/python/pep8.vim @@ -0,0 +1,18 @@ +" PEP8 caller +" Maintainer: Sergey Matveev +" License: GNU General Public License version 3 of the License or later +" +" Call pycodestyle utility and fill quickfix window with its results. + +function! python#pep8#do() abort + set makeprg=PATH=$PATH\ pycodestyle\ --select=E,W\ % + silent make + sign unplace * + let l:id = 1 + for item in getqflist() + execute(':sign place '.l:id.' name=P8 line='.l:item.lnum.' buffer='.l:item.bufnr) + let l:id = l:id + 2 + endfor + redraw! + copen +endfunction diff --git a/vim/.vim/autoload/python/testname.vim b/vim/.vim/autoload/python/testname.vim new file mode 100644 index 0000000..9cc598b --- /dev/null +++ b/vim/.vim/autoload/python/testname.vim @@ -0,0 +1,22 @@ +" Nose-compatible test name preparer +" Maintainer: Sergey Matveev +" License: GNU General Public License version 3 of the License or later +" +" When standing inside TestCase's test method, type t and full +" Python (your.project.tests:TestCaseName.test_method_name) path will be +" copied to clipboard ("*) register. + +function! python#testname#get() abort + normal mm + normal ?.*\s*def .*[Tt]est + normal ^f(Byw + let postfix = @" + normal [[f(Byw + let postfix = @" . "." . postfix + normal `m + let base = join([""] + split(getcwd(), "/")[:-1], "/") + let prefix = substitute(expand("%:p:r")[len(base)+1:], "/", ".", "g") + let name = prefix . ":" . postfix + let @* = name + echomsg name +endfunction diff --git a/vim/.vim/autoload/python/unused.vim b/vim/.vim/autoload/python/unused.vim new file mode 100644 index 0000000..a44a021 --- /dev/null +++ b/vim/.vim/autoload/python/unused.vim @@ -0,0 +1,6 @@ +function! python#unused#remove() abort + call setqflist(filter(getqflist(), {idx, val -> + \ stridx(val.text, "unused-import") != -1 || + \ stridx(val.text, "imported but unused") != -1})) + cdo d +endfunction diff --git a/vim/.vim/autoload/whereami.vim b/vim/.vim/autoload/whereami.vim new file mode 100644 index 0000000..5b5b1d8 --- /dev/null +++ b/vim/.vim/autoload/whereami.vim @@ -0,0 +1,14 @@ +function! whereami#pwdLoad() + let g:whereami_pwdL=trim(system("pwd -L")) + let g:whereami_pwdP=trim(system("pwd -P")) +endfunction + +function! whereami#do(fmt) abort + let fullpath = expand("%:p") + if fullpath[:len(g:whereami_pwdP)-1] ==# g:whereami_pwdP + let fullpath = g:whereami_pwdL . fullpath[len(g:whereami_pwdP):] + endif + let where = printf(a:fmt, fullpath, line(".")) + let @* = where + echomsg where +endfunction diff --git a/vim/.vim/ftdetect/mutt.vim b/vim/.vim/ftdetect/mutt.vim index d106b42..d21c8da 100644 --- a/vim/.vim/ftdetect/mutt.vim +++ b/vim/.vim/ftdetect/mutt.vim @@ -1,4 +1,4 @@ -function! s:KillSignature() +function! s:KillSignature() abort call cursor(1, 1) call search('^[>|] \?-- \?$') if getpos(".")[1] != 1 diff --git a/vim/.vim/ftplugin/c/autos.vim b/vim/.vim/ftplugin/c/autos.vim index 3e821d6..5f264f3 100644 --- a/vim/.vim/ftplugin/c/autos.vim +++ b/vim/.vim/ftplugin/c/autos.vim @@ -1,8 +1,8 @@ setlocal commentstring=//\ %s -abbreviate UCC unsigned char -abbreviate u8 uint8_t * -abbreviate U8 (uint8_t *) +abbreviate UCC unsigned char +abbreviate u8 uint8_t * +abbreviate U8 (uint8_t *) let @e = "ywoassert(pA!= NULL);" setlocal equalprg=cfmt.sh diff --git a/vim/.vim/ftplugin/go/autos.vim b/vim/.vim/ftplugin/go/autos.vim index faad3c9..f241d49 100644 --- a/vim/.vim/ftplugin/go/autos.vim +++ b/vim/.vim/ftplugin/go/autos.vim @@ -1,5 +1,5 @@ -set noexpandtab -let g:defsplit_shift=" " +setlocal noexpandtab +let b:defsplit_shift=" " let @e = "^iif err = A; err != nil {o " let @r = "oif err != nil { }O " diff --git a/vim/.vim/ftplugin/go/fmt.vim b/vim/.vim/ftplugin/go/fmt.vim index 49d20dc..9ed68ad 100644 --- a/vim/.vim/ftplugin/go/fmt.vim +++ b/vim/.vim/ftplugin/go/fmt.vim @@ -30,9 +30,7 @@ if !exists("g:go_fmt_commands") let g:go_fmt_commands = 1 endif -if !exists("g:gofmt_command") - let g:gofmt_command = "goimports" -endif +let g:gofmt_command = get(g:, "gofmt_command", "goimports") if g:go_fmt_commands command! -buffer Fmt call s:GoFormat() diff --git a/vim/.vim/ftplugin/go/gogetdoc.vim b/vim/.vim/ftplugin/go/gogetdoc.vim index 9105258..82496e5 100644 --- a/vim/.vim/ftplugin/go/gogetdoc.vim +++ b/vim/.vim/ftplugin/go/gogetdoc.vim @@ -1,35 +1,3 @@ -" Popup documentation of specified object under the cursor -" Requires github.com/zmb3/gogetdoc in the $PATH - -function! LintStatus() - if exists("b:gogetdoc_job") && job_status(b:gogetdoc_job) == "run" | return "GD" | endif - return "" -endfunction - -function! GoGetDocGot(ch) - let msgs = [] - while ch_status(a:ch) == "buffered" - let msgs = add(msgs, ch_read(a:ch)) - endwhile - if exists("b:godocid") | call popup_close(b:godocid) | endif - if len(msgs) == 0 - echohl WarningMsg | echomsg "No go doc" | echohl None - return - endif - let msgs = msgs[2:] - let b:godocid = popup_atcursor(msgs[2:-2], {"wrap": 0, "title": msgs[0], "move": "word"}) -endfunction - -function! s:GoGetDoc() - if exists("b:gogetdoc_job") && job_status(b:gogetdoc_job) == "run" | return | endif - let pos = line2byte(line(".")) + col(".") - 2 - let cmdline = "gogetdoc -pos " . expand("%p") . ":#" . pos - echomsg cmdline - let b:gogetdoc_job = job_start(cmdline, { - \"in_mode": "nl", - \"err_io": "null", - \"close_cb": "GoGetDocGot", - \}) -endfunction - -nmap :call GoGetDoc() +if exists("*go#getdoc#do") | finish | endif +let b:lint_status_func=function("go#getdoc#status") +nmap :call go#getdoc#do() diff --git a/vim/.vim/ftplugin/html/autos.vim b/vim/.vim/ftplugin/html/autos.vim index 3e073e6..2470c62 100644 --- a/vim/.vim/ftplugin/html/autos.vim +++ b/vim/.vim/ftplugin/html/autos.vim @@ -1 +1 @@ -abbreviate tto F tto Fpass -iabbrev embed import code ; code.interact(local=locals()) -iabbrev kargs *args, **kwargs -iabbrev pyldis # pylint: disable= -iabbrev deff def () -> None:F(i -iabbrev """ """o"2i"kA -nmap ss :set lazyredrawvip:sort u:'<,'>sort i:set nolazyredraw +iabbrev #u # coding: utf-8 +iabbrev tt # type: +iabbrev tti # type: ignore +iabbrev trace import pdb ; pdb.set_trace()pass +iabbrev embed import code ; code.interact(local=locals()) +iabbrev kargs *args, **kwargs +iabbrev pyldis # pylint: disable= +iabbrev deff def () -> None:F(i +iabbrev """ """o"2i"kA +nmap ss :set lazyredrawvip:sort u:'<,'>sort i:set nolazyredraw let @b = ">gvctry:<>k>>kP" let @n = "ddV/except.*: -" License: GNU General Public License version 3 of the License or later -" -" This plugin is intended for quick import-line insertion. -" For example you have got "from foo.bar import Baz" import somewhere in -" your Git-versioned code. In another file you can write "Baz" and then -" press in insert mode. Completion menu will show you suggestions -" of all import lines from your code containing Baz import. -" -" If you have Pylint or Pyflakes output in quickfix window, containing -" unfedined variables errors, then you can you :call AllImportCompl() -" function. It will go through the quickfix list and find all possible -" imports, sort them and insert under current cursor position. -" -" It uses external "git grep" call and assumes that "canonical" Python -" import format is used (single import per line). -" You can use http://www.git.stargrave.org/?p=pyimportcan.git;a=blob;f=pyimportcan.pl -" utility to convert existing imports to that format. - -let s:git_grep_cmd = "git grep -H --line-number --ignore-case --no-color " - -if exists('g:loaded_importcompl') | finish | endif -let g:loaded_importcompl = 1 - -function! SortByLen(s1, s2) - if len(a:s1) == len(a:s2) | return a:s1 > a:s2 | endif - return 1 ? len(a:s1) > len(a:s2) : -1 -endfunction - -function! ImportCompl() - normal diw - let output = system(s:git_grep_cmd . '"^from .* import .*' . @" . '" -- "*.py" "**/*.py"') - let suggestions = [] - for line in split(output, "\n") - if stridx(line, "unused-import") != -1 | continue | endif - let m = matchlist(line, '^.*:\d\+:\(.*\)$') - if len(m) == 0 | continue | endif - call insert(suggestions, m[1]) - endfor - call sort(suggestions, "SortByLen") - call uniq(suggestions) - call reverse(suggestions) - call complete(col('.'), suggestions) - return '' -endfunction - -inoremap =ImportCompl() - -function! AllImportCompl() - let output = system(s:git_grep_cmd . '"^from .* import" -- "*.py" "**/*.py"') - let imports = {} - for line in split(output, "\n") - if stridx(line, "unused-import") != -1 | continue | endif - for regexp in [ - \'^.*:\d\+:\(from .* import \(\w\+\).*\)$', - \'^.*:\d\+:\(from .* import \w\+ as \(\w\+\).*\)$', - \] - let m = matchlist(line, regexp) - if len(m) == 0 | break | endif - let imports[m[2]] = m[1] - endfor - endfor - let lines = getloclist(winnr()) - if len(lines) == 0 | let lines = getqflist() | endif - let result = [] - for line in lines - let m = matchlist(line.text, '\(E0602\|F821\).*' . "'" . '\(\w\+\)' . "'$") - if len(m) == 0 || !has_key(imports, m[2]) | continue | endif - call insert(result, imports[m[2]]) - endfor - call sort(result, "i") - call uniq(result) - call append(".", result) -endfunction +if exists("*python#importcompl#do") | finish | endif +inoremap =python#importcompl#do() diff --git a/vim/.vim/ftplugin/python/lint.vim b/vim/.vim/ftplugin/python/lint.vim new file mode 100644 index 0000000..a7d696a --- /dev/null +++ b/vim/.vim/ftplugin/python/lint.vim @@ -0,0 +1,6 @@ +if exists("*python#lint#start") | finish | endif +let b:lint_status_func=function("python#lint#status") +sign define LN text=LN texthl=Error +map :unlet! g:pylint_disable:call python#lint#start() +map [32~ :redraw!:copen +autocmd BufWritePost *.py call python#lint#start() diff --git a/vim/.vim/ftplugin/python/pep8.vim b/vim/.vim/ftplugin/python/pep8.vim index 7143e75..8340721 100644 --- a/vim/.vim/ftplugin/python/pep8.vim +++ b/vim/.vim/ftplugin/python/pep8.vim @@ -1,21 +1,3 @@ -" PEP8 caller -" Maintainer: Sergey Matveev -" License: GNU General Public License version 3 of the License or later -" -" Call pycodestyle utility and fill quickfix window with its results. - +if exists("*python#pep8#do") | finish | endif sign define P8 text=P8 texthl=Error -function! s:pep8() - set makeprg=PATH=$PATH\ pycodestyle\ --select=E,W\ % - silent make - sign unplace * - let l:id = 1 - for item in getqflist() - execute(':sign place '.l:id.' name=P8 line='.l:item.lnum.' buffer='.l:item.bufnr) - let l:id = l:id + 2 - endfor - redraw! - copen -endfunction - -map :call pep8() +map :call python#pep8#do() diff --git a/vim/.vim/ftplugin/python/testname.vim b/vim/.vim/ftplugin/python/testname.vim index e388f1b..7ec7802 100644 --- a/vim/.vim/ftplugin/python/testname.vim +++ b/vim/.vim/ftplugin/python/testname.vim @@ -1,24 +1,2 @@ -" Nose-compatible test name preparer -" Maintainer: Sergey Matveev -" License: GNU General Public License version 3 of the License or later -" -" When standing inside TestCase's test method, type t and full -" Python (your.project.tests:TestCaseName.test_method_name) path will be -" copied to clipboard ("*) register. - -function! TestName() - normal mm - normal ?.*\s*def .*[Tt]est - normal ^f(Byw - let postfix = @" - normal [[f(Byw - let postfix = @" . "." . postfix - normal `m - let base = join([""] + split(getcwd(), "/")[:-1], "/") - let prefix = substitute(expand("%:p:r")[len(base)+1:], "/", ".", "g") - let name = prefix . ":" . postfix - let @* = name - echomsg name -endfunction - -nmap t :call TestName() +if exists("*python#testname#get") | finish | endif +nmap t :call python#testname#get() diff --git a/vim/.vim/ftplugin/python/unused_remover.vim b/vim/.vim/ftplugin/python/unused_remover.vim deleted file mode 100644 index 5e6b1ba..0000000 --- a/vim/.vim/ftplugin/python/unused_remover.vim +++ /dev/null @@ -1,4 +0,0 @@ -function! UnusedImportsRemover() - call setqflist(filter(getqflist(), "stridx(v:val.text, \"unused-import\") != -1 || stridx(v:val.text, \"imported but unused\") != -1")) - cdo d -endfunction diff --git a/vim/.vim/ftplugin/texinfo/autos.vim b/vim/.vim/ftplugin/texinfo/autos.vim index 0f57cfe..b7664fd 100644 --- a/vim/.vim/ftplugin/texinfo/autos.vim +++ b/vim/.vim/ftplugin/texinfo/autos.vim @@ -1,2 +1,2 @@ -abbreviate \t @tab +abbreviate \t @tab setlocal commentstring=@c\ %s diff --git a/vim/.vim/plugin/bracketedpaste.vim b/vim/.vim/plugin/bracketedpaste.vim new file mode 100644 index 0000000..a80617f --- /dev/null +++ b/vim/.vim/plugin/bracketedpaste.vim @@ -0,0 +1,4 @@ +let &t_BE = "\e[?2004h" +let &t_BD = "\e[?2004l" +exec "set t_PS=\e[200~" +exec "set t_PE=\e[201~" diff --git a/vim/.vim/plugin/buftabline.vim b/vim/.vim/plugin/buftabline.vim index 4fb1318..60c067b 100644 --- a/vim/.vim/plugin/buftabline.vim +++ b/vim/.vim/plugin/buftabline.vim @@ -1,29 +1,3 @@ -if exists('*BufTabLine') | finish | endif - -function! s:BufTabline() - redir => bufsRaw - silent buffers - redir END - let bufs = [] - for buf in split(bufsRaw, "\n")[:16] - let leftIdx = stridx(buf, '"') - let rightIdx = strridx(buf, '"') - let filename = substitute(buf[leftIdx + 1 : rightIdx - 1], "%", "%%", "g") - let linenum = split(buf[rightIdx:], " ")[-1] - let attrs = split(buf[:leftIdx-1], '\s\+') - let attrs = map(attrs, 'substitute(v:val, "%", "%%", "g")') - let attrs = (len(attrs) == 1) ? attrs[0] : attrs[0] . ":" . join(attrs[1:], "") - let attrs = "%#TabLine#" . attrs . "%*" - if len(filename) > 20 | let filename = "<" . filename[-(20-1):] | endif - let hl = (match(attrs, "%%") == -1) ? "%#TabLine#:" : "%#TabLineSel#" - let bufs = add(bufs, attrs . hl . filename . ":" . linenum . "%*") - endfor - return join(bufs, " ") -endfunction - -function! BufTabline() - return s:BufTabline() -endfunction - +if exists("*buftabline#do") | finish | endif set showtabline=2 -set tabline=%!BufTabline() +set tabline=%!buftabline#do() diff --git a/vim/.vim/plugin/chnglstnav.vim b/vim/.vim/plugin/chnglstnav.vim index dac9e95..699fdd0 100644 --- a/vim/.vim/plugin/chnglstnav.vim +++ b/vim/.vim/plugin/chnglstnav.vim @@ -1,9 +1,2 @@ -if exists('*Chng') | finish | endif - -function! s:Chng(...) - if a:0 == 0 | return | endif - execute "normal " . a:1 . (a:1 > 0 ? "g;" : "g,") -endfunction - -command! -nargs=? Chng call s:Chng() -nmap :changes:Chng +if exists("*chnglstnav#do") | finish | endif +nmap :changes:call chnglstnav#do() diff --git a/vim/.vim/plugin/ctags.vim b/vim/.vim/plugin/ctags.vim index 268b27e..644e50a 100644 --- a/vim/.vim/plugin/ctags.vim +++ b/vim/.vim/plugin/ctags.vim @@ -1,41 +1,4 @@ -" Universal Ctags creator -" Maintainer: Sergey Matveev -" License: GNU General Public License version 3 of the License or later -" -" Create "tags" file in your project's root first. -" Then :Ctags LANG to fill it. - -if exists('*Ctags') | finish | endif - -function! s:Ctags(lang, onlyCmd, verbose) - let dst = tagfiles() - if len(dst) == 0 - echohl WarningMsg | echomsg "No tagfiles" | echohl None - return - endif - let dst = sort(dst, {a, b -> len(a) > len(b) ? 1 : len(a) == len(b) ? 0 : -1})[0] - let src = "/" . join(split(dst, "/")[:-3], "/") - if dst[0] != "/" - let dst = getcwd() . "/.tags/tags" - let src = getcwd() - endif - let cmdline = [ - \"uctags", - \"--languages=" . a:lang, - \"--python-kinds=-i", - \"--c++-kinds=+p", - \"--recurse", - \] - if a:verbose == v:true | let cmdline += ["--verbose"] | endif - let cmdline += ["-f", dst, src] - if a:onlyCmd == v:true - echo join(cmdline, " ") - return - endif - execute "!" . join(cmdline, " ") - if a:verbose != v:true | redraw! | endif -endfunction - -command! -nargs=1 Ctags silent call s:Ctags(, v:false, v:false) -command! -nargs=1 Ctagsv silent call s:Ctags(, v:true, v:false) -command! -nargs=1 Ctagscmd call s:Ctags(, v:true, v:true) +if exists("*ctags#do") | finish | endif +command! -nargs=1 Ctags silent call ctags#do(, v:false, v:false) +command! -nargs=1 Ctagsv silent call ctags#do(, v:true, v:false) +command! -nargs=1 Ctagscmd call ctags#do(, v:true, v:true) diff --git a/vim/.vim/plugin/defsplit.vim b/vim/.vim/plugin/defsplit.vim index 7beb26b..876599d 100644 --- a/vim/.vim/plugin/defsplit.vim +++ b/vim/.vim/plugin/defsplit.vim @@ -1,102 +1,6 @@ -" Python function call splitter -" Maintainer: Sergey Matveev -" License: GNU General Public License version 3 of the License or later -" -" This plugin splits Python function call on several lines. -" -" def foobar(self, foo: str, bar: Some[thing, too]) -> None: -" to -" def foobar( -" self, -" foo: str, -" bar: Some[thing, too], -" ) -> None: -" -" foo(bar, baz)[0] -" to -" foo( -" bar, -" baz, -" )[0] -" -" You can un-split it using :Undefsplit command on the line where -" splitting starts. -" -" :Defsplit has optional argument specifying how many opening round -" parenthesis must be skipped. -" :Defsplit 1 on foo(baz(baz(...))) produces -" foo(baz( -" baz(...), -" )) -" -" Also there is :Brsplit command behaving similarly, but it splits other -" types of brackets: "{}", "[]". - -if !exists("g:defsplit_shift") | let g:defsplit_shift = " " | endif -if exists('*Defsplit') | finish | endif - -function! s:bracket_find(brs_allowable, line, offset) - let possible = [] - for bracket in a:brs_allowable - let found = stridx(a:line, bracket, a:offset) - if found != -1 | let possible += [found] | endif - endfor - return min(possible) -endfunction - -function! s:Defsplit(brs_allowable, single_line_comma, ...) - if a:0 == 0 | let skip = 0 | else | let skip = str2nr(a:1) | endif - let shift = g:defsplit_shift - let line = getline(".") - for i in range(len(line)) - if line[i] != g:defsplit_shift[0] - let prfx = strpart(line, 0, i) - if line[i : i+3] ==# "def " || - \line[i : i+5] ==# "class " || - \line[i : i+9] ==# "async def " - let shift .= shift - endif - break - endif - endfor - let brs = {"(": ")", "[": "]", "{": "}"} - let brfirst = s:bracket_find(a:brs_allowable, line, 0) - let brlast = strridx(line, brs[line[brfirst]]) - while skip > 0 - let brfirst = s:bracket_find(a:brs_allowable, line, brfirst + 1) - let brlast = strridx(line, brs[line[brfirst]], brlast - 1) - let skip -= 1 - endwhile - let [curly, round, squar, outbuf] = [0, 0, 0, ""] - let ready = [strpart(line, 0, brfirst + 1)] - let trailing_comma = 1 - for c in split(line[brfirst + 1 : brlast-1], '\zs') - if c ==# "*" | let trailing_comma = 0 | endif - if outbuf ==# "" && c ==# " " | continue | endif - let outbuf .= c - if c ==# "," && !curly && !round && !squar - let ready = add(ready, prfx . shift . outbuf) - let outbuf = "" - elseif c ==# "[" | let squar += 1 - elseif c ==# "]" | let squar -= 1 - elseif c ==# "(" | let round += 1 - elseif c ==# ")" | let round -= 1 - elseif c ==# "{" | let curly += 1 - elseif c ==# "}" | let curly -= 1 - endif - endfor - if trailing_comma && !(a:single_line_comma == v:true && len(ready) == 1) - let outbuf = outbuf . "," - endif - let ready = add(ready, prfx . shift . outbuf) - let ready = add(ready, prfx . strpart(line, brlast)) - call append(line("."), ready) - normal "_dd -endfunction - -command! -nargs=? Defsplit call s:Defsplit(["("], v:false, ) -command! -nargs=? Brsplit call s:Defsplit(["(", "[", "{"], v:false, ) -command! -nargs=? Defsplits call s:Defsplit(["("], v:true, ) -command! -nargs=? Brsplits call s:Defsplit(["(", "[", "{"], v:true, ) - +if exists("*defsplit#do") | finish | endif +command! -nargs=? Defsplit call defsplit#do(["("], v:false, ) +command! -nargs=? Brsplit call defsplit#do(["(", "[", "{"], v:false, ) +command! -nargs=? Defsplits call defsplit#do(["("], v:true, ) +command! -nargs=? Brsplits call defsplit#do(["(", "[", "{"], v:true, ) command! Undefsplit normal ^v%$J:keepp s/^\(.*\)\([([{]\) \(.*[^,]\),\?\([)\]}]\)\(.*\)$/\1\2\3\4\5:keepp s/, \?\([)\]}]\+\)$/\1/e: diff --git a/vim/.vim/plugin/exted.vim b/vim/.vim/plugin/exted.vim index 3833a65..e24524e 100644 --- a/vim/.vim/plugin/exted.vim +++ b/vim/.vim/plugin/exted.vim @@ -1,4 +1,4 @@ -if exists('*exted') | finish | endif +if exists("*exted") | finish | endif function! s:exted(ext) execute "edit %<." . a:ext diff --git a/vim/.vim/plugin/fileline.vim b/vim/.vim/plugin/fileline.vim new file mode 100644 index 0000000..62bf31a --- /dev/null +++ b/vim/.vim/plugin/fileline.vim @@ -0,0 +1,3 @@ +if exists("*fileline#goto") | finish | endif +autocmd! BufNewFile *:* nested call fileline#goto() +autocmd! BufRead *:* nested call fileline#goto() diff --git a/vim/.vim/plugin/ggrep.vim b/vim/.vim/plugin/ggrep.vim index 8a9bd8a..4c71b70 100644 --- a/vim/.vim/plugin/ggrep.vim +++ b/vim/.vim/plugin/ggrep.vim @@ -1,4 +1,4 @@ -if exists('*Vmg') | finish | endif +if exists("*Vmg") | finish | endif function! s:Vmg(pattern) silent execute 'Ggrep "' . a:pattern . '"' diff --git a/vim/.vim/plugin/grep.vim b/vim/.vim/plugin/grep.vim index f7a5f12..03903d7 100644 --- a/vim/.vim/plugin/grep.vim +++ b/vim/.vim/plugin/grep.vim @@ -1,4 +1,4 @@ -if exists('*Vim') | finish | endif +if exists("*Vim") | finish | endif function! s:Vim(pattern) set grepprg=grep\ -Rns\ --binary-files=without-match\ --exclude-dir=.git\ --exclude-dir=.tags\ $*\ /dev/null\ . diff --git a/vim/.vim/plugin/lsp.vim b/vim/.vim/plugin/lsp.vim index d8c9167..bcef272 100644 --- a/vim/.vim/plugin/lsp.vim +++ b/vim/.vim/plugin/lsp.vim @@ -1,4 +1,4 @@ -if exists('*on_lsp_buffer_enabled') | finish | endif +if exists("*on_lsp_buffer_enabled") | finish | endif let g:lsp_auto_enable = 1 diff --git a/vim/.vim/plugin/pastemode.vim b/vim/.vim/plugin/pastemode.vim deleted file mode 100644 index 78f42a0..0000000 --- a/vim/.vim/plugin/pastemode.vim +++ /dev/null @@ -1,16 +0,0 @@ -if exists("g:loaded_mein_pastemode") | finish | endif -let g:loaded_mein_pastemode = 1 - -if &term =~ "screen.*" - let &t_ti = &t_ti . "\e[?2004h" - let &t_te = "\e[?2004l" . &t_te - function! XTermPasteBegin(ret) - set pastetoggle=[201~ - set paste - return a:ret - endfunction - map [200~ XTermPasteBegin("i") - imap [200~ XTermPasteBegin("") - cmap [200~ - cmap [201~ -endif diff --git a/vim/.vim/plugin/whereami.vim b/vim/.vim/plugin/whereami.vim index a6d5336..3398134 100644 --- a/vim/.vim/plugin/whereami.vim +++ b/vim/.vim/plugin/whereami.vim @@ -1,27 +1,4 @@ -if exists('*pwdLoad') | finish | endif - -function! s:pwdLoad() - let g:mein_pwdL=trim(system("pwd -L")) - let g:mein_pwdP=trim(system("pwd -P")) -endfunction - -autocmd VimEnter * call s:pwdLoad() - -function! s:WhereAmI(fmt) - let fullpath = expand("%:p") - if fullpath[:len(g:mein_pwdP)-1] ==# g:mein_pwdP - let fullpath = g:mein_pwdL . fullpath[len(g:mein_pwdP):] - endif - if a:fmt == "gnu" - let where = fullpath . ":" . line(".") - elseif a:fmt == "lldb" - let where = "breakpoint set --file " . fullpath . " --line " . line(".") - else - let where = "unknown fmt" - endif - let @* = where - echomsg where -endfunction - -nmap w :call WhereAmI("gnu") -nmap W :call WhereAmI("lldb") +if exists("*whereami#pwdLoad") | finish | endif +autocmd VimEnter * call whereami#pwdLoad() +nmap w :call whereami#do("%s:%d") +nmap W :call whereami#do("breakpoint set --file %s --line %d") diff --git a/vim/.vim/plugin/zshfe.vim b/vim/.vim/plugin/zshfe.vim index cd9cc07..af3540b 100644 --- a/vim/.vim/plugin/zshfe.vim +++ b/vim/.vim/plugin/zshfe.vim @@ -2,7 +2,7 @@ " Maintainer: Sergey Matveev " License: GNU General Public License version 3 of the License or later -if exists('*zshfe') | finish | endif +if exists("*zshfe") | finish | endif if !exists("g:zshfe_path") | let g:zshfe_path=expand("~/.vim/plugin/zshfe.zsh") | endif function! s:zshfe(query, opencmd) diff --git a/vim/.vimrc b/vim/.vimrc index 66b729b..56b9a21 100644 --- a/vim/.vimrc +++ b/vim/.vimrc @@ -73,6 +73,7 @@ highlight CursorColumn ctermfg=cyan ctermbg=red " }}} " Statusline {{{ +let LintStatus = {-> exists("b:lint_status_func") ? b:lint_status_func() : ""} set laststatus=2 set statusline=%F\ %m%r%h%w%k set statusline+=%{len(getqflist())?'[Q]':''} @@ -85,10 +86,6 @@ set statusline+=%#Todo#%c%V:0x%B set statusline+=%#Comment#%o set statusline+=%#Error#%{LintStatus()} set statusline+=%*\ %P - -function! LintStatus() " it is overrided in ftplugins - return "" -endfunction " }}} " View saving {{{ -- 2.44.0