I use gvim on Windows 10.I'd like to open wiki html page with command from a opened wiki page.
If I use the command ,
:!start ..\Vimwiki_html\%:r.html
it will translate to
:!start ..\Vimwiki_html%:r.html
The backslash is gone. My expectation is keep the baskslash charater and %:r will translate to a file name without extension.
If I use the command ,
:!start ..\Vimwiki_html\"%:r".html
it will translate to
:!start ..\Vimwiki_html\"file name".html
I don't want a pair double quotes.
Does anyone know what's the correct command? I can get the command string.
:!start ..\Vimwiki_html\MyWiki.html
Related
I am going through some logs written by a program that normally just logs to the console. Since it outputs to bash, I see a bunch of characters which are used for coloring in bash.
Is there any text editor out there that can interpret these character sequences and display the lines in color as bash does? Would be nice to be able to search through these logs without seeing a bunch of otherwise garbage characters.
If you don't want to use an editor you could use:
echo -e $(cat colorfile)
less -r colorfile
Or use vim addon AnsiEsc:
Download the AnsiEsc.vba.gz vim scripts file from (https://www.vim.org/scripts/download_script.php?src_id=14498)
Install details:
Open the AnsiEsc.vba.gz vim-scripts file in vim:
vim AnsiEsc.vba.gz
:so %
:q
Then open your file with vim and type
:AnsiEsc
I am trying to install the vim (7.4) surround extension on Arch Linux (downloaded and installed this week) within an Oracle VM on a Windows 7 host.
I am getting a variety of errors including E388 (Could not find definition) when on "Hello World" with my cursor inside the quotes I try:
:ds"
And E257 (cstag: tag not found) when on <div>Hello World</div> with my cursor inside the tags I try something like:
:cst<p>
I have downloaded the most recent version of vim surround from git
I have :set nocp
I have placed surround.vim in ~/.vim/plugin
I have restarted vim
I have regenerated the helptags, and :help surround does work.
I extracted the files as the user running vim, there is no permission error.
Running :scriptnames shows ~/.vim/plugin/surround in the list.
So as far as I can tell it is installed, just that it is not working. Any ideas?
Surround is almost certainly working correctly, you just don't know how to use it and/or don't understand the difference between "Ex" commands and normal mode commands.
:ds is the short form of :dsplit, see :help :dsplit.
:cst is the short form of :cstag, see :help :cstag.
They are "Ex" commands, but Surround's ds and cst are not "Ex" commands: they are normal mode commands.
Instead of doing:
:ds"
:cst<p>
do:
ds"
cst<p>
And… Read The Fantastic Manual: :help surround.
I'm attempting to use the :!<cmd> format in vim to execute an external command and put the results in the buffer. If I type :!, path completion is possible and I can complete the path right up to the command I want to execute. This automatically escapes spaces like so:
:!c:\Program\ Files\ (x86)\Microsoft\ Visual\ Studio\ 9.0\Common7\IDE\TF.exe
When I hit enter, I get:
'c:\Program\' is not recognized as an internal or external command
Which I suspect means that vim has not escaped the spaces properly when passing the command to cmd.exe. I've tried all sorts of escaping combinations to make this work but to no avail. The only way I've found to do this is to work out what the DOS8.3 filename is and use that instead of the long path name. However, I don't like this approach since it's going to make my script less portable. Does anyone know if this can be done, or is it a bug in vim?
If you have quoted arguments, not just the exe path, then you may need to do some fancy quoting, like below. The main problem is not the exe path itself, but the arguments. I found this webpage helpful for similar problems myself:
http://blogs.msdn.com/b/twistylittlepassagesallalike/archive/2011/04/23/everyone-quotes-arguments-the-wrong-way.aspx
Not sure offhand and don't have time to check, but if you have a quoted argument then sample below may be closer to what you need:
silent! exe 'r!"C:\Program Files (x86)\Microsoft Visual Studio 9.0\Common7\IDE\TF.exe" history /followbranches \^"#\^"'
Also, I wonder whether the quotes around the path may need special treatment since they are around only a portion of the full command. In any case, the quotes \^" work for main quotes in command line and ^" for quotes embedded in other quotes. I have in the past found it useful to experiment with the command at a windows prompt, remembering to test it with the way Vim prepares it, which is with your command prepended by c:\windows\sys32\cmd.exe .
On second thought, I think when I was working with similar problem I never did get to point of solving command with both quoted arguments and quoted exe-path-with-spaces in same command. I expect there's way to do it, but I instead just created a soft link to the exe in path with no spaces. E.g.:
mklink c:\users\myname\myexe c:\program files(x86)\myapp\myexe.exe
After having done that there's no need to quote the exe command itself and quoting the argument with \^" worked fine. I am of course curious about how to quote an exe-with-spaces that also has quoted arguments.
EDIT: I think I found way around my problem with quoting, don't have VS to test with your exact command but here's what I think may work from command line:
cmd /k ""C:\Program Files (x86)\Microsoft Visual Studio 9.0\Common7\IDE\TF.exe" history /followbranches ^"#^""
If that works for you from command line then I think only issue is getting Vim to include the /k switch. (Also, there could be issue with Windows command line "throwing away" the /followbranch switch, because of the forward slash, but maybe not.)
EDIT2: I think the trick for doing it from Vim is just to include the 'cmd /k' as part of the command you're running. You end up with several levels of shells opening, but I don't think that's a problem. For an example, here's on that runs from Vim, with (1) spaces in exe path, (2) quoted argument (the (message .. ) ) and even (3) a quote within a quoted argument (\^"hi\^"). This command opens an Emacs instance and has Emacs print message "hi":
!cmd /k ""c:\program files (x86)\emacs\emacs\bin\emacs.exe" --eval ^"(message \^"hi\^")^""
And yet one more EDIT: Including your own 'cmd /k' does create problems, I think, if you're trying not just to execute the external command, but to read its output back into the Vim buffer. In that case you could redirect the output to a file in the user's home directory and the use :read to insert into the buffer. If there's some way to get Vim's own cmd to use k switch then this would be unnecessary, but if not then at least this provides good workaround.
Enclose the full pathname of the executable in double quotation marks. Do not escape spaces in the pathname.
In your example, some of the backslashes were added to escape spaces, and others are a part of the pathname. You did not provide the original pathname, but I can guess at it. If I guessed right, the command that will work is:
:!"c:\Program Files (x86)\Microsoft Visual Studio 9.0\Common7\IDE\TF.exe"
This works equally well in a script. The equivalent script command is:
silent execute '!"c:\Program Files (x86)\Microsoft Visual Studio 9.0\Common7\IDE\TF.exe"'
I have tested this in Vim 7.3.346 x86, installed on Windows 7 Pro SP1 x64.
%0 (batch name) %1 (1st parameter) %2 (2nd parameter)
example:
C:\CSW>MyBatchFile.bat "C:\Program files" "C:\CSW\My File.txt"
Not sure if this works with vim but it does work with bash in windows.
You just need to call by adding double quote in it.
I dont have enough idea about Vim script. but while running in command prompt if you will give the complete exe path having space then it will give error like
C:>c:\Program Files\Internet Explorer\iexplore.exe
'c:\Program' is not recognized as an internal or external command,
operable program or batch file.
But It will work if you will surrounded with double qoute.
C:>"c:\Program Files\Internet Explorer\iexplore.exe"
C:>
Basically, I want to tell Vim:
Open my web browser (for instance, Firefox)
Open this file (say index.php) in thought this address : http://localhost
In other words: http://localhost/index.php
PS: Unfortunately I use Windows XP
If you are running Vim on windows, then this will work:
:! start http://localhost/index.php
This will use the default browser, if you wanted to start a specific browser then you would need the explicit path to the executable (instead of start).
From the Vim help cmd:
:!{cmd}
Execute {cmd} with the
shell. See also the 'shell' and
'shelltype' option.
Obviously, if you are on some other system you just need to use the appopriate command to start the browser on that platform.
on mac you can
:!open http://localhost/index.php
On Unix/Linux, use
:! firefox http://localhost/%:p
%:p is the path and filename of the current buffer
You'll need to use a method appropriate to your environment to start the web browser, but you already asked a question about that.
So, use :!start cmd /c ..., !d:\path\to\firefox ... or whatever. The important bit: you'll want to use "http://localhost/" . expand("%:t") as the argument passed to the browser. So, do something like
:exec ":!start cmd /c ... " . "http://localhost/" . expand("%:t")
^- leave a trailing space here
EDIT: A Clarification: expand("%:t") is a Vim script expression which expands to the last component of the current filename. On Windows this means that if the current filename is C:\a complicated path\to\index.html, expand("%:t") will return index.html.
HTH.
I want to run command like this:
vim -c "%g/blablabla/norm /str<ESC>cwSTR" file
How I write escape character in the command?
As you type the command, use control-v then escape to enter the escape.
However, I have to question whether vim is the right tool for this job. Normally, you would be better off with something like sed. That said, I'm not quite clear what the vim command is up to, so maybe you do need it.
This is what I would do:
vim -s -c ':exec "normal %g/blablabla/norm /str\<Esc>cwSTR"' file
Notice that I am using :exec to expand the "\" to the real . The advantage? it is more script friendly. However, I am not sure what this command is doing, are you using some of your custom maps here?