Vim Tips Wiki
m (Reverted edits by 106.3.82.105 (talk | block) to last version by 211.87.224.107)
Tag: Visual edit
 
(24 intermediate revisions by 21 users not shown)
Line 11: Line 11:
 
|category2=
 
|category2=
 
}}
 
}}
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).
+
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, grepping, syntax highlighting, indentation, completion, "quickfixing", etc).
   
 
==Vim Plugins==
 
==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.
 
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.
  +
  +
The plugins listed below are all great; the one additional plugin that really makes vim feel like an IDE for me is [https://github.com/w0rp/ale ale] -- the Asynchronous Lint Engine. It runs various tests in the background and highlights errors in your code with annotations in the side margin. Incredibly valuable.
   
 
Note: You can use {{script|id=2332|text=pathogen}} to isolate your plugins and make it easier to experiment with new plugins.
 
Note: You can use {{script|id=2332|text=pathogen}} to isolate your plugins and make it easier to experiment with new plugins.
Line 22: Line 24:
 
*{{script|id=184|text=vtreeexplorer}} is a tree based file explorer.
 
*{{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=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.
  +
*{{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).
  +
*Luc Hermitte's [https://github.com/LucHermitte/local_vimrc local_vimrc] and Markus "''embear''" Braun's [https://github.com/embear/vim-localvimrc/ local_vimrc] manage projects as files in a same directory tree.
  +
*Tim Pope's [https://github.com/tpope/vim-projectionist Projectionist] #4989 provides granular project configuration using "projections".
   
 
===Buffer/File Browsing===
 
===Buffer/File Browsing===
Line 29: Line 35:
 
*[https://wincent.com/products/command-t/ Command-T plugin], inspired by the "Go to File" window bound to Command-T in TextMate
 
*[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.
 
*{{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. Written 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===
 
===Code Browsing===
Line 37: Line 45:
 
*{{script|id=1729|text=exUtility}} global search, symbol search, tag track...(Like IDE/Source Insight).
 
*{{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.
 
*{{script|id=152|text=ShowMarks}} visually shows the location of marks.
  +
*[https://github.com/LucHermitte/lh-tags lh-tags] automatically updates the ctags database, and provides alternatives to `:tselect` to navigate code.
   
 
See also [[Browsing programs with tags]] and [[Cscope]].
 
See also [[Browsing programs with tags]] and [[Cscope]].
Line 43: Line 52:
 
*A plethora of [[:Category:Automated_Text_Insertion#Related_scripts|code snippet/template plugins]] are available, many offering [[wikipedia:Textmate#Snippets|TextMate]]-like snippet features.
 
*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=1879|text=AutoComplPop}} gives you code completion as you type.
  +
*[http://valloric.github.io/YouCompleteMe/ YouCompleteMe] is another completion plugin.
 
*{{script|id=614|text=CRefVim}} A C-reference manual especially designed for Vim.
 
*{{script|id=614|text=CRefVim}} A C-reference manual especially designed for Vim.
   
Line 50: Line 60:
 
*{{script|id=39|text=matchit}} improves % matching
 
*{{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=1147|text=bufkill}} allows you to delete a buffer without actually closing the window.
*{{script|id=3304|text=gundo}} visualizes your undo tree.
+
*{{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.
 
*{{script|id=1697|text=surround}} makes it easier to delete/change/add parentheses/quotes/XML-tags/much more.
  +
  +
=== Compilation ===
  +
* [https://github.com/tpope/vim-dispatch vim-dispatch] allows you to asynchronously run shell commands. When running a compiler, the quickfix window will be populated with any potential errors.
  +
* [https://github.com/LucHermitte/vim-build-tools-wrapper Build Tools Wrapper provides] ways to compile programs (possibly in background, on several cores, ...), and to test and execute programs. It can also filter compilation outputs on the fly. When compiling projects under CMake care, ''BTW'' plugin permits to switch the compilation mode (a directory actually). The current compilation mode (and project name) will be displayed in the statusline of each buffer (the quickfix buffer as well) through airline plugin.
  +
* [https://github.com/skywind3000/asyncrun.vim AsyncRun] allows you to run shell commands asynchronously in the background and output to the quickfix window. It provides a convenient way to execute commands and view the output without blocking your editing workflow. This can be useful for running build commands, running tests, or any other command line tasks within Vim.
  +
* (list to be completed)
   
 
===IDE integration===
 
===IDE integration===
Line 63: Line 79:
 
*{{script|id=2975|text=fugitive}} - git integration
 
*{{script|id=2975|text=fugitive}} - git integration
 
*{{script|id=240|text=perforce}} - perforce integration
 
*{{script|id=240|text=perforce}} - perforce integration
  +
*{{script|id=3861|text=lawrencium}} - mercurial integration
  +
*[http://www.gregsexton.org/portfolio/gitv/ gitv] - gitk clone for vim
  +
*[http://sjl.bitbucket.org/splice.vim/ Splice] - plugin for resolving conflicts during three-way merges
   
 
See also [http://vim.wikia.com/wiki/Category:VersionControl Category:VersionControl]
 
See also [http://vim.wikia.com/wiki/Category:VersionControl Category:VersionControl]
Line 68: Line 87:
 
==Debugging==
 
==Debugging==
 
There are several projects to add debugging functionality to vim
 
There are several projects to add debugging functionality to vim
  +
*Bundled [http://vimhelp.appspot.com/terminal.txt.html#terminal-debug terminal debugger plugin] (since vim 8.1, 2018-05-18)
 
*[http://clewn.sourceforge.net/ Clewn] implements full gdb support in the vim editor: breakpoints, watch variables, gdb command completion, assembly windows, etc.
 
*[http://clewn.sourceforge.net/ Clewn] implements full gdb support in the vim editor: breakpoints, watch variables, gdb command completion, assembly windows, etc.
  +
*[http://pyclewn.sourceforge.net/ pyClewn] like clewn but written in python and also supports [https://docs.python.org/2/library/pdb.html pdb].
 
*[http://jaredforsyth.com/projects/vim-debug/ vim-debug], which creates an integrated debugging environment in VIM.
 
*[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.
 
*{{script|id=84|text= gdbvim}} plugin: Watch in vim what you debug in gdb. And more.
  +
*[https://github.com/gilligan/vim-lldb vim-lldb]: provides lldb debbuging integration.
  +
*[https://github.com/idanarye/vim-vebugger vim-vebugger]: debugger front-end for gdb, jdb, Mdbg, pdg, Rdebug
  +
*[https://github.com/joonty/vdebug vdebug]: Multi-language DBGP debugger client for Vim (PHP, Python, Perl, Ruby, etc.)
  +
*[https://github.com/kmewhort/vim-byebug-breakpoints vim-byebug-breakpoints]: controls Ruby breakpoints for byebug (works with ruby >=2.0)
   
 
==Refactoring==
 
==Refactoring==
Line 76: Line 101:
 
*{{script|id=2087|text='''refactor''' plugin}}
 
*{{script|id=2087|text='''refactor''' plugin}}
 
*{{script|id=2164|text='''renamec''' plugin}}
 
*{{script|id=2164|text='''renamec''' plugin}}
  +
*[https://github.com/LucHermitte/vim-refactor lh-refactor plugin]
   
 
==Comments==
 
==Comments==
 
When using Visual Studio, see [http://www.ngedit.com/viemu.html ViEmu].
 
When using Visual Studio, see [http://www.ngedit.com/viemu.html 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:
+
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:
   
 
For example, one can take advantage of the tag stack:
 
For example, one can take advantage of the tag stack:
Line 93: Line 119:
 
From a console (the exclude options may vary) generate the tags file as follows:
 
From a console (the exclude options may vary) generate the tags file as follows:
 
<pre>
 
<pre>
ctags --exclude=.svn --exclude=target -R .
+
ctags --exclude=.svn --exclude=target -R .</pre>
  +
</pre>
 
  +
== Preconfigured VIM as IDE ==
  +
You can find preconfigure VIM as IDE environment created by Damian Ziobro on GitHub:
  +
  +
https://github.com/xmementoit/vim-ide
  +
  +
It contains preconfigured '''BASH script to install it on your Ubuntu''' (not tested on other OSes). In order to install vim-ide on Ubuntu, you need to do following steps:
  +
* back up your previous vimrc configuration
  +
cp $HOME/.vimrc $HOME/.vimrc.bak
  +
* clone vim-ide repository to your HOME directory
  +
cd $HOME && git clone https://github.com/xmementoit/vim-ide
  +
* install vim-ide in your system
  +
cd vim-ide && ./installVim.sh
  +
* explore possibilities and plugins of vim-ide repository in $HOME/.vimrc and $HOME/.vim. Ex. open main.cpp file
  +
vim /tmp/main.cpp
  +
* enjoy your work with vim-ide !

Latest revision as of 15:23, 17 August 2023

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, grepping, syntax highlighting, indentation, completion, "quickfixing", 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.

The plugins listed below are all great; the one additional plugin that really makes vim feel like an IDE for me is ale -- the Asynchronous Lint Engine. It runs various tests in the background and highlights errors in your code with annotations in the side margin. Incredibly valuable.

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.
  • :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).
  • Luc Hermitte's local_vimrc and Markus "embear" Braun's local_vimrc manage projects as files in a same directory tree.
  • Tim Pope's Projectionist #4989 provides granular project configuration using "projections".

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. Written 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.
  • lh-tags automatically updates the ctags database, and provides alternatives to `:tselect` to navigate code.

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[]

Compilation[]

  • vim-dispatch allows you to asynchronously run shell commands. When running a compiler, the quickfix window will be populated with any potential errors.
  • Build Tools Wrapper provides ways to compile programs (possibly in background, on several cores, ...), and to test and execute programs. It can also filter compilation outputs on the fly. When compiling projects under CMake care, BTW plugin permits to switch the compilation mode (a directory actually). The current compilation mode (and project name) will be displayed in the statusline of each buffer (the quickfix buffer as well) through airline plugin.
  • AsyncRun allows you to run shell commands asynchronously in the background and output to the quickfix window. It provides a convenient way to execute commands and view the output without blocking your editing workflow. This can be useful for running build commands, running tests, or any other command line tasks within Vim.
  • (list to be completed)

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

  • Bundled terminal debugger plugin (since vim 8.1, 2018-05-18)
  • Clewn implements full gdb support in the vim editor: breakpoints, watch variables, gdb command completion, assembly windows, etc.
  • pyClewn like clewn but written in python and also supports pdb.
  • vim-debug, which creates an integrated debugging environment in VIM.
  • gdbvim plugin: Watch in vim what you debug in gdb. And more.
  • vim-lldb: provides lldb debbuging integration.
  • vim-vebugger: debugger front-end for gdb, jdb, Mdbg, pdg, Rdebug
  • vdebug: Multi-language DBGP debugger client for Vim (PHP, Python, Perl, Ruby, etc.)
  • vim-byebug-breakpoints: controls Ruby breakpoints for byebug (works with ruby >=2.0)

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:

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 .

Preconfigured VIM as IDE[]

You can find preconfigure VIM as IDE environment created by Damian Ziobro on GitHub:

https://github.com/xmementoit/vim-ide

It contains preconfigured BASH script to install it on your Ubuntu (not tested on other OSes). In order to install vim-ide on Ubuntu, you need to do following steps:

  • back up your previous vimrc configuration
cp $HOME/.vimrc $HOME/.vimrc.bak
  • clone vim-ide repository to your HOME directory
cd $HOME && git clone https://github.com/xmementoit/vim-ide
  • install vim-ide in your system
cd vim-ide && ./installVim.sh
  • explore possibilities and plugins of vim-ide repository in $HOME/.vimrc and $HOME/.vim. Ex. open main.cpp file
vim /tmp/main.cpp
  • enjoy your work with vim-ide !