--- /dev/null
+set commentstring=//\ %s
--- /dev/null
+vim9script
+
+export def Do(motion: string)
+ var saved = @/
+ mark '
+ execute motion
+ call histdel("/", -1)
+ @/ = saved
+enddef
--- /dev/null
+vim9script
+
+export def KillSignature()
+ cursor(1, 1)
+ search('^[>|] \?-- \?$')
+ if getpos(".")[1] != 1
+ normal d}
+ endif
+enddef
-autocmd BufNewFile,BufRead *.hjson setlocal shiftwidth=2
-autocmd BufNewFile,BufRead *.hjson setlocal commentstring=#\ %s
+autocmd BufNewFile,BufRead *.hjson set filetype=hjson
-function! s:KillSignature() abort
- call cursor(1, 1)
- call search('^[>|] \?-- \?$')
- if getpos(".")[1] != 1
- normal d}
- endif
-endfunction
-
-autocmd BufRead /tmp/mutt-* call s:KillSignature()
-autocmd BufRead /tmp/mutt-* setlocal textwidth=72
-autocmd BufRead /tmp/mutt-* setlocal commentstring=>%s
-autocmd BufRead /tmp/mutt-* silent %substitute /^> */>/e | set nohlsearch
+autocmd BufRead,BufNewFile /tmp/mutt-* set filetype=mutt
+++ /dev/null
-autocmd BufNewFile,BufRead *.tex abbreviate framedo \begin{frame}<CR>\frametitle{TODO}<CR>\end{frame}<ESC>k>>wwlcw
-autocmd BufNewFile,BufRead *.tex abbreviate itemdo \begin{itemize}<CR>\item <CR>\end{itemize}<ESC>k>>$a
-autocmd BufNewFile,BufRead *.tex abbreviate cnter \begin{center}<CR>\end{center}<ESC>k$o
-set commentstring=//\ %s
let @e = "ywoassert(\epA!= NULL);\e"
nmap [cl O// clang-format off<ESC>
nmap ]cl o// clang-format on<ESC>
-nnoremap <silent> <buffer> ]] :call <SID>Go_jump('/^\(func\\|type\)')<cr>
-nnoremap <silent> <buffer> [[ :call <SID>Go_jump('?^\(func\\|type\)')<cr>
-nnoremap <silent> <buffer> ]m :call <SID>Go_jump('/^\s*\(func\\|type\)')<cr>
-nnoremap <silent> <buffer> [m :call <SID>Go_jump('?^\s*\(func\\|type\)')<cr>
-
-if exists('*<SID>Go_jump') | finish | endif
-
-fun! <SID>Go_jump(motion) range
- let cnt = v:count1
- let save = @/ " save last search pattern
- mark '
- while cnt > 0
- silent! exe a:motion
- let cnt = cnt - 1
- endwhile
- call histdel('/', -1)
- let @/ = save " restore last search pattern
-endfun
+vim9script
+if exists("*go#jump#Do") | finish | endif
+nnoremap <silent> <buffer> ]] :call go#jump#Do(':/^\(func\\|type\)')<CR>
+nnoremap <silent> <buffer> [[ :call go#jump#Do(':?^\(func\\|type\)')<CR>
+nnoremap <silent> <buffer> ]m :call go#jump#Do(':/^\s*\(func\\|type\)')<CR>
+nnoremap <silent> <buffer> [m :call go#jump#Do(':?^\s*\(func\\|type\)')<CR>
--- /dev/null
+set shiftwidth=2
+set commentstring=#\ %s
--- /dev/null
+vim9script
+mutt#KillSignature()
+set textwidth=72
+set commentstring=>%s
+set syntax=mail
+silent :%substitute /^> */>/e | set nohlsearch
--- /dev/null
+abbreviate framedo \begin{frame}<CR>\frametitle{TODO}<CR>\end{frame}<ESC>k>>wwlcw
+abbreviate itemdo \begin{itemize}<CR>\item <CR>\end{itemize}<ESC>k>>$a
+abbreviate cnter \begin{center}<CR>\end{center}<ESC>k$o
iabbrev <buffer> pyldis # pylint: disable=
iabbrev <buffer> deff def () -> None:<ESC>F(i
nmap <buffer> <leader>ss :set lazyredraw<CR>vip:sort u<CR>:'<,'>sort i<CR>:set nolazyredraw<CR>
-let @b = ">gvctry:\e<<oexcept Exception as err:\rbreakpoint()\rpass\e>>k>>kP"
-let @n = "ddV/except.*:\r<n3dd"
syntax keyword pythonStatement match case
--- /dev/null
+vim9script
+@b = ">gvctry:\e<<oexcept Exception as err:\rbreakpoint()\rpass\e>>k>>kP"
+@n = "ddV/except.*:\r<n3dd"
--- /dev/null
+set commentstring=#%s
+abbreviate <buffer> v9 vim9script
-" something that won't be met anywhere
-let s:sep = "₀◎○ë"
+vim9script
-function! align#do(first, last, sep) abort
- let in = []
- for n in range(a:first, a:last)
- let in = add(in, substitute(getline(n), a:sep, "\t" . s:sep, "g"))
+const Sep = "₀◎○ë" # something that won't be met anywhere
+
+export def Do(first: number, last: number, sep: string)
+ var in: list<string>
+ for n in range(first, last)
+ in = add(in, substitute(getline(n), sep, "\t" .. Sep, "g"))
endfor
- let out = systemlist("column -t -s \"\t\"", add(in, ""))
- for n in range(a:first, a:last)
- call setline(n, substitute(out[n - a:first], " " . s:sep, escape(a:sep, "&"), "g"))
+ var out = systemlist("column -t -s \"\t\"", add(in, ""))
+ for n in range(first, last)
+ setline(n, substitute(out[n - first], " " .. Sep, escape(sep, "&"), "g"))
endfor
-endfunction
+enddef
-if exists("*align#do") | finish | endif
-command! -nargs=1 -range Align call align#do(<line1>, <line2>, <f-args>)
+if exists("*align#Do") | finish | endif
+command! -nargs=1 -range Align call align#Do(<line1>, <line2>, <f-args>)
-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 . "%*")
+vim9script
+
+export def Do(): string
+ var bufsRaw = execute("buffers", "silent")
+ var bufs: list<string>
+ var leftIdx: number
+ var rightIdx: number
+ var filename: string
+ var linenum: string
+ var attrs: list<string>
+ var attr: string
+ var hl: string
+ for buf in split(bufsRaw, "\n")[ : 16]
+ leftIdx = stridx(buf, '"')
+ rightIdx = strridx(buf, '"')
+ filename = substitute(buf[leftIdx + 1 : rightIdx - 1], "%", "%%", "g")
+ linenum = split(buf[rightIdx : ], " ")[-1]
+ attrs = split(buf[ : leftIdx - 1], '\s\+')
+ attrs = map(attrs, 'substitute(v:val, "%", "%%", "g")')
+ attr = (len(attrs) == 1) ? attrs[0] : attrs[0] .. ":" .. join(attrs[1 :], "")
+ attr = "%#TabLine#" .. attr .. "%*"
+ if len(filename) > 20 | filename = "<" .. filename[-(20 - 1) :] | endif
+ hl = (match(attr, "%%") == -1) ? "%#TabLine#:" : "%#TabLineSel#"
+ bufs = add(bufs, attr .. hl .. filename .. ":" .. linenum .. "%*")
endfor
return join(bufs, " ")
-endfunction
+enddef
-if exists("*buftabline#do") | finish | endif
+if exists("*buftabline#Do") | finish | endif
set showtabline=2
-set tabline=%!buftabline#do()
+set tabline=%!buftabline#Do()
-function! chnglstnav#do(...)
- if a:0 == 0 | return | endif
- execute "normal " . a:1 . (a:1 > 0 ? "g;" : "g,")
-endfunction
+vim9script
+
+export def Do(...args: list<number>)
+ if len(args) == 0 | return | endif
+ execute "normal " .. args[0] .. (args[0] > 0 ? "g;" : "g,")
+enddef
-if exists("*chnglstnav#do") | finish | endif
-nmap <End> :changes<CR>:call chnglstnav#do()<Left>
+if exists("*chnglstnav#Do") | finish | endif
+nmap <End> :changes<CR>:call chnglstnav#Do()<Left>
-" Universal Ctags creator
-" Maintainer: Sergey Matveev <stargrave@stargrave.org>
-" 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.
+vim9script
-function! ctags#do(lang, onlyCmd, verbose) abort
- let dst = tagfiles()
- if len(dst) == 0
+# Universal Ctags creator
+# Maintainer: Sergey Matveev <stargrave@stargrave.org>
+# 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.
+
+export def Do(lang: string, onlyCmd: bool, verbose: bool)
+ var dsts = tagfiles()
+ if len(dsts) == 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], "/")
+ var dst = sort(dsts, (a, b) => len(a) > len(b) ? 1 : len(a) == len(b) ? 0 : -1)[0]
+ var src = "/" .. join(split(dst, "/")[: -3], "/")
if dst[0] != "/"
- let dst = getcwd() . "/.tags/tags"
- let src = getcwd()
+ dst = getcwd() .. "/.tags/tags"
+ 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
+ var cmdline = [
+ "uctags",
+ "--languages=" .. lang,
+ "--python-kinds=-i",
+ "--c++-kinds=+p",
+ "--recurse",
+ ]
+ if verbose == v:true | cmdline += ["--verbose"] | endif
+ cmdline += ["-f", dst, src]
+ if onlyCmd == v:true
echo join(cmdline, " ")
return
endif
- execute "!" . join(cmdline, " ")
- if a:verbose != v:true | redraw! | endif
-endfunction
+ execute "!" .. join(cmdline, " ")
+ if verbose != v:true | redraw! | endif
+enddef
-if exists("*ctags#do") | finish | endif
-command! -nargs=1 Ctags silent call ctags#do(<f-args>, v:false, v:false)
-command! -nargs=1 Ctagsv silent call ctags#do(<f-args>, v:true, v:false)
-command! -nargs=1 Ctagscmd call ctags#do(<f-args>, v:true, v:true)
+if exists("*ctags#Do") | finish | endif
+command! -nargs=1 Ctags silent call ctags#Do(<f-args>, v:false, v:false)
+command! -nargs=1 Ctagsv silent call ctags#Do(<f-args>, v:true, v:false)
+command! -nargs=1 Ctagscmd call ctags#Do(<f-args>, v:true, v:true)
-" Python function call splitter
-" Maintainer: Sergey Matveev <stargrave@stargrave.org>
-" 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: "{}", "[]".
+vim9script
-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
+# Python function call splitter
+# Maintainer: Sergey Matveev <stargrave@stargrave.org>
+# 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: "{}", "[]".
+
+def BracketFind(brsAllowable: list<string>, line: string, offset: number): number
+ var possible: list<number>
+ var found: number
+ for bracket in brsAllowable
+ found = stridx(line, bracket, offset)
+ if found != -1 | possible += [found] | endif
endfor
return min(possible)
-endfunction
+enddef
+
+const Brs = {"(": ")", "[": "]", "{": "}"}
-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(".")
+export def Do(brsAllowable: list<string>, singleLineComma: bool, ...args: list<number>)
+ var skip = len(args) == 0 ? 0 : args[1]
+ var shift = get(b:, "defsplit_shift", " ")
+ var line = getline(".")
+ var prfx: string
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
+ prfx = strpart(line, 0, i)
+ if line[i : i + 3] ==# "def " ||
+ line[i : i + 5] ==# "class " ||
+ line[i : i + 9] ==# "async def "
+ 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]])
+ var brfirst = BracketFind(brsAllowable, line, 0)
+ var 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
+ brfirst = BracketFind(brsAllowable, line, brfirst + 1)
+ brlast = strridx(line, Brs[line[brfirst]], brlast - 1)
+ 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
+ var [curly, round, squar, outbuf] = [0, 0, 0, ""]
+ var ready = [strpart(line, 0, brfirst + 1)]
+ var trailingComma = v:true
+ for c in split(line[brfirst + 1 : brlast - 1], '\zs')
+ if c ==# "*" | trailingComma = v:false | endif
if outbuf ==# "" && c ==# " " | continue | endif
- let outbuf .= c
+ 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
+ ready = add(ready, prfx .. shift .. outbuf)
+ outbuf = ""
+ elseif c ==# "[" | squar += 1
+ elseif c ==# "]" | squar -= 1
+ elseif c ==# "(" | round += 1
+ elseif c ==# ")" | round -= 1
+ elseif c ==# "{" | curly += 1
+ elseif c ==# "}" | curly -= 1
endif
endfor
- if trailing_comma && !(a:single_line_comma == v:true && len(ready) == 1)
- let outbuf = outbuf . ","
+ if trailingComma && !(singleLineComma == v:true && len(ready) == 1)
+ outbuf = outbuf .. ","
endif
- let ready = add(ready, prfx . shift . outbuf)
- let ready = add(ready, prfx . strpart(line, brlast))
- call append(line("."), ready)
+ ready = add(ready, prfx .. shift .. outbuf)
+ ready = add(ready, prfx .. strpart(line, brlast))
+ append(line("."), ready)
normal "_dd
-endfunction
+enddef
-if exists("*defsplit#do") | finish | endif
-command! -nargs=? Defsplit call defsplit#do(["("], v:false, <f-args>)
-command! -nargs=? Brsplit call defsplit#do(["(", "[", "{"], v:false, <f-args>)
-command! -nargs=? Defsplits call defsplit#do(["("], v:true, <f-args>)
-command! -nargs=? Brsplits call defsplit#do(["(", "[", "{"], v:true, <f-args>)
+if exists("*defsplit#Do") | finish | endif
+command! -nargs=? Defsplit call defsplit#Do(["("], v:false, <f-args>)
+command! -nargs=? Brsplit call defsplit#Do(["(", "[", "{"], v:false, <f-args>)
+command! -nargs=? Defsplits call defsplit#Do(["("], v:true, <f-args>)
+command! -nargs=? Brsplits call defsplit#Do(["(", "[", "{"], v:true, <f-args>)
command! Undefsplit normal ^v%$J:keepp s/^\(.*\)\([([{]\) \(.*[^,]\),\?\([)\]}]\)\(.*\)$/\1\2\3\4\5<CR>:keepp s/, \?\([)\]}]\+\)$/\1/e<CR>:<CR>
-" Simplified version of http://www.vim.org/scripts/script.php?script_id=2184
-" that does not replace current window
+vim9script
-function! fileline#goto() abort
- let file = bufname("%")
+# Simplified version of http://www.vim.org/scripts/script.php?script_id=2184
+# that does not replace current window
+
+export def Goto()
+ var file = bufname("%")
if filereadable(file) | return | endif
- let names = matchlist(file, '\(.\{-1,}\):\%(\(\d\+\)\%(:\(\d*\):\?\)\?\)\?$')
+ var names = matchlist(file, '\(.\{-1,}\):\%(\(\d\+\)\%(:\(\d*\):\?\)\?\)\?$')
if empty(names) | return | endif
- let file_name = names[1]
- let line_num = names[2] == "" ? "0" : names[2]
- let col_num = names[3] == "" ? "0" : names[3]
- if !filereadable(file_name) | return | endif
- let nr = bufnr("%")
- exec "keepalt edit +" . line_num . " " . file_name
- exec "normal! " . col_num . "|"
- exec "bdelete " . nr
-endfunction
+ var fileName = names[1]
+ var lineNum = names[2] == "" ? "0" : names[2]
+ var colNum = names[3] == "" ? "0" : names[3]
+ if !filereadable(fileName) | return | endif
+ var nr = bufnr("%")
+ execute "keepalt edit +" .. lineNum .. " " .. fileName
+ execute "normal! " .. colNum .. "|"
+ execute "bdelete " .. nr
+enddef
-if exists("*fileline#goto") | finish | endif
-autocmd! BufNewFile *:* nested call fileline#goto()
-autocmd! BufRead *:* nested call fileline#goto()
+if exists("*fileline#Goto") | finish | endif
+autocmd! BufNewFile *:* nested call fileline#Goto()
+autocmd! BufRead *:* nested call fileline#Goto()
-" Popup documentation of specified object under the cursor
-" Requires github.com/zmb3/gogetdoc in the $PATH
+vim9script
-function! go#getdoc#status()
+# Popup documentation of specified object under the cursor
+# Requires github.com/zmb3/gogetdoc in the $PATH
+
+export def Status(): string
if exists("b:gogetdoc_job") && job_status(b:gogetdoc_job) == "run" | return "GD" | endif
return ""
-endfunction
+enddef
-function! go#getdoc#got(ch) abort
- let msgs = []
- while ch_status(a:ch) == "buffered"
- let msgs = add(msgs, ch_read(a:ch))
+export def Got(ch: channel)
+ var msgs: list<string>
+ while ch_status(ch) == "buffered"
+ msgs = add(msgs, ch_read(ch))
endwhile
- if exists("b:godocid") | call popup_close(b:godocid) | endif
+ if exists("b:godocid") | 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
+ msgs = msgs[2 :]
+ b:godocid = popup_atcursor(msgs[2 : -2],
+ {"wrap": 0, "title": msgs[0], "move": "word"})
+enddef
-function! go#getdoc#do() abort
+export def Do()
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
+ var pos = line2byte(line(".")) + col(".") - 2
+ var 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
+ b:gogetdoc_job = job_start(cmdline, {
+ "in_mode": "nl",
+ "err_io": "null",
+ "close_cb": "go#getdoc#Got",
+ })
+enddef
-if exists("*go#getdoc#do") | finish | endif
-let b:mein_status_func=function("go#getdoc#status")
-nmap <buffer> <silent> <CR> :call go#getdoc#do()<CR>
+if exists("*go#getdoc#Do") | finish | endif
+let b:mein_status_func=function("go#getdoc#Status")
+nmap <buffer> <silent> <CR> :call go#getdoc#Do()<CR>
-function! nonhumanhl#load()
+vim9script
+export def Load()
highlight nonhuman ctermbg=blue ctermfg=red
- autocmd BufReadPost * syntax match nonhuman
- \ "[^\u0000-\u007Fа-яА-ЯёЁäÄöÖüÜßẞ]" containedin=ALL
-endfunction
+ autocmd BufReadPost * syntax match nonhuman "[^\u0000-\u007Fа-яА-ЯёЁäÄöÖüÜßẞ]" containedin=ALL
+enddef
-if exists("*nonhumanhl#load") | finish | endif
-call nonhumanhl#load()
+vim9script
+if exists("*nonhumanhl#Load") | finish | endif
+nonhumanhl#Load()
-" Python imports insert completion
-" Maintainer: Sergey Matveev <stargrave@stargrave.org>
-" 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 <F3> 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 python#importcompl#all()
-" 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.
+vim9script
-let s:git_grep_cmd = "git grep -H --line-number --ignore-case --no-color "
+# Python imports insert completion
+# Maintainer: Sergey Matveev <stargrave@stargrave.org>
+# 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 <F3> 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 python#importcompl#all()
+# 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.
-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
+const gitGrepCmd = "git grep -H --line-number --ignore-case --no-color "
-function! python#importcompl#do() abort
+export def Do(): string
normal diw
- let output = system(s:git_grep_cmd . '"^from .* import .*' . @" . '" -- "*.py" "**/*.py"')
- let suggestions = []
+ var output = system(gitGrepCmd .. '"^from .* import .*' .. @" .. '" -- "*.py" "**/*.py"')
+ var suggestions: list<string>
+ var m: list<string>
for line in split(output, "\n")
if stridx(line, "unused-import") != -1 | continue | endif
- let m = matchlist(line, '^.*:\d\+:\(.*\)$')
+ m = matchlist(line, '^.*:\d\+:\(.*\)$')
if len(m) == 0 | continue | endif
- call insert(suggestions, m[1])
+ insert(suggestions, m[1])
endfor
- call sort(suggestions, "python#importcompl#sortByLen")
- call uniq(suggestions)
- call reverse(suggestions)
- call complete(col('.'), suggestions)
- return ''
-endfunction
+ sort(suggestions, (s1: string, s2: string): number => {
+ if len(s1) == len(s2) | return 0 | endif
+ if len(s1) > len(s2) | return 1 | endif
+ return -1
+ })
+ uniq(suggestions)
+ reverse(suggestions)
+ complete(col("."), suggestions)
+ return ""
+enddef
-function! python#importcompl#all() abort
- let output = system(s:git_grep_cmd . '"^from .* import" -- "*.py" "**/*.py"')
- let imports = {}
+export def All()
+ var output = system(gitGrepCmd .. '"^from .* import" -- "*.py" "**/*.py"')
+ var imports = {}
+ var ms: list<string>
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]
+ '^.*:\d\+:\(from .* import \(\w\+\).*\)$',
+ '^.*:\d\+:\(from .* import \w\+ as \(\w\+\).*\)$',
+ ]
+ ms = matchlist(line, regexp)
+ if len(ms) == 0 | break | endif
+ imports[ms[2]] = ms[1]
endfor
endfor
-
- let lines = getloclist(winnr())
- if len(lines) == 0 | let lines = getqflist() | endif
- let result = []
+ var lines = getloclist(winnr())
+ if len(lines) == 0 | lines = getqflist() | endif
+ var result: list<string>
+ var m: string
for line in lines
if line.text !~ "^undefined name" | continue | endif
- let m = line.text[strridx(line.text[:-2], "'")+1:-2]
+ m = line.text[strridx(line.text[: -2], "'") + 1 : -2]
if len(m) == 0 || !has_key(imports, m) | continue | endif
- call insert(result, imports[m])
+ insert(result, imports[m])
endfor
- call sort(result, "i")
- call uniq(result)
- call append(".", result)
-endfunction
+ sort(result, "i")
+ uniq(result)
+ append(".", result)
+enddef
-function! python#unused#remove() abort
- call setqflist(filter(getqflist(), {idx, val ->
- \ stridx(val.text, "unused-import") != -1 ||
- \ stridx(val.text, "imported but unused") != -1}))
+vim9script
+
+export def Remove()
+ setqflist(filter(getqflist(), (idx, val) =>
+ stridx(val.text, "unused-import") != -1 ||
+ stridx(val.text, "imported but unused") != -1))
cdo d
-endfunction
+enddef
-if exists("*python#importcompl#do") | finish | endif
-inoremap <F3> <C-R>=python#importcompl#do()<CR>
-cnoremap <F3> call python#importcompl#all()<CR>
-cnoremap <F4> call python#unused#remove()<CR>
+if exists("*python#importcompl#Do") | finish | endif
+inoremap <F3> <C-R>=python#importcompl#Do()<CR>
+cnoremap <F3> call python#importcompl#All()<CR>
+cnoremap <F4> call python#unused#Remove()<CR>
-" PEP8 caller
-" Maintainer: Sergey Matveev <stargrave@stargrave.org>
-" License: GNU General Public License version 3 of the License or later
-"
-" Call pycodestyle utility and fill quickfix window with its results.
+vim9script
-function! python#pep8#do() abort
+# PEP8 caller
+# Maintainer: Sergey Matveev <stargrave@stargrave.org>
+# License: GNU General Public License version 3 of the License or later
+#
+# Call pycodestyle utility and fill quickfix window with its results.
+
+export def Do()
set makeprg=PATH=$PATH\ pycodestyle\ --select=E,W\ %
silent make
sign unplace *
- let l:id = 1
+ var _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
+ execute(":sign place " .. _id .. " name=P8 line=" .. item.lnum ..
+ " buffer=" .. item.bufnr)
+ _id = _id + 2
endfor
redraw!
copen
-endfunction
+enddef
-if exists("*python#pep8#do") | finish | endif
+if exists("*python#pep8#Do") | finish | endif
sign define P8 text=P8 texthl=Error
-map <buffer> <F5> :call python#pep8#do()<CR>
+map <buffer> <F5> :call python#pep8#Do()<CR>
-" Nose-compatible test name preparer
-" Maintainer: Sergey Matveev <stargrave@stargrave.org>
-" License: GNU General Public License version 3 of the License or later
-"
-" When standing inside TestCase's test method, type <leader>t and full
-" Python (your.project.tests:TestCaseName.test_method_name) path will be
-" copied to clipboard ("*) register.
+vim9script
-function! python#testname#get() abort
- let l:pos = getpos(".")
- let l:postfix = matchstr(getline(search(".*\s*def .*[Tt]est", "b")), '\w\+(')[:-2]
- let l:postfix = matchstr(getline(search("^\s*class", "bn")), '\w\+(')[:-2] . "." . l:postfix
- call setpos(".", l:pos)
- let l:base = join([""] + split(getcwd(), "/")[:-1], "/")
- let l:prefix = substitute(expand("%:p:r")[len(l:base)+1:], "/", ".", "g")
- let l:name = l:prefix . ":" . l:postfix
- let @* = l:name
- echomsg l:name
-endfunction
+# Nose-compatible test name preparer
+# Maintainer: Sergey Matveev <stargrave@stargrave.org>
+# License: GNU General Public License version 3 of the License or later
+#
+# When standing inside TestCase's test method, type <leader>t and full
+# Python (your.project.tests:TestCaseName.test_method_name) path will be
+# copied to clipboard ("*) register.
+
+export def Get()
+ var pos = getpos(".")
+ var postfix = matchstr(getline(search(".*\s*def .*[Tt]est", "b")), '\w\+(')[: -2]
+ postfix = matchstr(getline(search("^\s*class", "bn")), '\w\+(')[: -2] .. "." .. postfix
+ setpos(".", pos)
+ var base = join([""] + split(getcwd(), "/")[: -1], "/")
+ var prefix = substitute(expand("%:p:r")[len(base) + 1 :], "/", ".", "g")
+ var name = prefix .. ":" .. postfix
+ @* = name
+ echomsg name
+enddef
-if exists("*python#testname#get") | finish | endif
-nmap <buffer> <leader>t :call python#testname#get()<CR>
+if exists("*python#testname#Get") | finish | endif
+nmap <buffer> <leader>t :call python#testname#Get()<CR>
-function! whereami#pwdLoad()
- let g:whereami_pwdL=trim(system("pwd -L"))
- let g:whereami_pwdP=trim(system("pwd -P"))
-endfunction
+vim9script
-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):]
+export def PwdLoad()
+ g:whereami_pwdL = trim(system("pwd -L"))
+ g:whereami_pwdP = trim(system("pwd -P"))
+enddef
+
+export def Do(fmt: string)
+ var fullpath = expand("%:p")
+ if fullpath[ : len(g:whereami_pwdP) - 1] ==# g:whereami_pwdP
+ fullpath = g:whereami_pwdL .. fullpath[len(g:whereami_pwdP) : ]
endif
- let where = printf(a:fmt, fullpath, line("."))
- let @* = where
+ var where = printf(fmt, fullpath, line("."))
+ @* = where
echomsg where
-endfunction
+enddef
if exists("*whereami#pwdLoad") | finish | endif
-autocmd VimEnter * call whereami#pwdLoad()
-nmap <leader>w :call whereami#do("%s:%d")<CR>
-nmap <leader>W :call whereami#do("breakpoint set --file %s --line %d")<CR>
+autocmd VimEnter * call whereami#PwdLoad()
+nmap <leader>w :call whereami#Do("%s:%d")<CR>
+nmap <leader>W :call whereami#Do("breakpoint set --file %s --line %d")<CR>
--- /dev/null
+vim9script
+
+export def Do(query: string, opencmd: string)
+ silent var result = systemlist(g:zshfe_path .. " " .. query)
+ if len(result) == 0 | return | endif
+ execute opencmd .. " " .. result[0][: -2]
+enddef
-" zsh file completion caller
-" Maintainer: Sergey Matveev <stargrave@stargrave.org>
-" License: GNU General Public License version 3 of the License or later
+vim9script
-if exists("*<SID>zshfe") | finish | endif
+# zsh file completion caller
+# Maintainer: Sergey Matveev <stargrave@stargrave.org>
+# License: GNU General Public License version 3 of the License or later
+
+if exists("*zshfe#Do") | finish | endif
if !exists("g:zshfe_path")
- let g:zshfe_path=expand("<sfile>:p:h") . "/zshfe.zsh"
+ g:zshfe_path = expand("<sfile>:p:h") .. "/zshfe.zsh"
endif
-function! s:zshfe(query, opencmd)
- silent let result = systemlist(g:zshfe_path . " " . a:query)
- if len(result) == 0 | return | endif
- exec a:opencmd . " " . result[0][:-2]
-endfunction
-
-command! -nargs=1 Fe call s:zshfe(<f-args>, "edit")
-command! -nargs=1 Fsp call s:zshfe(<f-args>, "split")
-command! -nargs=1 Fvs call s:zshfe(<f-args>, "vsplit")
+command! -nargs=1 Fe call zshfe#Do(<f-args>, "edit")
+command! -nargs=1 Fsp call zshfe#Do(<f-args>, "split")
+command! -nargs=1 Fvs call zshfe#Do(<f-args>, "vsplit")
nmap <Leader>e :Fe
nmap <Leader><space> :Fsp
-let g:loaded_2html_plugin = 1
-let g:loaded_getscriptPlugin = 1
-let g:loaded_logipat = 1
-let g:loaded_rrhelper = 1
-let g:loaded_spellfile_plugin = 1
-let g:loaded_vimballPlugin = 1
-let g:loaded_vimball = 1
+vim9script
+
+g:loaded_2html_plugin = 1
+g:loaded_getscriptPlugin = 1
+g:loaded_logipat = 1
+g:loaded_rrhelper = 1
+g:loaded_spellfile_plugin = 1
+g:loaded_vimballPlugin = 1
+g:loaded_vimball = 1
-if exists("*<SID>exted") | finish | endif
-
-function! s:exted(ext)
- execute "edit %<." . a:ext
-endfunction
-
-command! -nargs=1 Ee silent call s:exted(<f-args>)
+vim9script
+command -nargs=1 Ee execute "edit %<." .. <f-args>
-if exists("*<SID>Vmg") | finish | endif
+vim9script
-function! s:Vmg(pattern)
- silent execute 'Ggrep "' . a:pattern . '"'
+command! -nargs=* -complete=file Vmg {
+ silent execute "Ggrep \"" .. <q-args> .. '"'
copen
- redraw!
-endfunction
-
-command! -nargs=* -complete=file Vmg call s:Vmg(<q-args>)
+}
-if exists("*<SID>Vim") | finish | endif
+vim9script
-function! s:Vim(pattern)
+command! -nargs=* -complete=file Vim {
set grepprg=grep\ -Rns\ --binary-files=without-match\ --exclude-dir=.git\ --exclude-dir=.tags\ $*\ /dev/null\ .
- execute "silent grep \"" . a:pattern . "\""
+ execute "silent grep \"" .. <q-args> .. "\""
copen
redraw!
-endfunction
-
-command! -nargs=* -complete=file Vim call s:Vim(<q-args>)
+}
-" go get golang.org/x/tools/gopls@latest
-" pip install 'python-language-server[all]'
+vim9script
-let g:lsc_enable_autocomplete = v:false
-let g:lsc_server_commands = {
- \ "c": {"command": "clangd --log=error"},
- \ "cpp": {"command": "clangd --log=error"},
- \ "go": {"command": "gopls", "log_level": -1},
- \ "python": {
- \ "command": "pyls",
- \ "workspace_config": {"pyls": {
- \ "configurationSources": ["flake8"],
- \ "plugins": {
- \ "mccabe": {"enabled": v:false},
- \ },
- \ }},
- \ "enabled": v:false,
- \ },
-\ }
-let g:lsc_auto_map = {
- \ "GoToDefinition": "gd",
- \ "GoToDefinitionSplit": "<C-W>gd",
- \ "ShowHover": v:true,
- \ "Completion": "omnifunc",
-\ }
+# go get golang.org/x/tools/gopls@latest
+# pip install 'python-language-server[all]'
+
+g:lsc_enable_autocomplete = v:false
+g:lsc_server_commands = {
+ c: {command: "clangd --log=error"},
+ cpp: {command: "clangd --log=error"},
+ go: {command: "gopls", log_level: -1},
+ python: {
+ command: "pyls",
+ workspace_config: {pyls: {
+ configurationSources: ["flake8"],
+ plugins: {
+ mccabe: {enabled: v:false},
+ },
+ }},
+ enabled: v:false,
+ },
+}
+g:lsc_auto_map = {
+ GoToDefinition: "gd",
+ GoToDefinitionSplit: "<C-W>gd",
+ ShowHover: v:true,
+ Completion: "omnifunc",
+}
map <F6> :LSClientAllDiagnostics<CR>
+vim9script
if exists("g:loaded_mein_netrw") | finish | endif
-let g:loaded_mein_netrw = 1
+g:loaded_mein_netrw = 1
-let g:netrw_banner = 0
-let g:netrw_bufsettings = "noma nomod nowrap ro nobl"
+g:netrw_banner = 0
+g:netrw_bufsettings = "noma nomod nowrap ro nobl"
-function! WinClose(islocal)
+def g:WinClose(islocal: number): string
close
-endfunction
-let g:Netrw_UserMaps = [["<Del>", "WinClose"]]
+ return ""
+enddef
+g:Netrw_UserMaps = [["<Del>", "g:WinClose"]]
autocmd VimLeave * call delete("/home/stargrave/.vim/.netrwhist")