Download your favorite Linux distribution at LQ ISO.
Go Back > Forums > Non-*NIX Forums > Programming
User Name
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.


  Search this Thread
Old 07-05-2011, 07:25 AM   #1
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.
" 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)
    call append(ln-1, word)
(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
Old 07-06-2011, 09:22 PM   #2
Registered: Apr 2002
Location: in a fallen world
Distribution: slackware by choice, others too :} ... android.
Posts: 23,067
Blog Entries: 11

Rep: Reputation: 910Reputation: 910Reputation: 910Reputation: 910Reputation: 910Reputation: 910Reputation: 910Reputation: 910
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: Slackware 10.1/10.2/12, Ubuntu 12.04, Crunchbang Statler
Posts: 3,786

Rep: Reputation: 282Reputation: 282Reputation: 282
Not sure if this will help

I can find my way around vi but have never used functions, mappings etc
Old 07-07-2011, 09:20 AM   #4
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).


mapping, vim

Thread Tools Search this Thread
Search this Thread:

Advanced Search

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 > Forums > Non-*NIX Forums > Programming

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

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