Advertisement
Azuhmier

hmofa.vim

Apr 21st, 2020
2,837
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
VIM 7.74 KB | None | 0 0
  1. "===============================================================================
  2. "
  3. "             FILE: hmofa.vim
  4. " Date of Creation: Sat 11/23/19 09:41:45
  5. "           AUTHOR: Azuhmier
  6. "===============================================================================
  7. let s:dir_setup_FILE = "/Users/Work/.vim/bundle/vim_hmofa/autoload/dir_setup.vim"
  8.  
  9. augroup hmofa
  10.   au!
  11.   au BufWritePost /Users/Work/.hmofa/.dirty exe "so " . s:dir_setup_FILE
  12. augroup end
  13.  
  14. "-----| -= |-----{{{
  15. let g:hmofa_master_dir = 'nada'
  16. nnoremap <leader>= :Goto<enter>
  17.  
  18.   "-----| :Goto |-----"
  19.   command! Goto call Goto_fun()
  20.  
  21.     "-----| Goto_fun() |-----"
  22.     function! Goto_fun()
  23.       " FUN VARS "{{{
  24.       let l:library   = "/Users/Work/Documents/hmofa/pastebin/Library.txt"
  25.       let l:library2  = "/Users/Work/Documents/hmofa/pastebin/code_examples/txt_files/lib_copy.txt"
  26.       let l:dir       = "/Users/Work/Documents/hmofa/pastebin/code_examples/goto_files*"
  27.       let l:dir_2     = '/Users/Work/Documents/hmofa/fics*'
  28.       let l:url_dir   = "/Users/Work/Documents/hmofa/pastebin/code_examples/goto_files/url.txt"
  29.  
  30.       let l:any      = "goto_files*/*"
  31.       let l:tag_list = 'tag_names.txt'
  32.       let l:tag_bin  = 'tag_bin.txt'
  33.       let l:op_list  = 'op_names.txt'
  34.       let l:op_bin   = 'ops.txt'
  35.       "}}}
  36.       "-----| MAIN |-----"
  37.       let l:current_file = expand('%:p')
  38.  
  39.         "-----| LIBRARY |-----"
  40.         " IF -  current file is a library
  41.         if l:current_file == l:library || l:current_file == l:library2
  42.           " go to alt. file
  43.           let l:buf_N = bufnr('%')
  44.           execute "normal \<C-^>"
  45.           silent execute ":bd".l:buf_N
  46.  
  47.         "-----| TAG AND OP LIST |-----"
  48.         " Elseif - current fIle is a tag_list
  49.         elseif (l:current_file =~ l:tag_list || l:current_file =~ l:op_list) && l:current_file =~ l:dir
  50.  
  51.           let l:line =  getline(".") " get entire line
  52.  
  53.           " get only the numbers from the line
  54.             " Template - {number} {tag}
  55.           let l:LN  = matchstr(l:line,'^\d\+\s\+')
  56.           let l:tag = substitute(l:line,l:LN,"","")
  57.           let l:LN  = substitute(l:LN," ","","g")
  58.  
  59.           let l:alt_file = expand('%:p') " set current file as the alt. file
  60.  
  61.  
  62.           "-----| TAG_BIN |-----"
  63.             if l:current_file =~ l:tag_list
  64.               execute "e ".l:tag_bin
  65.             else
  66.               execute "e ".l:op_bin
  67.             endif
  68.  
  69.           let l:buf_N = bufnr('%')
  70.           execute "normal ".l:LN."G"
  71.           let l:line_2 =  getline(".")
  72.  
  73.           " get only the numbers from the line
  74.           let l:LN_2 = matchstr(l:line_2,'^\d\+\s\+')
  75.           let l:LN_2 = substitute(l:LN_2," ","","g")
  76.  
  77.           "-----| LIBRARYY |-----"
  78.             if l:current_file =~ 'goto_files2'
  79.               execute "e ".l:library2
  80.             else
  81.               execute "e ".l:library
  82.             endif
  83.  
  84.           silent execute ":bd".l:buf_N
  85.           setlocal autowrite
  86.           execute "normal ".l:LN_2."G"
  87.  
  88.           let @# = l:alt_file
  89.             if l:current_file =~ l:op_list
  90.               let @/ =  '\]\[.*\].*\zs\V'.l:tag.'\m\ze'
  91.             else
  92.               let @/ =  '\V[\.\*,\s\zs'.l:tag.'\ze?\*,\.\*]
  93.                      \\|[\zs'.l:tag.'\ze?\*,\.\*\]
  94.                      \\|[\.\*,\s\zs'.l:tag.'\ze?\*]
  95.                      \\|[\zs'.l:tag.'\ze?\*]'
  96.               let @r =  '\V[\.\*\zs,\s'.l:tag.'?\*\ze,\.\*]
  97.                      \\|[\zs'.l:tag.'?\*,\ze\.\*\]
  98.                      \\|[\.\*\zs,\s'.l:tag.'?\*\ze]
  99.                      \\|[\zs'.l:tag.'?\*\ze]'
  100.             endif
  101.           execute "normal /\<cr>"
  102.  
  103.         "------| FICS/NOTES |------"
  104.         elseif l:current_file =~ l:dir_2
  105.           let l:url  = getline('.')
  106.           let l:url  = substitute(l:url,'\s','',"g")
  107.           let l:url  = escape(l:url, '/.')
  108.           let l:alt_file = expand('%:p') " set current file as the alt. file
  109.  
  110.           exe "e ".l:url_dir
  111.           exe "normal /".l:url."\<enter>"
  112.  
  113.           let l:line =  getline(".")
  114.           " get only the numbers from the line
  115.           let l:LN = matchstr(l:line,'^\d\+\s\+')
  116.           let l:tag = substitute(l:line,l:LN,"","")
  117.           let l:LN = substitute(l:LN," ","","g")
  118.  
  119.           "------| LIBRARYY |------"
  120.           execute "e ".l:library
  121.           setlocal autowrite
  122.           let @# = l:alt_file
  123.           execute "normal ".l:LN."G"
  124.           execute "normal 2k"
  125.  
  126.  
  127.         "------| OTHER |------"
  128.         elseif l:current_file =~ "goto_files"
  129.           let l:line =  getline(".")
  130.           "get only the numbers from the line
  131.           let l:LN = matchstr(l:line,'^\d\+\s\+')
  132.           let l:tag = substitute(l:line,l:LN,"","")
  133.           let l:LN = substitute(l:LN," ","","g")
  134.           "remember the taglist
  135.           let l:alt_file = expand('%:p')
  136.  
  137.           "------| LIBRARY |------"
  138.             if l:current_file =~ 'goto_files2'
  139.               execute "e ".l:library2
  140.             else
  141.               execute "e ".l:library
  142.             endif
  143.           setlocal autowrite
  144.           let @# = l:alt_file
  145.           execute "normal ".l:LN."G"
  146.  
  147.         else
  148.         echoerr "No can do"
  149.         endif
  150.     endfunction
  151. "}}}
  152. " ----- | Ntk | -----"{{{
  153. vnoremap <esc>b vNNgn
  154. vnoremap <esc>f vngn
  155. "Enter Tag Mode
  156. nnoremap <leader>n :Ntk<enter>
  157. " ---| Ntk |--- "
  158.   command Ntk call Ntk_fun()
  159.     " ---| Ntk_fun() |--- "
  160.     function Ntk_fun()
  161.       "Fun Vars"
  162.       let l:dir = '/Users/Work/Documents/hmofa/fics*'
  163.       let l:cur_dir = expand('%:p')
  164.      
  165.         "Where am I?
  166.         "If; cwd eq to l:dir
  167.         if l:cur_dir =~ l:dir
  168.           "If; Cur_fname Contains the String 'NOTES'    
  169.           if l:cur_dir =~ 'NOTES'
  170.             exe 'noh'
  171.             let l:tag = '\[^,]\*'
  172.             let @/ = '\%>12l\%<35l\[\@<=\([^,\]]\)\+
  173.                  \\|\%>12l\%<32l\(\1,\s\)\@<=[^,\]]\+'
  174.             exe "normal /<C-r>/"
  175.             exe "normal ngn"
  176.           endif
  177.         else
  178.           echo 'No Can Do'
  179.         endif
  180.     endfunction
  181.  
  182. " -----| Ntk2 |----- "
  183. "rm tag
  184. "<C-u> is used to delete from cursor to the beginning of the Cmd_Line
  185. vnoremap <esc><down> :<c-u>Ntk2<enter>
  186.  
  187.   " ---| Ntk2 |--- "
  188.   command  Ntk2 call Ntk2_fun()
  189.     " ---| Ntk2_fun() |--- "
  190.     function Ntk2_fun()
  191.       " GoTo Prev Visl Sel and Copy it
  192.       exe "normal gvy"
  193.       let l:cur_tag = getreg('"')
  194.       "Escape the Fwd Slashes
  195.       let l:cur_tag = escape(l:cur_tag, '/')
  196.       exe '6s/\V'.l:cur_tag.'?\*,\s
  197.             \\|,\s'.l:cur_tag.'?\*\ze]
  198.             \\|[\zs'.l:cur_tag.'?\*\ze]//'
  199.       exe "normal \<C-o>"
  200.       exe "normal gv"
  201.     endfunction
  202.  
  203. " -----| Ntk3 |----- "
  204. "add tag
  205. "<C-u> is used to delete from cursor to the beginning of the cmd_line
  206. vnoremap <esc><up> :<c-u>Ntk3<enter>
  207. " ---| Ntk3 |--- "
  208.   command  Ntk3 call Ntk3_fun()
  209.     " ---| Ntk3_fun() |--- "
  210.     function Ntk3_fun()
  211.       " go to prev visl sel and copy it
  212.       exe "normal gvy"
  213.       let l:cur_tag = getreg('"')
  214.       let l:line = line(".")
  215.       "escape the fwd slashes
  216.       let l:cur_tag = escape(l:cur_tag, '/')
  217.       let l:tagline = getline(6)
  218.       let l:grp_a = substitute(l:tagline, '\[[^\[\]]*\]\zs\[[^\]\[]*\].*',"","")  
  219.       let l:grp_b = substitute(l:tagline, '\zs\[[^\[\]]*\]\ze\[[^\]\[]*\]',"","")  
  220.  
  221.         if l:line == 13 || l:line == 14 || l:line == 19
  222.           if l:grp_a =~ '[]'
  223.             exe '6s/\(\V[\)/\1'.l:cur_tag.'/'
  224.           else
  225.             exe '6s/\(\V[\)/\1'.l:cur_tag.', /'
  226.           endif
  227.         else
  228.           if l:grp_b =~ '[]'
  229.             exe '6s/\(\V[\.\*][\)/\1'.l:cur_tag.'/'
  230.           else
  231.             exe '6s/\(\V[\.\*][\)/\1'.l:cur_tag.', /'
  232.           endif
  233.         endif
  234.  
  235.       exe "normal \<C-o>"
  236.       exe "normal gv"
  237.     endfunction
  238. "}}}
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement