Skip to content

Instantly share code, notes, and snippets.

@shurizzle
Last active September 5, 2025 19:11
Show Gist options
  • Save shurizzle/a90d9a43eb086f8f0106132f8c41ec6d to your computer and use it in GitHub Desktop.
Save shurizzle/a90d9a43eb086f8f0106132f8c41ec6d to your computer and use it in GitHub Desktop.
vimrc
let mapleader=','
set nocp
set mouse=a bo=all sc spr
set ttimeout ttimeoutlen=0
set nu ls=2 fen fdm=marker bs=2
set ts=2 sts=0 sw=2 noet nobk noswf hid
set si ic
set list lcs=tab:\ ·,trail:×,nbsp:%,eol:·,extends:»,precedes:«
set shm+=Fc nosmd
" if has('plan9')
" set nostmp
" endif
if (v:version == 802 && has('patch2508')) || v:version > 802
let &fillchars = &fillchars.',eob: '
endif
if has('termguicolors') && !has('gui_running')
set termguicolors
endif
sil colo desert
sil colo habamax
if has('plan9')
set mousef
let s:FIXED_UNICODE_FONTS = [
\ ['4x6'],
\ ['5x7'],
\ ['5x8'],
\ ['6x9'],
\ ['6x10'],
\ ['6x12'],
\ ['6x13', '6x13B', '6x13O'],
\ ['7x13', '7x13B', '7x13O'],
\ ['7x14', '7x14B'],
\ ['8x13', '8x13B', '8x13O'],
\ ['9x15', '9x15B'],
\ ['9x18', '9x18B'],
\ ['10x20'],
\ ]
let s:i = 0
while s:i < len(s:FIXED_UNICODE_FONTS)
let s:FIXED_UNICODE_FONTS[s:i] = join(map(s:FIXED_UNICODE_FONTS[s:i],
\ '"/lib/font/bit/fixed/unicode." . v:val . ".font"'), ',')
let s:i += 1
endwhile
let s:DEFAULT_FONT_IDX = 11
if exists('$remote') && match($remote, '^.\{-1,}!192.168.1.16!.\{-1,}$') != -1
let s:DEFAULT_FONT_IDX = 9
endif
let s:FONT_IDX = s:DEFAULT_FONT_IDX
function s:nextfont()
if s:FONT_IDX != (len(s:FIXED_UNICODE_FONTS)-1)
let s:FONT_IDX += 1
endif
let &gfn = s:FIXED_UNICODE_FONTS[s:FONT_IDX]
endfunction
function s:prevfont()
if s:FONT_IDX != 0
let s:FONT_IDX -= 1
endif
let &gfn = s:FIXED_UNICODE_FONTS[s:FONT_IDX]
endfunction
function s:resetfont()
let s:FONT_IDX = s:DEFAULT_FONT_IDX
let &gfn = s:FIXED_UNICODE_FONTS[s:FONT_IDX]
endfunction
let &gfn = s:FIXED_UNICODE_FONTS[s:FONT_IDX]
nnoremap <silent> <expr> <Leader>f- <SID>prevfont()
nnoremap <silent> <expr> <Leader>f+ <SID>nextfont()
nnoremap <silent> <expr> <Leader>f= <SID>resetfont()
nnoremap <silent> <expr> <Leader>f<S-=> <SID>resetfont()
" nnoremap <silent> <expr> <C-_> <SID>prevfont()
" nnoremap <silent> <expr> <C-+> <SID>nextfont()
" nnoremap <silent> <expr> <C-=> <SID>resetfont()
" nnoremap <silent> <expr> <C-S-=> <SID>resetfont()
set cb^=unnamed
endif
set gcr+=a:blinkon0
if has('gui_running')
set go=
if has('gui_gtk')
let s:fontsize = 9
function s:fontresize(add)
let s:fontsize += a:add
let &gfn = 'Monospace ' . s:fontsize
endfunction
function s:fontreset()
let s:fontsize = 9
call s:fontresize(0)
endfunction
call s:fontresize(0)
nnoremap <silent> <expr> <C-_> <SID>fontresize(-1)
nnoremap <silent> <expr> <C-+> <SID>fontresize(1)
nnoremap <silent> <expr> <C-=> <SID>fontreset()
nnoremap <silent> <expr> <C-S-=> <SID>fontreset()
endif
else
let &t_SI .= "\e[6 q"
let &t_SR .= "\e[4 q"
let &t_EI .= "\e[2 q"
let &t_Cs = "\e[4:3m"
let &t_Ce = "\e[4:0m"
let &t_ti .= "\e[2 q"
let &t_te .= "\e[6 q"
endif
if v:version >= 703
set incsearch hlsearch
set cursorline relativenumber textwidth=80 colorcolumn=+0
set wildmenu wildmode=full wildignorecase
endif
filetype on
filetype plugin on
filetype indent on
syntax on
if (has('termguicolors') && &termguicolors) || has('gui_running')
" Normal
hi! ModeNormal guifg=#bcbcbc guibg=#1c1c1c gui=bold cterm=bold
" QuickFixLine
hi! ModeInsert guifg=#1c1c1c guibg=#5f87af gui=bold cterm=bold
" Visual
hi! ModeVisual guifg=#1c1c1c guibg=#87afaf gui=bold cterm=bold
" Normal
hi! ModeCommand guifg=#bcbcbc guibg=#1c1c1c gui=bold cterm=bold
" Error
hi! ModeReplace guifg=#1c1c1c guibg=#af5f5f gui=bold cterm=bold
elseif &t_Co >= 256
" Normal
hi! ModeNormal ctermfg=250 ctermbg=234 cterm=bold
" QuickFixLine
hi! ModeInsert ctermfg=234 ctermbg=67 cterm=bold
" Visual
hi! ModeVisual ctermfg=234 ctermbg=109 cterm=bold
" Normal
hi! ModeCommand ctermfg=250 ctermbg=234 cterm=bold
" Error
hi! ModeReplace ctermfg=234 ctermbg=131 cterm=bold
elseif &t_Co >= 16
" Normal
hi! ModeNormal ctermfg=white ctermbg=black cterm=bold
" QuickFixLine
hi! ModeInsert ctermfg=black ctermbg=darkblue cterm=bold
" Visual
hi! ModeVisual ctermbg=black ctermfg=cyan cterm=bold
" Normal
hi! ModeCommand ctermfg=white ctermbg=black cterm=bold
" Error
hi! ModeReplace ctermbg=black ctermfg=darkred cterm=bold
elseif &t_Co >= 8
" Normal
hi! ModeNormal ctermfg=gray ctermbg=black cterm=bold
" QuickFixLine
hi! ModeInsert ctermfg=black ctermbg=darkblue cterm=bold
" Visual
hi! ModeVisual ctermfg=black ctermbg=darkcyan cterm=bold
" Normal
hi! ModeCommand ctermfg=gray ctermbg=black cterm=bold
" Error
hi! ModeReplace ctermbg=gray ctermfg=darkred cterm=bold
else
hi! ModeNormal term=bold
hi! ModeInsert term=bold
hi! ModeVisual term=bold
hi! ModeCommand term=bold
hi! ModeReplace term=bold
endif
let s:modes_map = {
\ 'n': ['ModeNormal', 'normal'],
\ 'no': ['ModeNormal', 'o-pend'],
\ 'niI': ['ModeNormal', 'i-pend'],
\ 'niR': ['ModeNormal', 'r-pend'],
\ 'i': ['ModeInsert', 'insert'],
\ 'ic': ['ModeInsert', 'i-comp'],
\ 'ix': ['ModeInsert', 'i-comp'],
\ 'v': ['ModeVisual', 'visual'],
\ 'vs': ['ModeVisual', 'visual'],
\ 'V': ['ModeVisual', 'v-line'],
\ 'Vs': ['ModeVisual', 'v-line'],
\ "\<C-v>": ['ModeVisual', 'v-bloc'],
\ 's': ['ModeVisual', 'select'],
\ 'S': ['ModeVisual', 's-line'],
\ "\<C-s>": ['ModeVisual', 's-bloc'],
\ 'c': ['ModeCommand', 'c-mode'],
\ 'r': ['ModeCommand', 'prompt'],
\ 'rm': ['ModeCommand', 'prompt'],
\ 'r?': ['ModeCommand', 'prompt'],
\ '!': ['ModeCommand', '!-mode'],
\ 'R': ['ModeReplace', 'r-mode'],
\ 'Rc': ['ModeReplace', 'r-comp'],
\ 'Rx': ['ModeReplace', 'r-comp'],
\ 't': ['ModeInsert', 't-mode'],
\ 'nt': ['ModeInsert', 'normal'],
\ }
if (v:version == 802 && has('patch2854')) || v:version > 802
function! StatuslineMode()
let l:mode = get(s:modes_map, mode())
return '%#'.l:mode[0].'# '.l:mode[1].' '
endfunction
set statusline=%{%StatuslineMode()%}
else
function! StatuslineMode()
let l:mode = get(s:modes_map, mode())
execute 'hi! link StatuslineMode '.l:mode[0]
return ' '.l:mode[1].' '
endfunction
hi! link StatuslineMode ModeNormal
set statusline=%#StatuslineMode#%{StatuslineMode()}
endif
set statusline+=%#PMenuSel#
set statusline+=\ %n:%h%f%q\ %m
set statusline+=%=%y
set statusline+=%([%{&fileencoding?&fileencoding:&encoding}]%)
set statusline+=\ %(%l:%v/%L\ %p%%%)
let &statusline .= ' '
vnoremap < <gv
vnoremap > >gv
nnoremap <silent> <C-n> :bnext!<CR>
nnoremap <silent> <C-p> :bprevious!<CR>
nnoremap Y y$
nnoremap <silent> <C-h> :wincmd h<CR>
nnoremap <silent> <C-j> :wincmd j<CR>
nnoremap <silent> <C-k> :wincmd k<CR>
nnoremap <silent> <C-l> :wincmd l<CR>
nnoremap yss ^ys$
nnoremap <silent> <Space>e :NERDTreeToggle<CR>
nnoremap <silent> ZZ :Bdelete<CR>
if has('terminal')
function! s:SplitTerm()
if (winheight('%') * 2) > winwidth('%')
bel term
else
" override 'splitright'
bel vert term
endif
endfunction
nnoremap <silent> <Leader>t :call <SID>SplitTerm()<CR>
endif
nnoremap <Leader>cr g]
if has('win32')
let s:dirsep = '\'
else
let s:dirsep = '/'
endif
" Execute macro on each line if in visual mode
function! s:ExecuteMacroOverVisualRange()
echo "@".getcmdline()
execute ":'<,'>normal @".nr2char(getchar())
endfunction
xnoremap @ :<C-u>call <SID>ExecuteMacroOverVisualRange()<CR>
function! s:justusevim()
let l:keys = ['Left', 'Right', 'Up', 'Down', 'PageUp', 'PageDown',
\ 'End', 'Home', 'Del']
let l:actions = {'n': ':', 'v': ':<C-u>', 'i': '<C-o>:'}
for l:key in l:keys
let l:name = l:key == 'Del' ? 'Delete' : l:key
let l:actions = {'n': ':', 'v': ':<C-u>', 'i': '<C-o>:'}
for l:mode in keys(l:actions)
exe l:mode . 'noremap <silent> <' . l:key . '> ' . l:actions[l:mode] .
\ 'echo "No ' . l:name . ' for you!"<CR>'
endfor
endfor
endfunction
call s:justusevim()
if has('plan9')
set errorformat+=%tarning:\ %f:%l\ %m
set errorformat+=%tarning:\ %f:%l[%.%#]\ %m
set errorformat+=%f:%l\ %m
set errorformat+=%f:%l[%.%#]\ %m
autocmd BufReadPost quickfix nnoremap <buffer> <CR> <CR>
endif
if has('plan9')
set gp=g\ $*
elseif executable('rg')
set gp=rg\ --vimgrep\ $*
elseif executable('grep')
set gp=grep\ -rn\ $*\ /dev/null
endif
sil runtime ftplugin/man.vim
function! s:GetVisualSelection()
call feedkeys("\<ESC>", 'nx')
let l:s_start = getpos("'<")
let l:s_end = getpos("'>")
let l:n_lines = abs(l:s_end[1] - l:s_start[1] + 1)
let l:lines = getline(l:s_start[1], l:s_end[1])
let l:lines[0] = l:lines[0][l:s_start[2]-1:]
if l:n_lines is 1
let l:lines[0] = l:lines[0][:(l:s_end[2] - l:s_start[2])]
else
let l:lines[l:n_lines-1] = l:lines[l:n_lines-1][0:l:s_end[2]-1]
endif
return l:lines
endfunction
function! s:GetVisualSelectionText()
let l:line_ending = {"unix": "\n", "dos": "\r\n", "mac": "\r"}[&fileformat]
return join(s:GetVisualSelection(), l:line_ending)
endfunction
function! s:Doc(m)
if a:m[0] ==? 'v'
let l:word = s:GetVisualSelectionText()
elseif a:m[0] ==? 'n'
let l:word = expand("<cword>")
else
return
endif
if &ft == 'vim' || &ft == 'help'
execute ":help ".l:word
elseif has('plan9') && &ft == 'rc'
execute ":Man 1 ".l:word
elseif !has('plan9') && (&ft == 'sh' || &ft == 'zsh' || &ft == 'bash')
execute ":Man 1 ".l:word
elseif &ft == 'man' || &ft == 'c' || &ft == 'cpp'
execute ":Man 2 ".l:word
else
execute ":Man ".l:word
endif
endfunction
nnoremap <silent> K :call <SID>Doc('n')<CR>
vnoremap <silent> K :call <SID>Doc('v')<CR>
if (v:version == 800 && has('patch1630')) || v:version > 800
function! s:trim(s)
return trim(a:s)
endfunction
else
function! s:trim(s)
return substitute(a:s, '^\v\_s*(.{-})\_s*$', '\1', '')
endfunction
endif
" Formatting {{{
function! s:ReplaceLines(lnum, count, content)
if type(a:content) == v:t_string
let l:content = split(a:content, "\n")
else
let l:content = a:content
endif
let l:l = min([len(l:content), a:count])
let l:i = 0
while l:i < l:l
call setline(a:lnum+l:i, l:content[l:i])
let l:i += 1
endwhile
if a:count > len(l:content)
let l:start = a:lnum+l:i
let l:stop = l:start+(a:count-len(l:content)-1)
execute l:start.','.l:stop.'d'
elseif a:count < len(l:content)
call append(a:lnum+a:count-1, l:content[(l:i):])
endif
endfunction
function! GofmtFormat()
if executable('gofmt')
if v:lnum != 1 || (v:lnum+v:count-1) != line('$') | return 0 | endif
let l:formatted = systemlist('gofmt -s', getline(v:lnum, v:lnum+v:count-1))
if v:shell_error > 0
call map(l:formatted, 'substitute(v:val, "\\V\\M\\C^<standard input>", expand("%"), "")')
cexpr l:formatted
call setqflist([], 'a', { 'title': 'gofmt -s' })
cwindow
else
let l:saved_view = winsaveview()
call s:ReplaceLines(v:lnum, v:count, l:formatted)
call winrestview(l:saved_view)
call setqflist([], 'r', { 'title': '' })
cclose
endif
endif
return 0
endfunction
function! s:SearchForConfig(path)
let l:path = fnamemodify(a:path, '%:p')
while 1
if filereadable(l:path.s:dirsep.'.indent.pro')
return l:path
endif
let l:newpath = fnamemodify(l:path, '%:h')
if l:path == l:newpath
return 0
endif
endwhile
endfunction
function! s:IndentErrorFile(line)
let l:idx = stridx(a:line, ':')
if l:idx <= 0 | return 0 | endif
let l:file = a:line[:(l:idx-1)]
let l:line = a:line[(l:idx+1):]
let l:idx = stridx(l:line, ':')
if l:idx <= 0 | return 0 | endif
let l:lno = l:line[:(l:idx-1)]
if l:lno =~ '\D' | return 0 | endif
let l:lno = str2nr(l:lno)
let l:line = s:trim(l:line[(l:idx+1):])
if empty(l:line) | return 0 | endif
let l:qf = {
\ 'filename': l:file,
\ 'lnum': l:lno,
\ 'text': l:line,
\ }
if l:line[:7] ==? 'Warning:'
let l:qf['type'] = 'W'
let l:qf['text'] = s:trim(l:line[8:])
elseif l:line[:5] ==? 'Error:'
let l:qf['type'] = 'E'
let l:qf['text'] = s:trim(l:line[6:])
endif
return l:qf
endfunction
function! s:IndentError(line)
" this should not happen but we ignore the line just in case
if a:line[:7] != 'indent: ' | return 0 | endif
let l:line = a:line[8:]
let l:err = s:IndentErrorFile(l:line)
if type(l:err) == v:t_dict
return l:err
else
return {
\ 'type': 'E',
\ 'text': s:trim(l:line),
\ }
endif
endfunction
function! IndentFormat()
if executable('indent')
if v:lnum != 1 || (v:lnum+v:count-1) != line('$') | return 0 | endif
try
let l:stdout_file = tempname()
let l:filename = expand('%:p')
let l:basepath = s:SearchForConfig(fnamemodify(l:filename, ':h'))
try
if l:basepath
cd! l:basepath
endif
let l:stderr = systemlist('indent -o ' .
\ shellescape(l:stdout_file),
\ getline(v:lnum, v:lnum+v:count))
finally
if l:basepath
cd! -
endif
endtry
if v:shell_error > 0
call setqflist([], 'r')
call setqflist([], 'r', { 'title': 'indent' })
for l:line in l:stderr
let l:err = s:IndentError(l:line)
if type(l:err) == v:t_dict
if l:err['filename'] ==? 'Standard input'
let l:err['filename'] = l:filename
endif
call setqflist([l:err], 'a')
endif
endfor
cwindow
else
let l:saved_view = winsaveview()
let l:formatted = readfile(l:stdout_file)
if empty(l:formatted) | return 0 | endif
call s:ReplaceLines(v:lnum, v:count, l:formatted)
call winrestview(l:saved_view)
call setqflist([], 'r', { 'title': '' })
cclose
endif
finally
call delete(l:stdout_file)
endtry
endif
return 0
endfunction
let s:disabled_autofmt_langs = {}
let s:disable_autofmt = 0
function! s:Format()
if !empty(&formatprg) || !empty(&formatexpr)
let l:saved_view = winsaveview()
normal gggqG
call winrestview(l:saved_view)
endif
endfunction
command! -nargs=0 Format call <SID>Format()
function! s:AutoFormat()
if !s:disable_autofmt && !get(b:, 'disable_autofmt', 0) &&
\ !get(s:disabled_autofmt_langs, &l:ft, 0)
call s:Format()
endif
endfunction
autocmd BufWritePre * call <SID>AutoFormat()
command! -narg=0 BufDisableAutoFmt let b:disable_autofmt = 1
command! -narg=0 BufEnableAutoFmt let b:disable_autofmt = 0
command! -narg=1 LangDisableAutoFmt let s:disabled_autofmt_langs[<f-args>] = 1
command! -narg=1 LangEnableAutoFmt call remove(s:disabled_autofmt_langs, <f-args>)
command! -narg=0 DisableAutoFmt let s:disable_autofmt = 1
command! -narg=0 EnableAutoFmt let s:disable_autofmt = 0
" }}}
" FileType {{{
if v:version >= 703
function! s:SetBufWidth(n)
exe 'setl tw='.a:n
endfunction
else
function! s:SetBufWidth(...)
endfunction
endif
function! s:FTPlugin()
let l:match = expand('<amatch>')
if l:match ==? 'go'
setl makeprg=go\ build
" Ignore lines beginning with '#' ('# command-line-arguments' line sometimes
" appears?)
setl errorformat=%-G#\ %.%#
" Ignore lines containing 'panic: message'
setl errorformat+=%-G%.%#panic:\ %m
" Start of multiline error string is 'can\'t load package'
setl errorformat+=%Ecan\'t\ load\ package:\ %m
" Start of multiline unspecified string is
" 'filename:linenumber:columnnumber:'
setl errorformat+=%A%\\%%(%[%^:]%\\+:\ %\\)%\\?%f:%l:%c:\ %m
" Start of multiline unspecified string is 'filename:linenumber:'
setl errorformat+=%A%\\%%(%[%^:]%\\+:\ %\\)%\\?%f:%l:\ %m
" Continuation of multiline error message is indented
setl errorformat+=%C%*\\s%m
" All lines not matching any of the above patterns are ignored
setl errorformat+=%-G%.%#
call s:SetBufWidth(80)
setl ts=4 sw=4 noet fo=croq fp= fex=GofmtFormat()
setl commentstring=//\ %s
elseif l:match ==? 'c'
call s:SetBufWidth(80)
setl ts=4 sw=4 noet fo=roq fp= fex=IndentFormat()
setl commentstring=/*\ %s\ */
elseif l:match ==? 'vim'
call s:SetBufWidth(80)
setl ts=2 sw=2 noet fo=roq fp= fex=
setl commentstring=\"\ %s
elseif has('plan9') && l:match ==? 'man'
call s:SetBufWidth(80)
setl ts=8 sw=8 noet fo= fp= fex= cms=
endif
endfunction
autocmd FileType * call <SID>FTPlugin()
" }}}
function! s:CHeader()
let l:name = '_'.toupper(substitute(expand('%:t'), '\M\V\[\.-]', '_', 'g'))
call append(0, ['#ifndef '.l:name, '#define '.l:name.' 1'])
call append('$', '#endif /* '.l:name.' */')
endfunction
command! -nargs=? CHeader call <SID>CHeader()
if !has('plan9')
function s:httppost(url, postdata, ...)
let l:headdata = a:0 > 0 ? a:000[0] : {}
let l:method = a:0 > 1 ? a:000[1] : 'POST'
let l:file = tempname()
if executable('curl')
let l:cmd = 'curl -qsSLkiX ' . shellescape(l:method)
for l:key in keys(l:headdata)
let l:header = l:key . ': ' . l:headdata[l:key]
let l:cmd .= ' -H ' . shellescape(l:header)
endfor
let l:cmd .= ' --data-binary @' . shellescape(l:file)
let l:cmd .= ' ' . shellescape(a:url)
elseif executable('wget')
let l:cmd = 'wget -qLO- --save-headers --server-response --method='
let l:cmd .= shellescape(l:method)
for l:key in keys(l:headdata)
let l:header = l:key . ': ' . l:headdata[l:key]
let l:cmd .= ' --header=' . shellescape(l:header)
endfor
let l:cmd .= ' --body-file ' . shellescape(l:file)
let l:cmd .= ' ' . shellescape(a:url)
else
call delete(l:file)
throw 'No uploader found'
endif
call writefile(a:postdata, file, 'b')
let l:res = system(l:cmd)
call delete(l:file)
let l:pos = stridx(l:res, "\r\n\r\n")
if l:pos != -1
let l:content = strpart(l:res, l:pos+4)
else
let l:pos = stridx(l:res, "\n\n")
let l:content = strpart(l:res, l:pos+2)
endif
let l:headers = split(l:res[:l:pos-1], '\r\?\n')
let l:matched = matchlist(get(l:headers, 0), '^HTTP/\%(1\.[01]\|[23]\%(\.0\)\?\)\s\+\(\d\+\)\s*\(.*\)')
if !empty(l:matched)
let [l:status, l:message] = l:matched[1:2]
call remove(l:headers, 0)
else
if v:shell_error || len(l:matched)
let [l:status, l:message] = ['500', "Couldn't connect to host"]
else
let [l:status, l:message] = ['200', 'OK']
endif
endif
return {
\ 'status': l:status,
\ 'message': l:message,
\ 'headers': l:headers,
\ 'content': l:content
\ }
endfunction
endif
if has('plan9')
function! s:PP(start, stop)
let l:res = system('hget -P -m POST https://paste.rs/ >[2=1]',
\ getline(a:start, a:stop))
if v:shell_error
echoe l:res
else
let l:res = s:trim(l:res)
call setreg('+', l:res)
echo '+ = ' . l:res
endif
endfunction
else
function! s:PP(start, stop)
let l:res = s:httppost('https://paste.rs/', getline(a:start, a:stop))
if l:res['status'] == '201'
let l:res = s:trim(l:res['content'])
if has('unnamedplus')
let l:reg = '+'
let l:opts = 'u'
elseif has('unnamed')
let l:reg = '*'
let l:opts = 'u'
else
let l:reg = '"'
let l:opts = ''
endif
call setreg(l:reg, l:res, l:opts)
if !has('nvim') && !has('clipboard_working')
call OSCYank(l:res)
endif
echom l:reg . ' = ' . l:res
elseif l:res['status'] == '206'
echoe 'Text too long'
else
echoe l:res['status'] . ' ' . l:res['message']
endif
endfunction
endif
command! -range=% -nargs=0 PP call s:PP(<line1>, <line2>)
if has('plan9')
function! s:Sig()
echo s:trim(system("sig ".expand("<cword>")))
endfunction
command! Sig call s:Sig()
nnoremap <silent> gs :Sig<CR>
function s:Plumb(m)
if a:m[0] ==? 'v'
let l:what = s:GetVisualSelectionText()
elseif a:m[0] ==? 'n'
let l:what = expand("<cWORD>")
else
return
endif
execute 'sil !plumb '.shellescape(l:what).' >/dev/null'
endfunction
nnoremap <silent> <Leader><S-p> :call <SID>Plumb('n')<CR>
vnoremap <silent> <Leader><S-p> :call <SID>Plumb('v')<CR>
endif
function! s:GitDiff()
32new ++ff=unix ++enc=utf-8 ++nobin ++edit +setl\ ma
setlocal buftype=nofile
if has('plan9')
silent .!git/diff
else
silent .!git diff
endif
silent 1d _
setlocal ft=diff bufhidden=wipe
endfunction
command! Gd call s:GitDiff()
function! s:Scratch()
enew
setlocal buftype=nofile bufhidden=hide noswapfile
endfunction
command! Scratch call s:Scratch()
autocmd QuickFixCmdPost [^l]* nested cwindow
autocmd QuickFixCmdPost l* nested lwindow
function! s:Grep(args)
execute "sil grep! ".a:args." ."
endfunction
command! -nargs=* G call s:Grep(<q-args>)
function! s:LGrep(args)
execute "sil lgrep! ".a:args." ."
endfunction
command! -nargs=* Lg call s:LGrep(<q-args>)
function! s:InputTextSearch()
let l:query = inputdialog('Search text: ')
if l:query != ""
call s:Grep(shellescape(l:query))
endif
endfunction
nnoremap <Leader>fg :call <SID>InputTextSearch()<CR>
function! s:CStruct(...)
let l:query = ''
if a:0 > 0
if a:0 > 1
echoerr 'Too many arguments'
return
endif
let l:query = s:trim(a:1)
endif
if l:query == ''
let l:query = s:trim(inputdialog('struct name: '))
endif
if l:query == ""
return
endif
call append(line('.'), [
\ 'typedef struct '.l:query.' '.l:query.';',
\ 'struct '.l:query.' {',
\ '};'
\ ])
endfunction
command! -nargs=* CStruct call s:CStruct(<f-args>)
function! s:InputFileSearch()
let l:query = inputdialog('Search file: ')
if l:query != ""
if has('plan9')
if executable('pcre2grep')
let l:grep = 'pcre2grep'
else
let l:grep = 'grep'
endif
else
let l:grep = 'grep'
endif
let l:res = []
let l:files = split(system("walk -f | ".l:grep." -i ".shellescape(l:query)), "\n", 0)
for l:f in l:files
call add(l:res, {'filename': l:f})
endfor
call setqflist(l:res)
copen
endif
endfunction
nnoremap <Leader>ff :call <SID>InputFileSearch()<CR>
if has('plan9')
function! s:Masto9()
enew
setl bt=nofile
nos
setl ma nonu nornu nofen
sil exe 'r!m'
while line('$') > 1 && getline('.') =~ '^\s*$'
norm! dd
endwhile
norm! 1G
while line('$') > 1 && getline('.') =~ '^\s*$'
norm! dd
endwhile
setl ft= nomod noma
file masto9
endfunction
command! -nargs=0 Masto call <SID>Masto9()
endif
function s:MkdirP(dir)
if empty(glob(a:dir))
call mkdir(a:dir, 'p')
endif
endfunction
let s:bundle = has('neovim') ? stdpath('data') : split(&rtp, ',')[0]
let s:bundle = substitute(fnamemodify(s:bundle, ':p'), '[\/]\+$', '', '')
\ .'/plugged'
if has('win32')
let s:bundle = substitute(s:bundle, '[/]', '\\', 'g')
endif
call s:MkdirP(s:bundle)
function s:GitClone(repo, dir)
call s:MkdirP(fnamemodify(a:dir, ':h'))
let l:dir = shellescape(a:dir)
let l:repo = shellescape(a:repo)
if has('plan9')
execute '!git/clone '.l:repo.' '.l:dir
else
execute '!git clone '.l:repo.' '.l:dir
endif
endfunction
if !has('plan9')
if empty(glob(s:bundle.s:dirsep.'vim-plug'))
call s:GitClone('https://github.com/junegunn/vim-plug.git',
\ s:bundle.s:dirsep.'vim-plug')
endif
if !empty(glob(s:bundle.s:dirsep.'vim-plug'))
execute 'source '.s:bundle.s:dirsep.'vim-plug'.s:dirsep.'plug.vim'
endif
call plug#begin(s:bundle)
Plug 'junegunn/vim-plug'
else
function! s:PrependBundle(dir)
let &rtp = a:dir . ',' . &rtp
endfunction
function! s:ClonePlugin(repo, dir)
if empty(glob(s:bundle.s:dirsep.a:dir))
call s:GitClone(a:repo, s:bundle.s:dirsep.a:dir)
endif
call s:PrependBundle(s:bundle.s:dirsep.a:dir)
endfunction
function! s:CloneGH(repo)
call s:ClonePlugin('https://github.com/'.a:repo.'.git',
\ fnamemodify(a:repo, ':t'))
endfunction
function! s:Plug(repo)
if a:repo[0] =~ '[/$~]'
call s:PrependBundle(a:repo)
else
call s:CloneGH(a:repo)
endif
endfunction
command! -nargs=1 -bar Plug call <SID>Plug(<args>)
endif
" mucomplete {{{
set noinfercase
set completeopt-=preview
set completeopt+=menuone,noselect
let g:mucomplete#enable_auto_at_startup = 0
let g:mucomplete#no_mappings = 1
imap <unique> <c-n> <plug>(MUcompleteFwd)
imap <unique> <c-p> <plug>(MUcompleteBwd)
" }}}
if !has('plan9')
call plug#begin()
endif
if (v:version == 801 && has('patch1270')) || v:version > 801
set shm-=S
else
Plug 'henrik/vim-indexed-search'
endif
if !has('plan9') && !has('nvim')
if (v:version == 800 && has('patch1394')) || v:version > 800
let s:VimOSCYankPostRegisters = ['', '+', '*']
let s:VimOSCYankOperators = ['y', 'd']
let s:cb = &cb
function! s:VimOSCYankPostCallback(event)
if index(s:VimOSCYankPostRegisters, a:event.regname) != -1
\ && index(s:VimOSCYankOperators, a:event.operator) != -1
call OSCYankRegister(a:event.regname)
endif
endfunction
endif
function! s:setclipboard()
let &cb = s:cb
if has('clipboard_working')
augroup Clipboard
autocmd!
augroup END
if (v:version == 800 && has('patch1394')) || v:version > 800
augroup VimOSCYankPost
autocmd!
augroup END
endif
if has('unnamedplus')
set cb^=unnamedplus
elseif has('unnamed')
set cb^=unnamed
endif
else
augroup Clipboard
autocmd!
autocmd VimEnter,GUIEnter * call <SID>setclipboard()
augroup END
if (v:version == 800 && has('patch1394')) || v:version > 800
augroup VimOSCYankPost
autocmd!
autocmd TextYankPost * call s:VimOSCYankPostCallback(v:event)
augroup END
endif
endif
endfunction
call s:setclipboard()
endif
if !has('plan9') && !has('nvim')
call s:setclipboard()
if exists('$TMUX')
let g:oscyank_osc52 = "\x1bPtmux;\x1b\x1b]52;c;%s\x07\x1b\\"
endif
let g:oscyank_silent = 1
Plug 'ojroques/vim-oscyank', {'branch': 'main'}
endif
Plug 'preservim/nerdtree'
Plug 'tpope/vim-commentary'
Plug 'tpope/vim-surround'
Plug 'tpope/vim-repeat'
Plug 'moll/vim-bbye'
Plug 'ap/vim-buftabline'
Plug 'lifepillar/vim-mucomplete'
Plug 'shurizzle/vim-rfc'
if !has('plan9')
Plug 'tpope/vim-fugitive'
call plug#end()
endif
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment