====== Vim Studio ====== Last job, I was working on C# with JetBrain's Rider IDE. Which has a really nice Vim plugin, IdeaVim. I was content. Now I am back to working on C++, with Visual Studio. Which has left its Vim plugins (VimEmu, VsVim) in the dust with the 2022 update. Things just don't work all that nicely. Which made me consider going back to the roots, and instead of bringing Vim to the IDE, I am trying to bring the MSVC solution to Vim. This is the map I am drawing as I am moving forward, so I can retrace my steps later. ===== Vim ===== First off, you need a working Vim installation. For several reasons, I suggest using [[Cygwin]], because it also offers all the other tools you might need down the line, as well as a proper shell to work from. ===== taglist.vim ===== The one Vim plugin you should never leave home without. [[https://www.vim.org/scripts/script.php?script_id=273|taglist.vim]] ===== ctags ===== Ctags is a tool that builds a symbol database that will allow Vim to do things like "jump to definition" or "jump to declaration". There are two tools called "ctags" around: Exuberant ctags, and Universal ctags. While c-ctags had been discontinued quite some time ago, [[https://ctags.io/|Universal Ctags]] is still alive. It's also the version getting installed when you select "ctags" in the Cygwin package manager, so go ahead and install it. ===== cscope ===== [[https://cscope.sourceforge.net/|Cscope]] is a similar tool to ctags, only it works the other way around: Instead of going from the code using something to its declaration / definition, Cscope allows you to find out //where something is being used.// Of course we want that as well. Again, the Cygwin package manager provides. ===== MSBuild ===== MSBuild is a command line tool packaged with Visual Studio that allows building .sln and .vxcproj files from the command line. It's located in ''C:\Program Files\Microsoft Visual Studio\2022\Professional\Msbuild\Current\Bin\MSBuild.exe'' (or whatever your version of Visual Studio is). It's directory is not added to ''$PATH'', making things a bit awkward. We will eventually want to call MSBuild from within Vim (using '':make''). This is facilitated by ''$VIMRUNTIME/compiler/msbuild.vim'' -- which, however, uses ''msbuild'' instead of ''MSBuild.exe'', which is a problem in Cygwin's case-sensitive shell that does not automatically assume the ''.exe'' extension. (Further complicated by a directory called ''MSBuild'' being present in the same directory as ''MSBuild.exe''.) Luckily there's an easy workaround for that. Create a local binary directory (''~/.bin''), add that to your ''$PATH'' in your shell startup script of choice, and then create ''~/.bin/msbuild'' that calls ''MSBuild.exe'' with the full path. While you're at it, add the ''-maxCpuCount'' parameter to ''MSBuild.exe'', or your builds will use a single thread only (and take forever as a result). ===== Setting MSBuild as Vim's compiler ===== In ''$VIM/vimrc'', set ''compiler msbuild''. (There are [[https://stackoverflow.com/questions/77984411/set-compiler-option-from-vimrc|more elegant ways]] to set this option for only C++ files. But that means you have to actually go to C++ mode (e.g. by opening a C++ file) before you can call '':make'', and I didn't want that. ===== Setting up ctags ===== Go to the top level directory of your solution, and run: ctags -R --c++-kinds=+p --fields=+iaS --extras=+q --exclude=.git --exclude=.svn --exclude=.hydra --exclude=.vs --exclude=bin --exclude=obj This will take a while, especially on large projects. ===== References ===== * [[https://kulkarniamit.github.io/whatwhyhow/howto/use-vim-ctags.html|Use vim with ctags]]