Vim Tips Wiki
No edit summary
 
(→‎Vim Functionality: add back gundo)
(40 intermediate revisions by 19 users not shown)
Line 1: Line 1:
  +
{{TipImported
{{review}}
 
{{Tip
 
 
|id=1119
 
|id=1119
  +
|previous=1118
|title=How to use Vim like an IDE
 
  +
|next=1120
|created=February 3, 2006 20:51
 
  +
|created=2006
 
|complexity=intermediate
 
|complexity=intermediate
 
|author=Matt Zyzik
 
|author=Matt Zyzik
 
|version=6.0
 
|version=6.0
 
|rating=121/61
 
|rating=121/61
  +
|category1=Integration
|text=
 
  +
|category2=
I personally use Vim for all text editing, even software development. At one point I stopped using IDEs. One major reason is that Vim can do all the major things I need from IDEs (tabs, file trees, greping, syntax highlighting, indentation, completion, "quickfix"ing, etc.). Vim 7 will be introducing one of the most critical features: completion (intellisense).
 
  +
}}
  +
I use Vim for all text editing, even software development. At one point I stopped using IDEs. One major reason is that Vim can do all the major things I need from IDEs (tabs, file trees, greping, syntax highlighting, indentation, completion, "quickfix"ing, etc).
   
  +
==Vim Plugins==
  +
Still Vim needs plugins to do some IDE-like things that aren't built in. Here are some Vim scripts that make Vim more like an IDE.
   
  +
Note: You can use {{script|id=2332|text=pathogen}} to isolate your plugins and make it easier to experiment with new plugins.
   
  +
===Project/Filetree Browsing===
Still Vim needs plugins to do some IDE-like things that aren't built in.
 
  +
*{{script|id=1658|text=NERDTree}} is a tree explorer plugin for navigating the filesystem.
  +
*{{script|id=184|text=vtreeexplorer}} is a tree based file explorer.
  +
*{{script|id=69|text=project}} gives you a "project" view of files, rather than a straight file system view
  +
*{{script|id=3855|text=ide}} Tracks files status (open/edited/closed/read only) within a project with icons; automatically builds and updates syntax highlight rules based on the project files (C/C++/Java); avoids buffer duplication; see [http://dgomezpr.com/ece/code/ide-vim demo].
  +
*{{help|netrw}} for information about the explorer distributed with Vim. It does not display files in a tree by default, but can by using the {{help|prefix=no|g:netrw_liststyle}} option. It also offers useful file-sorting options (by date, size, name).
   
  +
===Buffer/File Browsing===
One thing you might want is the vtreeexplorer (http://vim.org/scripts/script.php?script_id=184) plugin, which allows you to have a "file list" in a vertically split window. Another thing worth considering is the minibufexpl (http://vim.org/scripts/script.php?script_id=159) plugin, which will allow for tabs of all your files (works really well).
 
  +
*{{script|id=42|text=bufexplorer}} lets you navigate through open buffers
  +
*{{script|id=159|text=minibufexpl}} Elegant buffer explorer; takes very little screen space.
  +
*{{script|id=1581|text=lookupfile}} Lookup files using Vim7 ins-completion
  +
*[https://wincent.com/products/command-t/ Command-T plugin], inspired by the "Go to File" window bound to Command-T in TextMate
  +
*{{script|id=521|text=MRU}} access recently opened files.
  +
*[http://www.vim.org/scripts/script.php?script_id=3736 ctrlp] Fuzzy file, buffer, mru, tag, ... finder with regexp support. Writen in vim language. Access all the functions with '''ctrl-p'''
  +
*[http://www.vim.org/scripts/script.php?script_id=1984 FuzzyFinder] same as previous.
   
  +
===Code Browsing===
  +
*{{script|id=273|text=taglist}} gives you an outline of the source you're viewing
  +
*{{script|id=3465|text=Tagbar}} similar to taglist but can order tags by scope. Recommend for programming languages with classes, e.g. C++, Java, Python.
  +
*{{script|id=3221|text=Indexer}} generates tags for all files in project automatically and keeps tags up-to-date. Using ctags. Works well with project plugin or independently.
  +
*{{script|id=2368|text=CCTree}} is a Call-Tree Explorer, Cscope based source-code browser, and code flow analyzer.
  +
*{{script|id=1729|text=exUtility}} global search, symbol search, tag track...(Like IDE/Source Insight).
  +
*{{script|id=152|text=ShowMarks}} visually shows the location of marks.
   
  +
See also [[Browsing programs with tags]] and [[Cscope]].
   
  +
===Writing Code===
Yet another thing is in a former tip of mine ([[VimTip1078]]), which allows you to delete a buffer without actually closing the window. Also, below, I have a new, more complicated version of it. The below script will actually create a scratch buffer if there are no listed buffers left. The script, in addition, takes care of a small annoyance. Before, if you 1) open vim, 2) :e a file, 3) :bd, 4) :e the same file... then there will be two buffers listed (that file and a [no name] buffer). The following script ensures this doesn't happen.
 
  +
*A plethora of [[:Category:Automated_Text_Insertion#Related_scripts|code snippet/template plugins]] are available, many offering [[wikipedia:Textmate#Snippets|TextMate]]-like snippet features.
  +
*{{script|id=1879|text=AutoComplPop}} gives you code completion as you type.
  +
*{{script|id=614|text=CRefVim}} A C-reference manual especially designed for Vim.
   
  +
See also [[Omni completion]] and [[Make Vim completion popup menu work just like in an IDE]].
   
  +
===Vim Functionality===
  +
*{{script|id=39|text=matchit}} improves % matching
  +
*{{script|id=1147|text=bufkill}} allows you to delete a buffer without actually closing the window.
  +
*{{script|id=4177|text=undotree}} or {{script|id=3304|text=gundo}} visualizes your undo tree, see [[Using undo branches]].
  +
*{{script|id=1697|text=surround}} makes it easier to delete/change/add parentheses/quotes/XML-tags/much more.
   
  +
===IDE integration===
(Everything in this tutorial and in most of my other tips/tutorials assumes the user does "set hidden".)
 
  +
You may want to use your IDE for some tasks like debugging, so some integration between Vim and the IDE can be helpful.
  +
*[[Integrate gvim with Visual Studio]]
  +
*[http://eclim.org/ Eclim] brings Eclipse functionality to the Vim editor.
   
  +
===Source Control Integration===
Using this Kwbd function (:call Kwbd(1)) will make Vim behave like an IDE; or maybe even better.
 
  +
There are many Vim plugins for different source control management systems. Here are a few.
  +
*{{script|id=90|text=vcscommand.vim}} - CVS/SVN/SVK/git/hg/bzr integration plugin
  +
*{{script|id=2975|text=fugitive}} - git integration
  +
*{{script|id=240|text=perforce}} - perforce integration
  +
*{{script|id=3861|text=lawrencium}} - mercurial integration
   
  +
See also [http://vim.wikia.com/wiki/Category:VersionControl Category:VersionControl]
   
  +
==Debugging==
  +
There are several projects to add debugging functionality to vim
  +
*[http://clewn.sourceforge.net/ Clewn] implements full gdb support in the vim editor: breakpoints, watch variables, gdb command completion, assembly windows, etc.
  +
*[http://jaredforsyth.com/projects/vim-debug/ vim-debug], which creates an integrated debugging environment in VIM.
  +
*{{script|id=84|text= gdbvim}} plugin: Watch in vim what you debug in gdb. And more.
   
  +
==Refactoring==
  +
*[[Vim as a refactoring tool and some examples in C sharp]]
  +
*{{script|id=2087|text='''refactor''' plugin}}
  +
*{{script|id=2164|text='''renamec''' plugin}}
   
  +
==Comments==
 
  +
When using Visual Studio, see [http://www.ngedit.com/viemu.html ViEmu].
"here is a more exotic version of my original Kwbd script
 
 
"delete the buffer; keep windows; create a scratch buffer if no buffers left
 
 
function Kwbd(kwbdStage)
 
 
if(a:kwbdStage == 1)
 
 
if(!buflisted(winbufnr(0)))
 
 
bd!
 
 
return
 
 
endif
 
 
let g:kwbdBufNum = bufnr("%")
 
 
let g:kwbdWinNum = winnr()
 
 
windo call Kwbd(2)
 
 
execute "normal " . g:kwbdWinNum . ""
 
 
let g:buflistedLeft = 0
 
 
let g:bufFinalJump = 0
 
 
let l:nBufs = bufnr("$")
 
 
let l:i = 1
 
 
while(l:i <= l:nBufs)
 
 
if(l:i != g:kwbdBufNum)
 
 
if(buflisted(l:i))
 
 
let g:buflistedLeft = g:buflistedLeft + 1
 
 
else
 
 
if(bufexists(l:i) && !strlen(bufname(l:i)) && !g:bufFinalJump)
 
 
let g:bufFinalJump = l:i
 
 
endif
 
 
endif
 
 
endif
 
 
let l:i = l:i + 1
 
 
endwhile
 
 
if(!g:buflistedLeft)
 
 
if(g:bufFinalJump)
 
 
windo if(buflisted(winbufnr(0))) | execute "b! " . g:bufFinalJump | endif
 
 
else
 
 
enew
 
 
let l:newBuf = bufnr("%")
 
 
windo if(buflisted(winbufnr(0))) | execute "b! " . l:newBuf | endif
 
 
endif
 
 
execute "normal " . g:kwbdWinNum . ""
 
 
endif
 
 
if(buflisted(g:kwbdBufNum) || g:kwbdBufNum == bufnr("%"))
 
 
execute "bd! " . g:kwbdBufNum
 
 
endif
 
 
if(!g:buflistedLeft)
 
 
set buflisted
 
 
set bufhidden=delete
 
 
set buftype=nofile
 
 
setlocal noswapfile
 
 
normal athis is the scratch buffer
 
 
endif
 
 
else
 
 
if(bufnr("%") == g:kwbdBufNum)
 
 
let prevbufvar = bufnr("#")
 
 
if(prevbufvar > 0 && buflisted(prevbufvar) && prevbufvar != g:kwbdBufNum)
 
 
b #
 
 
else
 
 
bn
 
 
endif
 
 
endif
 
 
endif
 
 
endfunction
 
 
 
}}
 
 
== Comments ==
 
The links in the article must use host "www.vim.org", arther than "vim.org".
 
 
'''Anonymous'''
 
, February 5, 2006 2:20
 
 
----
 
----
  +
Code navigation in vi offers much more than a standard IDE, because of the ability to execute the desired combination of commands. Generate an index much more rapidly than an IDE with a heavy GUI interface:
Oops. Sorry about that. These are the two links again with www in front:
 
   
  +
For example, one can take advantage of the tag stack:
http://www.vim.org/scripts/script.php?script_id=184
 
http://www.vim.org/scripts/script.php?script_id=159
 
   
  +
For C++, follow the instructions: [http://design.liberta.co.za/articles/code-completion-intellisense-for-cpp-in-vim-with-omnicppcomplete/ on using OmniCpp]
Matt Zyzik
 
  +
Define a custom .ctags file
, February 6, 2006 8:04
 
  +
:--c++-kinds=+p
----
 
  +
:--fields=+iaS
I'd like to add one more features that IDE supplied, debugger integration. For me, that's the only reason I can't completely throw away IDE.
 
  +
:--extra=+q
  +
:--language-force=C++
   
  +
From a console (the exclude options may vary) generate the tags file as follows:
'''Anonymous'''
 
  +
<pre>
, February 6, 2006 21:49
 
  +
ctags --exclude=.svn --exclude=target -R .
----
 
  +
</pre>
I bet you think you got me... but alas:
 
http://clewn.sourceforge.net/
 
 
Check that out.
 
 
Matt Zyzik
 
, February 7, 2006 6:40
 
----
 
How about integration of the VC++ debugger? I cannot help it but I have to work on Windows :).
 
 
shashi.lakshmi--AT--gmail.com
 
, February 8, 2006 16:19
 
----
 
ViEmu - for when you're *really* stuck with visual studio. http://www.ngedit.com/viemu.html
 
 
'''Anonymous'''
 
, February 15, 2006 20:06
 
----
 
I am a newbie and web developer. I look for a favorite IDE for me. I want to try vim.
 
how to be a web develop enviroment, including xhtml, xml, javascript, css, php, asp etc.?
 
 
mikeyao2--AT--gmail.com
 
, August 4, 2006 18:58
 
----
 
This is what I am looking for!!!!
 
Finally the Fun back in Coding in "Console" for me!!!
 
Insya 4JJI...
 
 
Tired and bored at gigantic IDE... (well, sometime they help me... sigh)
 
Now, let see what Vim 7.0 had for me ... (for about years I neglect it. The last time I use, is 6.0 version)
 
 
Thanks Brams and other for this !!!!
 
 
http://swdev.blogs.friendster.com/my_blog/
 
 
Anyway, is there any J2EE coder around here and would like to share the tips
 
I currently developing it on Windows .... (thats way All the Viiiiiim.... faded away)
 
So, any J2EE tips guys???
 
 
swdev.bali--AT--gmail.com
 
, December 14, 2006 18:51
 
----
 
<!-- parsed by vimtips.py in 0.521598 seconds-->
 

Revision as of 18:02, 5 March 2013

Tip 1119 Printable Monobook Previous Next

created 2006 · complexity intermediate · author Matt Zyzik · version 6.0


I use Vim for all text editing, even software development. At one point I stopped using IDEs. One major reason is that Vim can do all the major things I need from IDEs (tabs, file trees, greping, syntax highlighting, indentation, completion, "quickfix"ing, etc).

Vim Plugins

Still Vim needs plugins to do some IDE-like things that aren't built in. Here are some Vim scripts that make Vim more like an IDE.

Note: You can use pathogen to isolate your plugins and make it easier to experiment with new plugins.

Project/Filetree Browsing

  • NERDTree is a tree explorer plugin for navigating the filesystem.
  • vtreeexplorer is a tree based file explorer.
  • project gives you a "project" view of files, rather than a straight file system view
  • ide Tracks files status (open/edited/closed/read only) within a project with icons; automatically builds and updates syntax highlight rules based on the project files (C/C++/Java); avoids buffer duplication; see demo.
  • :help netrw for information about the explorer distributed with Vim. It does not display files in a tree by default, but can by using the g:netrw_liststyle option. It also offers useful file-sorting options (by date, size, name).

Buffer/File Browsing

  • bufexplorer lets you navigate through open buffers
  • minibufexpl Elegant buffer explorer; takes very little screen space.
  • lookupfile Lookup files using Vim7 ins-completion
  • Command-T plugin, inspired by the "Go to File" window bound to Command-T in TextMate
  • MRU access recently opened files.
  • ctrlp Fuzzy file, buffer, mru, tag, ... finder with regexp support. Writen in vim language. Access all the functions with ctrl-p
  • FuzzyFinder same as previous.

Code Browsing

  • taglist gives you an outline of the source you're viewing
  • Tagbar similar to taglist but can order tags by scope. Recommend for programming languages with classes, e.g. C++, Java, Python.
  • Indexer generates tags for all files in project automatically and keeps tags up-to-date. Using ctags. Works well with project plugin or independently.
  • CCTree is a Call-Tree Explorer, Cscope based source-code browser, and code flow analyzer.
  • exUtility global search, symbol search, tag track...(Like IDE/Source Insight).
  • ShowMarks visually shows the location of marks.

See also Browsing programs with tags and Cscope.

Writing Code

See also Omni completion and Make Vim completion popup menu work just like in an IDE.

Vim Functionality

IDE integration

You may want to use your IDE for some tasks like debugging, so some integration between Vim and the IDE can be helpful.

Source Control Integration

There are many Vim plugins for different source control management systems. Here are a few.

See also Category:VersionControl

Debugging

There are several projects to add debugging functionality to vim

  • Clewn implements full gdb support in the vim editor: breakpoints, watch variables, gdb command completion, assembly windows, etc.
  • vim-debug, which creates an integrated debugging environment in VIM.
  • gdbvim plugin: Watch in vim what you debug in gdb. And more.

Refactoring

Comments

When using Visual Studio, see ViEmu.


Code navigation in vi offers much more than a standard IDE, because of the ability to execute the desired combination of commands. Generate an index much more rapidly than an IDE with a heavy GUI interface:

For example, one can take advantage of the tag stack:

For C++, follow the instructions: on using OmniCpp Define a custom .ctags file

--c++-kinds=+p
--fields=+iaS
--extra=+q
--language-force=C++

From a console (the exclude options may vary) generate the tags file as follows:

ctags --exclude=.svn --exclude=target -R .