For me I think the following is the case:
$VIMRUNTIME='C:/Program Files (x86)/Vim/vim73'
But if I look in the pc's environment variables (via Computer>Properties etc) I cannot see this path - should I add it manually?
_vimrc currently looks like the following:
set nocompatible
source $VIMRUNTIME/vimrc_example.vim
source $VIMRUNTIME/mswin.vim
behave mswin
set diffexpr=MyDiff()
" Use CTRL-S for saving, also in Insert mode
:nnoremap <C-S> :<C-U>update<CR>
:vnoremap <C-S> :<C-U>update<CR>gv
:cnoremap <C-S> <C-C>:update<CR>
:inoremap <C-S> <C-O>:update<CR>
function MyDiff()
let opt = '-a --binary '
if &diffopt =~ 'icase' | let opt = opt . '-i ' | endif
if &diffopt =~ 'iwhite' | let opt = opt . '-b ' | endif
let arg1 = v:fname_in
if arg1 =~ ' ' | let arg1 = '"' . arg1 . '"' | endif
let arg2 = v:fname_new
if arg2 =~ ' ' | let arg2 = '"' . arg2 . '"' | endif
let arg3 = v:fname_out
if arg3 =~ ' ' | let arg3 = '"' . arg3 . '"' | endif
let eq = ''
if $VIMRUNTIME =~ ' '
if &sh =~ '\<cmd'
let cmd = '""' . $VIMRUNTIME . '\diff"'
let eq = '"'
else
let cmd = substitute($VIMRUNTIME, ' ', '" ', '') . '\diff"'
endif
else
let cmd = $VIMRUNTIME . '\diff'
endif
silent execute '!' . cmd . ' ' . opt . arg1 . ' ' . arg2 . ' > ' . arg3 . eq
endfunction
Though vim helpfiles describe $VIMRUNTIME as an environment variable, you may find that it is not set in your shell.
It should be set in Vim, and you should be able to see it, in Vim, thus:
:echo $VIMRUNTIME
The ever-so helpful Vim helpfiles don't explain this.
But they do describe in exhausting detail the steps Vim goes through to derive a value for $VIMRUNTIME in its own, er, runtime environment.
If you are blessed with some form of obsessive compulsion, you might read far enough through this dense help text to see, at the very bottom, where it says that if want $VIMRUNTIME in your shell, you can get it with the following command:
VIMRUNTIME=`vim -e -T dumb --cmd 'exe "set t_cm=\<C-M>"|echo $VIMRUNTIME|quit' | tr -d '\015' `
Despite appearances, this is not some sort of joke. I repeat:
VIMRUNTIME=`vim -e -T dumb --cmd 'exe "set t_cm=\<C-M>"|echo $VIMRUNTIME|quit' | tr -d '\015' `
No. $VIMRUNTIME is a special environment variable that automatically gets set by Vim.
:help $VIMRUNTIME would have already told you this:
You don't normally set $VIMRUNTIME yourself, but let Vim figure it out.
Learn how the excellent and comprehensive :help is structured; all the information is in there (you just need to know how to find it)!
Related
So in my Jenkins pipeline I run a couple of curl commands across different stages. I store the ouput of Stage1 into a file and for every item in that list I run another curl command and use the output of that to extract some values using jq.
However from the second stage I can't seem to store the jq extracted values into variables to echo them later. What am I doing wrong?
{Stage1}
.
.
.
{Stage2}
def lines = stageOneList.readLines()
lines.each { line -> println line
stageTwoList = sh (script: "curl -u $apptoken" + " -X GET --url " + '"' + "$appurl" + "components/tree?component=" + line + '"', returnStdout: true)
pfName = sh (script: "jq -r '.component.name' <<< '${stageTwoList}' ")
pfKey = sh (script: "jq -r '.component.key' <<< '${stageTwoList}' ")
echo "Component Names and Keys\n | $pfName | $pfKey |"
}
returns in the end for Stage2
[Pipeline] sh
+ jq -r .component.name
digital-hot-wallet-gateway
[Pipeline] sh
+ jq -r .component.key
dhwg
[Pipeline] echo
Component Names and Keys
| null | null |
Any help in the right direction appreciated!
You passed true as the argument for the returnStdout argument to the shell step method for stageTwoList, but then forgot to use the same argument for the JSON parsed returns to the next two variable assignments:
def lines = stageOneList.readLines()
lines.each { line -> println line
stageTwoList = sh(script: "curl -u $apptoken" + " -X GET --url " + '"' + "$appurl" + "components/tree?component=" + line + '"', returnStdout: true)
pfName = sh(script: "jq -r '.component.name' <<< '${stageTwoList}' ", returnStdout: true)
pfKey = sh(script: "jq -r '.component.key' <<< '${stageTwoList}' ", returnStdout: true)
echo "Component Names and Keys\n | $pfName | $pfKey |"
}
Note you can also make this much easier on yourself by doing the JSON parsing natively in Groovy and with Jenkins Pipeline step methods:
String stageTwoList = sh(script: "curl -u $apptoken" + " -X GET --url " + '"' + "$appurl" + "components/tree?component=" + line + '"', returnStdout: true)
Map stageTwoListData = readJSON(text: stageTwoList)
pfName = stageTwoListData['component']['name']
pfKey = stageTwoListData['component']['key']
I try to use:
string result;
string path = "C:/winccoa.projects/filters/bin/tools/rxrepl.exe";
string cmd = "'opcki' | " + path + " -s 'op' -r 'tata'";
system(cmd, result);
DebugN(result);
But in LogViewer i see nothing, instead ["tatacki"]
Why? What i doing wrong?
In PowerShell that works fine:
PS C:\> 'opcki' | C:/winccoa.projects/filters/bin/tools/rxrepl.exe -s "op" -r "tata"
tatacki
I'm assuming that WinCC's system() function targets cmd.exe, not powershell.exe (which is typical, because historically cmd.exe has been the default shell, and APIs are unlikely to change, so as to maintain backward compatibility).
Therefore, formulate your command for cmd.exe:
string cmd = "echo opcki | " + path + " -s op -r tata";
Not the use of echo to produce output and the omission of single-quoting ('...'), which cmd.exe doesn't recognize.
If embedded quoting were needed, you'd have to use `" inside "..." PowerShell strings (or use '...' PowerShell strings (whose content is taken literally) and embed " chars. as-is).
Script:
#!/bin/sh -x
ARGS=""
CMD="./run_this_prog"
. . .
ARGS="-first_args '-A select[val]' "
. . .
$CMD $ARGS
I want the commandline to be expanded like this when I run this shell script:
./run_this_prog -first_args '-A select[val]'
Instead what shell does (note the added '\' before each single quote):
+ ARGS=
+ CMD='./run_this_prog'
+ ARGS='-first_args '\''-A select[val]'\'' '
and what it ran on commandline (escaped every special char - Not what I want):
./run_this_prog -first_args \'\-A select\[val\]\'
I tried escaping single quotes like :
ARGS="-first_args \'-A select[val]\' "
But that resulted in (added '\' after each backslash):
+ ARGS=
+ CMD='./run_this_prog'
+ ARGS='-first_args \'\''-A select[val]\'\'' '
I did my googling but couldn't find anything relevant. What am I missing here?
I am using sh-3.2 on rel6 centOS.
Once a quote is inside a string, it will not work the way you want: Inside a string quotes are not syntactic elements, they are just literal characters. This is one reason why bash offers arrays.
Replace:
#!/bin/sh -x
...
ARGS="-first_args '-A select[val]' "
$CMD $ARGS
With:
#!/bin/bash -x
...
ARGS=(-first_args '-A select[val]')
"$CMD" "${ARGS[#]}"
For a much more detailed discussion of this issue, see: "I'm trying to put a command in a variable, but the complex cases always fail!"
I've just downloaded vim7.4 for windows and I'll like to know what the default vimrc file that comes with it is doing. Just a brief explanation of each item would be nice to know.
Here it is.
set nocompatible
source $VIMRUNTIME/vimrc_example.vim
source $VIMRUNTIME/mswin.vim
behave mswin
set diffexpr=MyDiff()
function MyDiff()
let opt = '-a --binary '
if &diffopt =~ 'icase' | let opt = opt . '-i ' | endif
if &diffopt =~ 'iwhite' | let opt = opt . '-b ' | endif
let arg1 = v:fname_in
if arg1 =~ ' ' | let arg1 = '"' . arg1 . '"' | endif
let arg2 = v:fname_new
if arg2 =~ ' ' | let arg2 = '"' . arg2 . '"' | endif
let arg3 = v:fname_out
if arg3 =~ ' ' | let arg3 = '"' . arg3 . '"' | endif
let eq = ''
if $VIMRUNTIME =~ ' '
if &sh =~ '\<cmd'
let cmd = '""' . $VIMRUNTIME . '\diff"'
let eq = '"'
else
let cmd = substitute($VIMRUNTIME, ' ', '" ', '') . '\diff"'
endif
else
let cmd = $VIMRUNTIME . '\diff'
endif
silent execute '!' . cmd . ' ' . opt . arg1 . ' ' . arg2 . ' > ' . arg3 . eq
endfunction
set nocompatible
By default, Vim behaves like its ancestor vi. It's not really a problem for quick edits but it seriously sucks if you intend to use it for more than 10 minutes. set nocompatible makes Vim more Vim-like than Vi-like.
See :help nocompatible.
source $VIMRUNTIME/vimrc_example.vim
source $VIMRUNTIME/mswin.vim
Source those two files. vimrc_example.vim contains example settings. It may be a good idea to take a look at it: it may contain useful things for you.
behave mswin
mswin.vim contains a bunch of settings and mappings designed to make Vim work more or less like a typical Windows editor, like <C-v> to paste. This command "activates" that stupid behavior.
set diffexpr=MyDiff()
function MyDiff()
let opt = '-a --binary '
if &diffopt =~ 'icase' | let opt = opt . '-i ' | endif
if &diffopt =~ 'iwhite' | let opt = opt . '-b ' | endif
let arg1 = v:fname_in
if arg1 =~ ' ' | let arg1 = '"' . arg1 . '"' | endif
let arg2 = v:fname_new
if arg2 =~ ' ' | let arg2 = '"' . arg2 . '"' | endif
let arg3 = v:fname_out
if arg3 =~ ' ' | let arg3 = '"' . arg3 . '"' | endif
let eq = ''
if $VIMRUNTIME =~ ' '
if &sh =~ '\<cmd'
let cmd = '""' . $VIMRUNTIME . '\diff"'
let eq = '"'
else
let cmd = substitute($VIMRUNTIME, ' ', '" ', '') . '\diff"'
endif
else
let cmd = $VIMRUNTIME . '\diff'
endif
silent execute '!' . cmd . ' ' . opt . arg1 . ' ' . arg2 . ' > ' . arg3 . eq
endfunction
This is a function that defines Vim's behavior when used for diffing two or more buffers. It looks more like a hack than anything else, to me. It seems to be checking if your Windows environment is able to do the diff itself and, if not, use the builtin diff.
If you intend to use/learn Vim seriously, none of the above should go into your $HOME\_vimrc. Not even the first line since nocompatible is set automatically for you if Vim finds a $HOME\_vimrc.
I'm not really familiar with Windows so the diff part may be useful but you can safely drop the rest.
When you see a set something, do :help 'something (with the single quote).
You may have figured this out, but one thing you may want to add if you remove the vimrc_example.vim source is syntax on. Without this, text will be colorless in gvim regardless of colorscheme.
I want to call msbuild from the function below and redirect the output to a new buffer.
My problem is that I need to use a variable, for the filename, and therefore cant use '!' (can I?), and when I use exe or system() read complains that I'm not giving it a proper file.
func! myFunction()
let findstr = "findstr /s /m " . '"' . expand("%:t") . '"' . " *.vcxproj"
for project in split(system(findstr), nr2char(10))
echo "Building '" . project . "'"
let msbuild = "c:\\windows\\Microsoft.NET\\Framework\\v4.0.30319\\msbuild.exe" . " " . project . " " . "/t:rebuild /p:configuration=debug"
:tabnew | r system(msbuild) "<--THIS LINE HERE
endfor
endfunc
The :read command takes a file not a vim expression. However it can read in from standard output via :read !{cmd}. Example :%r!ls. Using the :execute command you can build your new command with your variable.
exe '%r!' . msbuild
Or you can use :put along with the expression register if you want to use an expression like system(). (Probably want to follow this with :0d_ to delete the first empty line)
put=system(msbuild)
Now it looks like you are trying to build your project and get a list of errors. I would recommend you look into :make, the 'makeprg' option, and the quickfix list as this is a more vim way of building a project.
For more help see:
:h :r!
:h :exe
:h :pu
:h #=
:h :make
:h 'makeprg'
:h quickfix
This is a function you can use to execute arbitrary shell commands and present their output in a new window ( you can put this in your _vimrc):
let s:lastcmd = ''
function! s:RunShellCommand(cmdline, bang)
" Support for repeating last cmd with bang:
let _ = a:bang != '' ? s:lastcmd : a:cmdline == '' ? '' : join(map(split(a:cmdline), 'expand(v:val)'))
if _ == ''
return
endif
let s:lastcmd = _
let bufnr = bufnr('%')
let winnr = bufwinnr(_)
" You can position the new window whenever you want, I chose below + right:
silent! execute winnr < 0 ? 'belowright new ' . fnameescape(_) : winnr . 'wincmd w'
" I could set buftype=nofile, but then no switching back and forth buffers.
" The results are presented just for viewing, not editing, modify at will:
setlocal buftype=nowrite bufhidden=wipe nobuflisted noswapfile wrap number
setlocal modifiable
silent! :%d
" Useful for debugging, if you encounter issues with fnameescape():
call setline(1, 'You entered: ' . a:cmdline)
call setline(2, 'Expanded to: ' . _)
call append(line('$'), substitute(getline(2), '.', '=', 'g'))
silent execute '$read !' . _
silent! execute 'autocmd BufUnload <buffer> execute bufwinnr(' . bufnr . ') . ''wincmd w'''
" If resizing is unwanted for commands with too much output, remove this line:
silent! execute 'autocmd BufEnter <buffer> execute ''resize '' . line(''$'')'
" You can use <localleader>r to re-execute the last command:
silent! execute 'nnoremap <silent> <buffer> <localleader>r :call <SID>RunShellCommand(''' . _ . ''', '''')<CR>'
execute 'resize ' . line('$')
setlocal nomodifiable
1
endfunction " RunShellCommand(cmdline)
command! -complete=shellcmd -nargs=* -bang Shell call s:RunShellCommand(<q-args>, '<bang>')
Use like:
:Shell gcc -ggdb -o test test.c && ./test