LinuxQuestions.org

LinuxQuestions.org (/questions/)
-   Programming (https://www.linuxquestions.org/questions/programming-9/)
-   -   Create doc comments in vim using pre-typed text (https://www.linuxquestions.org/questions/programming-9/create-doc-comments-in-vim-using-pre-typed-text-890011/)

texasone 07-05-2011 07:25 AM

Create doc comments in vim using pre-typed text
 
Okay, I currently have a set up in vim so that when I type "<leader>ns" it takes any given word and turns it into a sub "sub word(){}". I also have it when I type "<leader>nc" it creates a doc comment section that is "blank". I was wondering if someone could help me out with combining the two so that when I typed <leader>ns it would create the doc comments with the word already in the Subroutine: line and create the new sub routine aswell. I'm trying to understand what I have (downloaded from the internet) and only doing so so. If someone could help explain how the vim function works, I might be able to go from there but I can't really find any relevant info online for it.
Code:

" Put cursor over word and hit ,ns to create new Sub
nmap <leader>nc o
#------------------------------------------------------------------------------
# Subroutine:
# Function  :
# Parms    :
# Returns  :
# Assumes  :
#------------------------------------------------------------------------------



nnoremap <Leader>ns :call Newsub()<CR>
function! Newsub()
  let word = "sub " . expand("<cword>") . "()" . " {" . "}"
  let ln = search("__.*__", 'nW')
  if ln == 0
    call append('$', word)
  else
    call append(ln-1, word)
  endif
endfunction

(the <leader>nc is formatted in vim so that it creates it to look like that [aka, all one line with ctrl-v ctrl-m seperating them])
Thank you
RzITex

Tinkster 07-06-2011 09:22 PM

Moved: This thread is more suitable in <PROGRAMMING> and has been moved accordingly to help your thread/question get the exposure it deserves.

Wim Sturkenboom 07-07-2011 12:24 AM

Not sure if this will help

http://www.eandem.co.uk/mrw/vim/usr_doc/index.html
http://researchweb.iiit.ac.in/~smr/d...m_tutorial.pdf

I can find my way around vi but have never used functions, mappings etc

texasone 07-07-2011 09:20 AM

thanks Wim. I was only able to get to the researchweb pdf because of firewall. I'm definitely going to keep that pdf close by. Had a lot of great info (and some spelling errors). It didn't really help that much in relation to an insertion function like I'm trying to do. I just asked on stackoverflow to see if I could get eyes on the topic (will relay answer here if it works).

I'm pretty much the same as you. I can navigate and use vi/vim (though I'm barely touching vim's power).


All times are GMT -5. The time now is 06:25 PM.