shortcut to program files (x86) directory - vim

On my win32 system I had this command in Vim to open a vim file in wordpad:
silent ! start c:\Program Files (x86)\Windows NT\Accessories\wordpad.exe "%:p"<CR>
On my win64 system this doesn't work. I get this error:
error: Windows cannot find `"c:\Program"`
Maybe because of the space(s) inside "Program Files (x86)" and "Windows NT"?
How can i resolve this problem?

On 64-bit Windows wordpad.exe won't be in "Program Files (x86)", but in "Program Files". At least it is on my machine.
There are environment variables to find the folder names: "%ProgramFiles%" and "%ProgramFiles(x86)%".

Put quotes around your path.
Like so:
silent ! start "c:\Program Files (x86)\Windows NT\Accessories\wordpad.exe" "%:p"<CR>

Vim on Windows has a special !start (without a space in between) for asynchronous invocation.
And, as always, you need to put double quotes around the path, like this:
silent !start "c:\Program Files (x86)\Windows NT\Accessories\wordpad.exe" "%:p"

Related

Runas a certain xls file

I need to write a batch script which opens a certain xls file on behalf of another user account.
runas separately works OK:
runas /profile /user:username "C:\Program Files (x86)\Microsoft Office\Office15\EXCEL.EXE"
excel connector is also OK:
"C:\Program Files (x86)\Microsoft Office\Office15\EXCEL.EXE /r C:\fol der\file.xls"
but together it's not:
runas /profile /user:username "C:\Program Files (x86)\Microsoft Office\Office15\EXCEL.EXE /r C:\fol der\file.xls"
It can't handle the path of the xls file if there is space anywhere.
As per RUNAS - Execute a program under a different user account: RUNAS used backslash \ as an escape character (not the standard ^ used by other CMD commands). Moreover, runas /? gives next example literally:
runas /env /user:user#domain.microsoft.com "notepad \"my file.txt\""
Hence, your line should be as follows:
runas /profile /user:username "\"C:\Program Files (x86)\Microsoft Office\Office15\EXCEL.EXE\" /r \"C:\fol der\file.xls\""

Change the relative order with which gvim search for executable files

Gvim will search the executable files in $PATH, $VIMRUNTIME(the folder where gvim.exe locate) and the current folder. The folder of $PATH have the highest priority.
Suppose i place a cygwin version “find.exe" in the folder where gvim.exe locate.
and i want gvim to call this cygwin version of "find.exe" instead of the windows version of "find.exe" for ":!find", how could i do?
You can modify $PATH in your ~/.vimrc; this will avoid messing with any other Windows program (well, except for those that are launched from inside Vim - do check their compatibility).
:let $PATH = 'C:\cygwin\bin;' . $PATH
If other Cygwin binaries still interfere, copy Cygwin's find.exe to another folder (be it $VIMRUNTIME or a fresh directory somewhere else), and prepend that to $PATH.
:let $PATH = $VIMRUNTIME . ';' . $PATH
If you put C:\cygwin\bin (or your equivalent) at the start of your $PATH it will find the cygwin binary first and use that one rather than the windows binary.

Compile with VC++

I need to convert this gcc build command to VC++
g++ -o launcher.exe launcher.cpp -I C:/JDK/include_jdk -I C:/JDK/include_jdk/win32 -L C:/Program Files (x86)/Java/jre6/bin/client -ljvm
I don't use VC++ at all (use mingw) and just have to compile this single file. Please, help!
To compile a single file easily in VC++, open up a Visual Studio Command Prompt (you should have a shortcut installed as part of the installation process), and do the following:
cl launcher.cpp
That will build launcher.exe for you.
To add specific include paths use the /I option, and to add linker options, you can add them after passing the /link parameter, so for example use /libpath to add a library search path, and then just stick the library names onto the command line:
cl launcher.cpp /I C:/JDK/include_jdk /I C:/JDK/include_jdk/win32 /link /libpath "C:/Program Files (x86)/Java/jre6/bin/client" libjvm.lib
The output filename, if you're compiling a single .cpp file, will be that filename with a .exe extension, but that's what you seem to want. Otherwise, stick a /out parameter on... but I'll leave that as an exercise for you.
More information can be found on MSDN.

Zip batch command and Excel

