How to get gvim to play nicely with Visual Studio 2010? - visual-studio-2010

On my last job, they used Visual Studio 2005 (and occasionally Visual Studio 97), and for command line convenience I used vim for editing things like Mercurial version control configuration files like hgrc and .hgignore
However my coworkers soon began to complain that vim would change the encoding of the files, and would cause a message to popup in Visual Studio telling them about the encoding difference.
After that I stopped using vim and just ended up editing the files in Visual Studio.
Are there any changes to vim's configuration I can make so that this does not occur?
I'd use notepad to edit my files but it always puts that pesky .txt extension on the ends of my files.
I'm also aware of solutions like Notepad++, but I just wondered if there was a solution for this in vim.

If it is because their VS files are being saved as UTF-8 by default and your vim is doing ISO-8859-1 or ASCII, try changing your file encoding:
" Encoding displayed
:set encoding=utf-8
" Encoding written to file.
:set fileencoding=utf-8

For new files
:set ff=dos
In the standard setup, vim will preserve the line-ending style of an already existing file.

Another option might be to use ViEmu, which is a plugin that provides vi emulation within Visual Studio. Please note that it is not a free plugin, but to me it's worth paying for.

VSVim is a free extension for VS2010 that provides a fair bit of vim functionality built right in the IDE.
ViEmu is a much more complete implementation that's not free but is worth the money.

Related

Can visual studio code block modifications like vim?

Is it possible to lock files in visual studio code? Similarly to what you do in vim where you have to press "i" if you want to modify files I'd like to be able to keep the files locked and then press a key that allows me to modify them and then lock them again. Is it possible to do so in visual studio just like in vim?
It looks like you're looking for a "modal editor" interface.
If using actual Vim keybindings and commands would work for you, then consider adopting Vim for VS Code, which emulates most of the Vim UI inside VS Code.
It should give you the best of both worlds.

Refactor on save in Visual Studio 2019

