LinuxQuestions.org
Review your favorite Linux distribution.
Home Forums Tutorials Articles Register
Go Back   LinuxQuestions.org > Forums > Non-*NIX Forums > Programming
User Name
Password
Programming This forum is for all programming questions.
The question does not have to be directly related to Linux and any language is fair game.

Notices


Reply
  Search this Thread
Old 07-05-2011, 07:25 AM   #1
texasone
Member
 
Registered: Jun 2008
Location: /home/lorax
Distribution: Debian Testing
Posts: 141

Rep: Reputation: Disabled
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
 
Old 07-06-2011, 09:22 PM   #2
Tinkster
Moderator
 
Registered: Apr 2002
Location: earth
Distribution: slackware by choice, others too :} ... android.
Posts: 23,067
Blog Entries: 11

Rep: Reputation: 928Reputation: 928Reputation: 928Reputation: 928Reputation: 928Reputation: 928Reputation: 928Reputation: 928
Moved: This thread is more suitable in <PROGRAMMING> and has been moved accordingly to help your thread/question get the exposure it deserves.
 
Old 07-07-2011, 12:24 AM   #3
Wim Sturkenboom
Senior Member
 
Registered: Jan 2005
Location: Roodepoort, South Africa
Distribution: Ubuntu 12.04, Antix19.3
Posts: 3,794

Rep: Reputation: 282Reputation: 282Reputation: 282
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
 
Old 07-07-2011, 09:20 AM   #4
texasone
Member
 
Registered: Jun 2008
Location: /home/lorax
Distribution: Debian Testing
Posts: 141

Original Poster
Rep: Reputation: Disabled
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).
 
  


Reply

Tags
mapping, vim



Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is Off
HTML code is Off



Similar Threads
Thread Thread Starter Forum Replies Last Post
Vim plugin for hiding block comments sadarax Linux - General 9 03-31-2014 05:54 PM
Start a terminal with pre-typed text? dh2k Slackware 2 04-17-2011 11:17 AM
hiding typed text with asterisks dolphs Linux - General 8 08-27-2008 08:25 AM
start vim when vi is typed PlatinumRik Linux - Software 7 03-15-2004 04:24 PM
vim - comments formatting alexLinux Programming 0 12-24-2003 04:22 PM

LinuxQuestions.org > Forums > Non-*NIX Forums > Programming

All times are GMT -5. The time now is 01:56 PM.

Main Menu
Advertisement
My LQ
Write for LQ
LinuxQuestions.org is looking for people interested in writing Editorials, Articles, Reviews, and more. If you'd like to contribute content, let us know.
Main Menu
Syndicate
RSS1  Latest Threads
RSS1  LQ News
Twitter: @linuxquestions
Open Source Consulting | Domain Registration