dotfiles

Cross platform dotfiles for linux, mac and windows
git clone git@getsh.org:dotfiles.git
Log | Files | Refs

plugin.vim (1570B)


      1 " Strip the newline from the end of a string
      2 function! Chomp(str)
      3   return substitute(a:str, '\n$', '', '')
      4 endfunction
      5 
      6 " Find a file and pass it to cmd
      7 function! DmenuOpen(cmd)
      8   let fname = Chomp(system("git ls-files | dmenu-mac -i -l 20 -p " . a:cmd))
      9   if empty(fname)
     10     return
     11   endif
     12   execute a:cmd . " " . fname
     13 endfunction
     14 
     15 " find file in git repo
     16 function! ChooseFile()
     17   let dir = expand("%:h")
     18   if empty(dir) | let dir = getcwd() | endif
     19 
     20   let root = system("cd " . dir . " && git rev-parse --show-toplevel")
     21   if v:shell_error != 0 | echo "Not in a git repo" | return | endif
     22   let root = root[0:-2]
     23 
     24   let selection = system("cd " . root . " && git ls-files -co --exclude-standard | choose")
     25   if empty(selection) | echo "Canceled" | return | end
     26 
     27   echo "Finding file..."
     28   exec ":e " . root . "/" . selection
     29 endfunction
     30 
     31 function! DiffWithSaved()
     32   let filetype=&ft
     33   diffthis
     34   vnew | r # | normal! 1Gdd
     35   diffthis
     36   exe "setlocal bt=nofile bh=wipe nobl noswf ro ft=" . filetype
     37 endfunction
     38 
     39 " Move to a file common to nvim and vim
     40 function! ToggleList()
     41 	if &list == "nolist"
     42 		set list
     43 	else
     44 		set nolist
     45 	endif
     46 endfunction
     47 
     48 function! ToggleBackground()
     49 	if &background == "light"
     50 		set background=dark
     51 	else
     52 		set background=light
     53 	endif
     54 endfunction
     55 
     56 function! FileMvHelper()
     57 	:normal! 0i"A"0y$A p0imv j0
     58 endfunction
     59 " Run Make
     60 
     61 function SaveAndBuild()
     62 		wall
     63 		Make
     64 endfunction
     65 
     66 function QuickUnderline(n)
     67 	if a:n == 1
     68 		normal! yypv$r=
     69 	else
     70 		normal! yypv$r-
     71 	endif
     72 endfunction
     73 
     74 function ReverseDate()
     75 	normal! dt/wwpldeBP
     76 endfunction
     77 
     78