I have many excel files that I need zipped into each of their own zip folders. I thought I had this ironed out, but I have co-workers coming back to me saying that they cannot open the excel file because it has become corrupted. I went back and checked the original file, and it opens up just fine. But when I open up the same version of the file that was zipped, I too get the corrupted error. I'm on Office 2010, which is able to repair it, but my co-workers are all Office 2007 which does not seem to be able to fix the file. My batch code is as follows:
for /r %%X in (*.xlsm) do "C:\Program Files\7-Zip\7z.exe" a -tzip "%%~nX" "%%X"
I think you might be using a wrong value as the first parameter to the 7zip executable. According to the documentation on FOR:
%~nI - expands %I to a file name only
And according to the 7zip documentation:
You can use the "a" command with the single letter a. This command stands for 'archive' or 'add'. Use it to put files in an archive. You have to specify the destination archive, and the source files (in that order).
So, using your script with an example file, it seems to me that your command line becomes:
"C:\Program Files\7-Zip\7z.exe" a -tzip "somefile.xlsm" "C:\path\to\somefile.xlsm"
Shouldn't the first parameter have a .zip file extension on the end? So the line is modified to look like this:
for /r %%X in (*.xlsm) do "C:\Program Files\7-Zip\7z.exe" a -tzip "%%~nX.zip" "%%X"
As annoying as it is, file extensions actually mean something in Windows. Your previous line was creating a zip file with the .xlsm extension. When people try opening those files, Excel complains (because it's a zip file; not a .xlsm).
#Echo OFF
PUSHD "C:\Program Files\7-Zip" && (
FOR /R "%CD%" %%# in (*.xlms) DO (7z a -tzip "%%~n#.zip" "%%#")
POPD
)
REM Don't worry about the PUSHD command, the %CD% variable isn't expanded, that's the trick.
Pause&Exit
And you can use the dynamic operator * (asterisk) and 7zip -recursive parameter if you want all together in one file:
7z a -r -tzip "ALL.zip" "*.xlsm"
Sorry guys.
It was a false alarm. Turns out it wasn't all of the files, but only a select few. The files were sectioned out by region, and the only ones that were corrupt were the first region. Why? I can only assume that they were corrupted by my original attempts at making a batch file, as all the other files were zipped with the finished batch and thus didn't have errors. So nothing was wrong with my script. Thanks for the help though.

Setting up gVim on windows

I am trying to get gVim working on a windows 7 machine and am having the following problems:
Whenever I try to change the _vimrc file, I get a message saying that I don't have permission to save in this location. This is on my home pc btw.
I can't seem to change the directory where the files I edit are being saved. They are all being saved to my desktop at the moment. I tried :set dir=path to where I want to save... with no success.
I wanted to run through vimtutor; however, whenever I type vimtutor into cmd, vim flashes open for a second then closes.
How do I alter the _vimrc file and how do I set the destination for edited files?
I find many people do it differently. Here's how I organize my configurations on windows.
First note that I don't believe in mixing my vim configurations with the stock vim installation. So I don't write or modify files in %PROGRAMFILES% or %PROGRAMFILES(x86)%.
My vim configurations work on different platforms (OS X, linux, windows). And I keep them organized in a .vim folder and a .vimrc file.
Some of my windows machines have cygwin and others do not. On the ones without cygwin, I put my .vim folder and my _vimrc file in %USERPROFILE%. On the ones with cygwin, I put my .vim folder and my _vimrc file in my cygwin user's home directory.
%HOME% is not defined on windows OOTB, so I define it. I find setx.exe is easy...
Example: setx HOME %USERPROFILE% or setx HOME d:\cygwin\home\myname
Alternatively, you can add environment variables via the control panel.
Note, you can copy/store the .vim folder and _vimrc file in %HOME%. But I like to keep them in a git repo elsewhere on my machine and link to them. On windows, I use mlink /d %HOME%\.vim location_of_vim_folder to link the .vim folder. And mlink /h %HOME%\_vimrc location_of_dot_vimrc_file to link the .vimrc to _vimrc file.
Note, you should have write permissions to your %HOME% folder defined above... so this should solve your problem with permissions. (You need to be an administrator to write to %PROGRAMFILES% or %PROGRAMFILES(x86)%
In my vimrc, I have a bit of boiler plate stuff for windows:
"g:my_vim_dir is used elsewhere in my vim configurations
let g:my_vim_dir=expand("$HOME/.vim")
"$HOME/.vim and $HOME/.vim/after are in the &rtp on unix
"But on windows, they need to be added.
if has("win16") || has("win32") || has("win64")
"add g:my_vim_dir to the front of the runtimepath
execute "set rtp^=".g:my_vim_dir
"add g:my_vim_dir\after to the end of the runtimepath
execute "set rtp+=".g:my_vim_dir."\\after"
"Note, pathogen#infect() looks for the 'bundle' folder in each path
"of the &rtp, where the last dir in the '&rtp path' is not 'after'. The
"<path>\bundle\*\after folders will be added if and only if
"the corresponding <path>\after folder is in the &rtp before
"pathogen#infect() is called. So it is very important to add the above
"'after' folder.
"(This applies to vim plugins such as snipmate, tabularize, etc.. that
" are loaded by pathogen (and perhaps vundle too.))
" Not necessary, but I like to cleanup &rtp to use \ instead of /
" when on windows machines
let &rtp=substitute(&rtp,"[/]","\\","g")
"On windows, if called from cygwin or msys, the shell needs to be changed
"to cmd.exe to work with certain plugins that expect cmd.exe on windows versions
"of vim.
if &shell=~#'bash$'
set shell=$COMSPEC " sets shell to correct path for cmd.exe
endif
endif
"Then I load pathogen... (Or if you prefer, you could load vundle bundles here if you wish )
I can't seem to change the directory where the files I edit are being saved. They are all being saved to my desktop at the moment. I tried :set dir=path to where I want to save... with no success.
dir is the location for swap files, which are special backing files used by Vim at runtime.
What you want is cd or lcd which changes the current directory. Type :help cd inside of Vim for more info.
How do I alter the _vimrc file and how do I set the destination for edited files?
I have _vimrc in my Vim folder ($VIM), so when I want to put Vim on a new Windows machine I just copy my entire folder.

Resources