scripting - Vim script: Buffer/CheatSheet Toggle -


i want make vim cheat sheet plugin. it's real simple:

  • i want toggle cheatsheets. vertsplit toggle, taglist or nerdtree.
  • i want cheatsheet filetype specific. toggle c++ cheatsheet when have opened .cpp file.
  • i want cheatsheet horizontally split. shows 2 files, syntax cheat sheet , snippet trigger cheat sheet.

i have collection of these cheatsheets, in vimhelp format, have manually open them.

i haven't done vim scripting, imagine simple put together. i'm sorta sick of googling unrelated codesnippets, i'm asking here is:

  1. could give me short sum-up of need learn in regards vim scripting piece together. have hard time finding how toggle buffer window.

  2. if know intro tutorials covers material need , running, please provide link.

tx,

aktivb

the function below may not want, , haven't tested it, should give ideas.

the main idea function reads filetype of current buffer (you can test typing :echo &ft) , sets path of appropriate cheat sheat. if exists, path opened (read-only , non-modifiable) in split window. can call function way wish, example mapping {f5} key shown.

i'm not sure toggling possibilities (is easier closing split window?) @ bufloaded() function, returns whether or not given file being accessed.

function! load_cheat_sheet()     let l:ft = &ft      if l:ft == 'html'         let l:path = 'path/to/html/cheat/sheet'     elseif l:ft == 'c'         let l:path = 'path/to/c/cheat/sheet'     elseif l:ft == 'tex'         let l:path = 'path/to/tex/cheat/sheet'     endif      if l:path != '' && filereadable(l:path)         execute ':split +setlocal\ noma\ ro ' l:path     endif endfunction  map <f5> :call load_cheat_sheet()<cr> 

hope helps. shout if unclear, or want know more.


Comments

Popular posts from this blog

c# - How to set Z index when using WPF DrawingContext? -

razor - Is this a bug in WebMatrix PageData? -

android - layout with fragment and framelayout replaced by another fragment and framelayout -