You are not logged in.

#1 2006-12-02 22:38:07

cschep
Member
Registered: 2006-12-02
Posts: 124
Website

vim? - or more editor (ide?) questions!

Hello All,

I went through college recently, got my CS major and have only used MS products and compilers and IDE's the whole time! That's what happens when you live in WA, I suppose.

I had a few run-ins with linux in my college days but it didn't stick. Recently I discovered arch and it stuck. The keep it simple attitude combined with awesome package management that you don't have wait for (gentoo compile times yikes). In short I'm really enjoying it.

Anyway, I'm here now and I'm just starting to edit code with Vim and I just discovered Gvim. I've been just leaving a terminal open and switching to it to compile/run the code and editing in the Gvim window. This works, but it's...just not that slick.

What I'm here to ask is how YOU do it? Mostly I'm asking Vim users, but if you've got a slick system for editing/compiling code I'd love to hear about it.

I've got eclipse downloaded and installed with cdt, it works like a champ but I've been really enjoying Vim, and I want to continue to use it and get faster with it.

I've seen screen shots of code completion inside Vim as well. That would be slick.

Basically, can I get code completion and compiling done inside the Vim window? How about breakpoints for debugging?

How about 2 of 3? smile

Thanks for the help and thanks to the arch devs!

Offline

#2 2006-12-02 23:33:03

pauldonnelly
Member
Registered: 2006-06-19
Posts: 776

Re: vim? - or more editor (ide?) questions!

Well, see :help make for starters.

Offline

#3 2006-12-02 23:35:36

cschep
Member
Registered: 2006-12-02
Posts: 124
Website

Re: vim? - or more editor (ide?) questions!

So a make file is required to build within Vim?

Offline

#4 2006-12-02 23:40:17

pauldonnelly
Member
Registered: 2006-06-19
Posts: 776

Re: vim? - or more editor (ide?) questions!

I believe you can use any program, as long as you tell Vim the proper command to run. A makefile or equivalent is probably easiest in the long run.

Breakpoints seem to be controlled with :breakadd and :breakdel.

I don't actually program with Vim myself. I use Emacs+Slime, since it's pretty much the best Lisp development environment around. This is just some hints that I've picked up.

Offline

#5 2006-12-03 00:42:08

alger
Member
Registered: 2006-09-01
Posts: 39
Website

Re: vim? - or more editor (ide?) questions!

It's actually a lot easier. with :! program you can run any program  from vi. For example to compile and run in java:

:w
:! javac % (vim substitutes the % with the file you are editing)
:! java package.MainClass

Since vim keeps history of commands you only have to type it once, then you can use the up arrow

Tabs are also very useful when editing source code:

:tabe file (to open file in a new tab)
gt (to move between tabs)

Offline

#6 2006-12-03 04:57:13

battra
Member
From: Earth.US.Illinois.Chicago
Registered: 2006-05-12
Posts: 71

Re: vim? - or more editor (ide?) questions!

There are many vim plugins available some of which give vim IDE-like features:
http://www.vim.org/scripts/script_search_results.php

The main ones I use are:
taglist: navigating within a file (and also between)
bufexplorer: navigating between files
NERD_commenter

They have code completion plugins there for various languages.

And, here's a debugger plugin:

http://www.vim.org/scripts/script.php?script_id=663


"I know nothing except the fact of my ignorance."
- Socrates

Offline

#7 2006-12-03 18:59:40

phrakture
Arch Overlord
From: behind you
Registered: 2003-10-29
Posts: 7,879
Website

Re: vim? - or more editor (ide?) questions!

cschep wrote:

Anyway, I'm here now and I'm just starting to edit code with Vim and I just discovered Gvim. I've been just leaving a terminal open and switching to it to compile/run the code and editing in the Gvim window. This works, but it's...just not that slick.

Well, the way it *should* work, is actually not the :!command way others have shown here, though that is very useful.

