LinuxQuestions.org
Share your knowledge at the LQ Wiki.
Go Back   LinuxQuestions.org > Forums > Linux Forums > Linux - Newbie
User Name
Password
Linux - Newbie This Linux forum is for members that are new to Linux.
Just starting out and have a question? If it is not in the man pages or the how-to's this is the place!

Notices


Reply
  Search this Thread
Old 02-27-2011, 01:15 PM   #1
xeon123
Member
 
Registered: Sep 2006
Posts: 374

Rep: Reputation: 16
create command in vim


Hi,

I would like to create a command in the vim that saves a tex document and also compile it. Is it possible?

Thanks,
 
Old 02-27-2011, 01:25 PM   #2
druuna
LQ Veteran
 
Registered: Sep 2003
Posts: 10,532
Blog Entries: 7

Rep: Reputation: 2389Reputation: 2389Reputation: 2389Reputation: 2389Reputation: 2389Reputation: 2389Reputation: 2389Reputation: 2389Reputation: 2389Reputation: 2389Reputation: 2389
Hi,

I have these 2 in place (~/.vimrc):
Code:
" -----------------------------------------------------------------------------
"  f5 -> Compile (gcc) written code
map <F5> : call CompileGcc()<CR>
func! CompileGcc()
  exec "w"
  exec "!gcc % -o %<"
endfunc

" -----------------------------------------------------------------------------
"  shift f5 ->Compile (gcc) and run written code
map <S-F5> :call CompileRunGcc()<CR>
func! CompileRunGcc()
  exec "w"
  exec "!gcc % -o %<"
  exec "! ./%<"
endfunc
F5 -> Write file + compile using gcc.
Shift-F5 -> Write file + compile file (gcc) + run file.

Tailor the above to your liking.

Hope this helps.
 
Old 02-28-2011, 03:23 AM   #3
xeon123
Member
 
Registered: Sep 2006
Posts: 374

Original Poster
Rep: Reputation: 16
And if I want a general compile method?

For example, if the file extension of my file is .c, I press F5 and I compile it with gcc, if the file is .java, I compile it with javac, if the file is .tex, I compile it with latex, etc...

Thanks,
 
Old 02-28-2011, 03:32 AM   #4
xeon123
Member
 
Registered: Sep 2006
Posts: 374

Original Poster
Rep: Reputation: 16
I've found the answer:

Code:
autocmd FileType java       nnoremap <buffer> <silent> <f5> :!javac %:p<cr>
autocmd FileType cpp        nnoremap <buffer> <silent> <f5> :!gcc %:p<cr>
autocmd FileType c        nnoremap <buffer> <silent> <f5> :!gcc %:p<cr>
autocmd FileType tex        nnoremap <buffer> <silent> <f5> :!latex %:p<cr>
 
Old 02-28-2011, 05:49 AM   #5
druuna
LQ Veteran
 
Registered: Sep 2003
Posts: 10,532
Blog Entries: 7

Rep: Reputation: 2389Reputation: 2389Reputation: 2389Reputation: 2389Reputation: 2389Reputation: 2389Reputation: 2389Reputation: 2389Reputation: 2389Reputation: 2389Reputation: 2389
You're welcome

Nice to see you got the answer to your second question, and posted the solution!
 
  


Reply


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
Editor comparison: vim VS vim-lite, Cleaning vim Ruler2112 *BSD 4 04-13-2009 04:26 PM
The command ' wq ' in vi and vim Gins Linux - General 3 02-24-2008 07:07 AM
vi / vim command shahed Linux - Newbie 1 12-06-2006 11:10 PM
is it possible to create vim macro to..... hedpe Linux - Software 1 06-16-2005 08:41 PM
How do I create a symbolic link so vi opens up vim? blk96gt Slackware 4 06-14-2004 03:53 AM

LinuxQuestions.org > Forums > Linux Forums > Linux - Newbie

All times are GMT -5. The time now is 11:42 AM.

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
Facebook: linuxquestions Google+: linuxquestions
Open Source Consulting | Domain Registration