I love Prettier for VS Code. I want to do similar things in Visual Studio (2019).
It now has 'Wrap, indent, and align parameters or arguments' for example (https://learn.microsoft.com/en-us/visualstudio/ide/reference/wrap-align-indent-parameters?view=vs-2019); and I'd like to do this automatically whenever I save the file.
Does anyone know if this is possible? Or if there's a free extension that can do this?
Mads Kristensen (a Microsoft employee who makes scads of Visual Studio extensions and teaches you to too!) made a JsPrettier extension for "classic" Visual Studio (ie, not VS Code):
https://github.com/madskristensen/JavaScriptPrettier
It does not format on save if you set that up in its settings.
If it's literally Prettier in Visual Studio that you're after, this isn't a bad option.
I don't know of a free plugin but you can get quite a long way towards this with some muscle memory and the built in autoformat command.
CTRL+E, CTRL+D, CTRL+S
will do code indentation and formatting, and save the file.
If you have Resharper (sorry), there's a configurable code cleanup tool which will do what you want and CTRL+E, CTRL+F, CTRL+S will do the cleanup and save.
The Format document on Save VS extension does exactly what you want, with one exception. It automatically runs Visual Studio's code cleanup command on save.
Visual Studio's code cleanup commands covers many code style preferences and can be configured with a .editorconfig file. Unfortunately one thing that is not supported by VS yet (not counting Resharper) is line wrap preferences. There is an open ticket for this: dotnet/roslyn#33872
If and when Roslyn supports line wrap preferences (presumably as a new .editorconfig preference), then Visual Studio code cleanup will enforce it and the extension will apply it on save.

How do I reformat MSBUILD xml in Resharper or VS Studio?

Both ReSharper 6 and VS 2010 treat my MSBUILD files as XML when it has the .Proj extension, but it will not allow me to reformat the text. The options are greyed out in ReSharper and VS 2010. How do I turn it on? Right now, I am forced to either copy and paste the code into a file with an xml extension reformat and copy and paste it back, or rename the file with an xml extension.
You can write a Visual Studio macro that will do all the renaming and reformatting for you. Macros can be bound to the toolbar and to commands (keyboard shortcuts), so you can make this into a single click/shortcut.
JetBrains answer as of today (2013-12-02) is that project files are excluded from code cleanup. There's a discussion of the issue on their code cleanup page which contains a link to a bug named Verify that Code Cleanup works with MSBuild .proj files which contains the information that the fix version is only 9.0!
So there seems no way short of an external tool to get this done.

DOS Editor with intellisense

Is there any DOS editor with intellisense.
If Visual studio addin is there that will be more useful.
Have you seen http://www.drbatcher.com/ there's a free trail. Normally I just use Notepad++ or Notepad2 when editing my batch files as they give syntax highlighting.
More often I write PowerShell scripts now and use PowerGui Script editor when creating those scripts.http://powergui.org/
Try vim for DOS, along with an appropriate script (there's plenty to choose from).
http://www.vim.org/download.php#pc

Configure Visual Studio to use UNIX line endings

We would like to use Visual Studio 2005 to work on a local copy of an SVN repository. This local copy has been checked out by Mac OS X (and updates and commits will only be made under Mac OS X, so no problem there), and as a consequence the line endings are UNIX-style.
We fear that Visual Studio will introduce Windows-style line endings. Is it possible to force Visual Studio to use UNIX line endings?
Warning: This solution no longer works for Visual Studio 2017 and later. Instead, both of the answers by jcox and Munther Jaber are needed. I have combined them into one answer.
As OP states "File > Advanced Save Options", select Unix Line Endings.
This will only affect new files that are created. Fixing any that were previously created can be done file-by-file or you can search for tools that will fix on-bulk.
Here are some options available for Visual Studio Community 2017
"File > Advanced Save Options" has been removed by microsoft due to "uncommon use". Whatever that means. https://developercommunity.visualstudio.com/content/problem/8290/file-advanced-save-options-option-is-missed.html
You can add it back by going to "Tools>Customize", then "Commands" tab, select the drop down next to "Menu Bar" select "File" then "Add Command">File>Advanced Save Options..". You can then reorder it in the file menu by using "move down".
I don't know if you will have to then set the advanced save options for each and every file, but it might prevent the issue I was having where my Visual Studio kept adding CL RF line endings into my files that were uniformly LF.
But I took it one step further and I added an extension called "Line Endings Unifier" by going to "Tools>Extensions and Updates>Online" and then searching for "line endings" in the search bar to the right. I will use this to automatically force all of my scripts to save with uniform line endings of my choice, but you can do more with it.
https://marketplace.visualstudio.com/items?itemName=JakubBielawa.LineEndingsUnifier
strip'em is another solution that does something similar to Line Endings Unifier. http://www.grebulon.com/software/stripem.php
I am not sure how they differ or the advantages/disadvantages of either. I'm mainly using Line Endings Unifier just because it was in the Visual Studio Marketplace. I think I've used all of these methods in the past, but my memory is fuzzy.
So I found this problem and the answers very confusing, especially since I primarily develop in Linux and PhpStorm and simply never have these issues.
I found that for Visual Studio 2019, only Munther Jaber's solution worked when combined with #jcox's .editorconfig changes for new files.
However, being unfamiliar with Visual Studio itself, it took me a LONG TIME to find out where the line ending box is...
SO I made a video of how to configure this.
https://youtu.be/YfN3igHXTPo
Update: I learned how to make animated GIFs via FFMPEG just so I could embed the video here!
VS2017 supports .editorconfig files, which can be checked in along with your project. This is the relevant command for setting Unix line endings:
end_of_line = lf
"File > Advanced Save Options", select Unix Line Endings works per file based.
Alternatively You can use Strip'em Add-in for Visual Studio
This Add-in converts the text format of a file when it is saved in Visual Studio.
More info here: http://www.grebulon.com/software/stripem.php
There are some VS extension that are useful to solve this problem
I will recommend Trim line ends on save. This extension is free and open source. There are similar extensions that may work for you, just go to TOOLS | Extensions and Updates and search online for "line end"
For Visual Studio 2019 for Mac
Go to Project> Solution Options> Source Code> Code Formatting> Text File
In the Line Terminations drop box select Unix/Mac.
Image
The LF is clickable and you choose either LF or CRLF.
It is possible to force line endings in Visual Studio 2017 for Mac
Go to Tools > Add Custom Tool....
In the dialog box that appears scroll the left menu down to the Text Editor section and select General.
In the first option, Line ending conversion, change Leave line endings as is to Always convert line endings.
In the latest version on Windows you go to
File > Preferences > Settings > Text Editor > Files > Eol

Resources