Vim comes bundled with (and there's tons more on www.vim.org) what are called "compiler" scripts. See /usr/share/vim/compiler.

Let's say we're writing sooooomme.... hmmm.. java code.  When we want to compile it, it's as simple as:

:w
:compiler javac
:make

The ":compiler" line only needs to be called once for the lifetime of that session.  It actually does two things.  It sets 'makeprg', which is the application used when you type ":make".  It also sets 'errorformat', which is used to properly parse and find the errors.  For instance, it you ran the above and there were 10 errors from javac, vim would, firstly, move to the line of the first error listed, and secondly, fill in a list of errors (not displayed by default) for you to jump around to, and look at.  You can use :copen or :cwindow to view the error list after a :make.

Offline

#8 2006-12-03 19:04:56

phrakture
Arch Overlord
From: behind you
Registered: 2003-10-29
Posts: 7,879
Website

Re: vim? - or more editor (ide?) questions!

Just two clarifications:

battra wrote:

taglist: navigating within a file (and also between)

taglist actually does no navigation.  The navigation is built into vim's interface with 'ctags'.  It just so happens that taglist _uses_ ctags, and in doing so, it creates tags files for vim to use for navigation.

battra wrote:

They have code completion plugins there for various languages.

Code completion itself is facilitated by vim itself.  But parsing different languages requires plugins (much like syntax files and everything else).  They use functionality called "omni completion".  Quite a few of these languages are provided for in the base vim install itself (c, css, html, xml, javascript, ruby, python, and "syntax" which uses a languages syntax definition form completions - a great fallback).

Offline

#9 2006-12-03 19:06:54

sweiss
Member
Registered: 2004-02-16
Posts: 635

Re: vim? - or more editor (ide?) questions!

Speaking of which, is there a tutorial which describes how to use Vim as a development environment rather than just a text editor?

That would be something worth bookmarking.

Offline

#10 2006-12-03 22:01:26

elasticdog
Member
From: Washington, USA
Registered: 2005-05-02
Posts: 995
Website

Re: vim? - or more editor (ide?) questions!

phrakture, you may know this one...I've always wondered if there is a quick way to run a java program from Vim without having to type in the whole <code>myprogramname</code> after you compile it, since <code>%</code> obviously won't work since it would have the <code>.java</code> on the end.  Is there an easier way to just have the basename of the file?

Offline

#11 2006-12-03 22:14:19

alger
Member
Registered: 2006-09-01
Posts: 39
Website

Re: vim? - or more editor (ide?) questions!

phrakture wrote:

Let's say we're writing sooooomme.... hmmm.. java code.  When we want to compile it, it's as simple as:

:w
:compiler javac
:make

The ":compiler" line only needs to be called once for the lifetime of that session.  It actually does two things.  It sets 'makeprg', which is the application used when you type ":make".  It also sets 'errorformat', which is used to properly parse and find the errors.  For instance, it you ran the above and there were 10 errors from javac, vim would, firstly, move to the line of the first error listed, and secondly, fill in a list of errors (not displayed by default) for you to jump around to, and look at.  You can use :copen or :cwindow to view the error list after a :make.

I'm trying to use this, and i have to tipe :make %, else javac complains about not getting arguments.  :?

Offline

#12 2006-12-04 17:27:33

phrakture
Arch Overlord
From: behind you
Registered: 2003-10-29
Posts: 7,879
Website

Re: vim? - or more editor (ide?) questions!

elasticdog wrote:

phrakture, you may know this one...I've always wondered if there is a quick way to run a java program from Vim without having to type in the whole <code>myprogramname</code> after you compile it, since <code>%</code> obviously won't work since it would have the <code>.java</code> on the end.  Is there an easier way to just have the basename of the file?

Here ya go:

:make %:r.java
For more:
:h expand

Offline

#13 2006-12-04 19:39:29

NeOnsKuLL
Member
From: Havana, Cuba
Registered: 2005-03-29
Posts: 117

Re: vim? - or more editor (ide?) questions!

If you need something like Eclipse (I mean some of eclipse features), but more lightweight, like VIM, try eclim [1]. Eclim "brings Eclipse functionality to Vim". It sounds like you need.

See you

NeOnsKuLL

[1] Eclim AUR Page


Intel Core 2 Duo E8400 3.0 GHz | 2x1GB 667MHz | 250+750GB Seageate SATAII | Samsung 19" TFT 1440x900
Openbox + obmenugen + PyTyle | bmpanel2 | oblogout | conky | pyBgSetter (with Esetroot as backend)
Projects: obmenugen, pyBgSetter

Offline

#14 2006-12-04 21:57:28

elasticdog
Member
From: Washington, USA
Registered: 2005-05-02
Posts: 995
Website

Re: vim? - or more editor (ide?) questions!

phrakture wrote:
elasticdog wrote:

phrakture, you may know this one...I've always wondered if there is a quick way to run a java program from Vim without having to type in the whole <code>myprogramname</code> after you compile it, since <code>%</code> obviously won't work since it would have the <code>.java</code> on the end.  Is there an easier way to just have the basename of the file?

Here ya go:

:make %:r.java
For more:
:h expand

Damn!  You never cease to amaze me with Vim knowledge, thanks.  Must...learn...more... big_smile

Reading the help file and messing around with it a bit yields this set of commands to compile and then run a java program:

:make %
:!java %:r

VERY COOL!

Offline

#15 2006-12-05 01:51:36

codemac
Member
From: Cliche Tech Place
Registered: 2005-05-13
Posts: 794
Website

Re: vim? - or more editor (ide?) questions!

So I was looking for a way to have a dwm like setup.

Best new key stroke : CTRL-w CTRL-r

rotates windows.  Now I can have a fake zoom like dwm.  Hurrah!

Offline

Board footer

Powered by FluxBB