Automatic syntax highlighting will not work in gVim - r

I think I've tried every intuitive combination of these four commands, with and without colons, in my _vimrc:
syntax enable
syntax on
set filetype=r
set syntax=r
But when I open a script in gVim, it's all one solid color. Within a session, both ':set syntax=r' and ':set filetype=r' work fine, while the other two do nothing.
My full _vimrc is below:
set nocompatible
source $VIMRUNTIME/vimrc_example.vim
source $VIMRUNTIME/mswin.vim
behave mswin
set keymodel-=stopsel
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
filetype plugin indent on
" show existing tab with 4 spaces width
set tabstop=4
" when indenting with '>', use 4 spaces width
set shiftwidth=4
" On pressing tab, insert 4 spaces
set expandtab
"show line numbers
set number
"syntax highlighting for R
"syntax enable
syntax on
set filetype=r
"set syntax=r
colorscheme elflord
"see commands as they're being typed
set showcmd
"change the key combo for normal mode to 'jk'
inoremap jk <ESC>
"add line below cursor in insert mode
:autocmd InsertEnter * set cul
:autocmd InsertLeave * set nocul

Related

R function cat outputs to clipbaord

I have written an R function to write some SAS code (yes, I know, I am lazy), and it prints text as follows:
proc_sql_missing <- function(cols, data){
cat("\nproc sql;")
cat(paste0("\n\tselect\tPat_TNO,\n\t\t\t", paste(names(data)[cols], collapse = ",\n\t\t\t")))
cat("\n\tfrom", substitute(data))
cat(paste0("\n\twhere\t", paste(names(data)[cols], collapse = "= . OR\n\t\t\t"), "= .;"))
cat("\nquit;")
}
Which when called prints something similar to the following to the R output:
proc sql;
select Pat_TNO,
fuq_pa_enjoy_hate,
fuq_pa_bored_interest,
fuq_pa_like_dislike,
fuq_pa_pleasble_unpleasble,
fuq_pa_absorb_notabsorb,
fuq_pa_fun_notfun,
fuq_pa_energizing_tiring,
fuq_pa_depress_happy,
fuq_pa_pleasant_unpleast,
fuq_pa_good_bad,
fuq_pa_invigor_notinvigor,
fuq_pa_frustrate_notfrust,
fuq_pa_gratifying_notgrat,
fuq_pa_exhilarate_notexhil,
fuq_pa_stimulate_notstim,
fuq_pa_accom_notaccom,
fuq_pa_refresh_notrefresh,
fuq_pa_doing_notdoing
from followup
where fuq_pa_enjoy_hate= . OR
fuq_pa_bored_interest= . OR
fuq_pa_like_dislike= . OR
fuq_pa_pleasble_unpleasble= . OR
fuq_pa_absorb_notabsorb= . OR
fuq_pa_fun_notfun= . OR
fuq_pa_energizing_tiring= . OR
fuq_pa_depress_happy= . OR
fuq_pa_pleasant_unpleast= . OR
fuq_pa_good_bad= . OR
fuq_pa_invigor_notinvigor= . OR
fuq_pa_frustrate_notfrust= . OR
fuq_pa_gratifying_notgrat= . OR
fuq_pa_exhilarate_notexhil= . OR
fuq_pa_stimulate_notstim= . OR
fuq_pa_accom_notaccom= . OR
fuq_pa_refresh_notrefresh= . OR
fuq_pa_doing_notdoing= .;
quit;
Is there any way I can automatically copy this text to the clipboard so I can paste straight into SAS?
capture.output to capture the output:
output <- capture.output(proc_sql_missing(cols, data))
Then you can use clipr::write_clip(output), or writeClipboard(output) on Windows.
You can specify file = "clipboard" as an argument to cat, so if you change your function to
proc_sql_missing <- function(cols, data) {
cat(
paste(
"\nproc sql;",
paste0("\n\tselect\tPat_TNO,\n\t\t\t",
paste(names(data)[cols], collapse = ",\n\t\t\t")),
paste("\n\tfrom", substitute(data)),
paste0("\n\twhere\t",
paste(names(data)[cols], collapse = "= . OR\n\t\t\t"),
"= .;"),
"\nquit;",
sep = "\n"),
file = "clipboard"
)
}
Then when you run, say,
proc_sql_missing(1:3, mtcars)
Then your clipboard will now contain
proc sql;
select Pat_TNO,
mpg,
cyl,
disp
from mtcars
where mpg= . OR
cyl= . OR
disp= .;
quit;

syntax error: unexpected end of file- unix

I am working on my unix homework but I get an error and I couldn't fix. Can anyone please help me?
myCalc is a very simple calculator. operand1 and operand2 are integers. operator is the words plus, minus, div, and times. The operands and operators will be passed on the command line. Generate error messages if the operands are not valid or the operator is not valid. If no arguments are passed show the usage statement.
if ( $2 =~ "plus" ) then
# c = $1 + $3
echo "The sum is: $c"
else if ( $2 =~ "minus" ) then
# c = $1 - $3
echo "The difference is: $c"
else if ( $2 =~ "div" ) then
# c = $1 / $3
echo "The quotient is: $c"
else if ( $2 =~ "times" ) then
# c = $1 * $3
echo "The product is: $c"
else echo "You have entered an invalid operation"
exit 2
if ( $# < 3 ) then
echo "You are missing an operand or operator"
exit 1
endif

H2 csvread encrypt

H2-folks,
I have a H2-Database-Table like this:
CREATE TABLE Achimv
(
NAME CHAR(10)
, VORNAME CHAR(10)
, PLZ CHAR(10)
)
;
and I have got a CSV-File with '$' as row separators:
Berger $Willi$26531
Meyer $Hans $85322
Klausen$Till $52389
and the INSERT-Statements work perfectly as follows:
INSERT INTO Achimv
SELECT * FROM CSVREAD
('E:/Achimv.csv',
' NAME
$ VORNAME
$ PLZ
', 'charset=UTF-8 fieldSeparator=$');
But now the table should be filled with the first two rows being
AES-encrypted and the third one not.
My modification (done like in the H2-Dokumentation-pdf):
. . . . .
('E:/Achimv.csv',
' ENCRYPT('AES', '00', STRINGTOUTF8(NAME))
$ ENCRYPT('AES', '00', STRINGTOUTF8(VORNAME))
$ PLZ
', 'charset=UTF-8 fieldSeparator=$');
ended with a SQL-Syntax-Error:
. . .
' ENCRYPT('AES[*]', '00', STRINGTOUTF8(NAME))
How is it possible to load CSV-data with CSVREAD in combination with ENCRYT ?
Thanks in advance
Achim
INSERT INTO Achimv
SELECT
ENCRYPT('AES', '00', STRINGTOUTF8(NAME)),
ENCRYPT('AES', '00', STRINGTOUTF8(VORNAME)),
PLZ
FROM CSVREAD
('E:/Achimv.csv',
' NAME
$ VORNAME
$ PLZ
', 'charset=UTF-8 fieldSeparator=$');

In Gnuplot, how to plot a function many times on the same plot in a for loop

In gnuplot, I'm trying to plot a function with 5 parameters, whose values are stored in an external file, 8 times on the same graph. I want to plot the vapor pressure of 8 species as a function of temperature; the vapor pressure is parametrized by 5 variables. I have tried using a do-for loop, but that only plots one species. How can I plot the function 8 times on the same plot using the 8 sets of parameters? The code below is based on this answer, and works except that the answer as given will print 8 pngs, but I would like 1, and modified it in my attempt to do so.
parameters.txt
A B C D E
33.634 -3647.9 -8.6428 -9.69E-11 1.19E-06
19.419 -5869.9 -0.4428 -1.26E-02 5.22E-06
-15.077 -4870.2 14.501 -3.16E-02 1.35E-05
76.1 -5030 -25.078 9.76E-03 -2.58E-13
2.1667 -2631.8 4.035 -1.18E-02 6.10E-06
39.917 -4132 -10.78 1.97E-10 2.04E-06
29.89 -3953.5 -7.2253 2.11E-11 8.96E-07
99.109 -7533.3 -32.251 1.05E-02 1.23E-12
vapor.plt
reset
datafile = "parameters.txt"
set terminal pngcairo
set xrange [273.15:493.15]
set logscale y
set output "vapor.png"
do for [step=1:8] {
# read parameters from file, where the first line is the header, thus the +1
a=system("awk '{ if (NR == " . step . "+1) printf \"%f\", $1}' " . datafile)
b=system("awk '{ if (NR == " . step . "+1) printf \"%f\", $2}' " . datafile)
c=system("awk '{ if (NR == " . step . "+1) printf \"%f\", $3}' " . datafile)
d=system("awk '{ if (NR == " . step . "+1) printf \"%f\", $4}' " . datafile)
e=system("awk '{ if (NR == " . step . "+1) printf \"%f\", $5}' " . datafile)
# convert parameters to numeric format
a=a+0.
b=b+0.
c=c+0.
d=d+0.
e=e+0.
plot 10**(a + b/x + c*log10(x) + d*x + e*x**2) title ''
}
set output
To plot several function into one graph, you must either use only one plot command, and separate the functions with commas:
plot f(x), g(x), h(x)
This would plot all three function in one graph. For your case you would need to extract the parameters first to have a1, a2,... a8 etc. This would have the advantage, that you could have a key (legend) for the parameter sets.
The second option fits better to your existing script. You need to put the plot calls in a multiplot:
reset
datafile = "parameters.txt"
set terminal pngcairo
set xrange [273.15:493.15]
set logscale y
set output "vapor.png"
set lmargin at screen 0.1
set rmargin at screen 0.9
set bmargin at screen 0.1
set tmargin at screen 0.9
set multiplot
do for [step=1:8] {
# read parameters from file, where the first line is the header, thus the +1
a=system("awk '{ if (NR == " . step . "+1) printf \"%f\", $1}' " . datafile)
b=system("awk '{ if (NR == " . step . "+1) printf \"%f\", $2}' " . datafile)
c=system("awk '{ if (NR == " . step . "+1) printf \"%f\", $3}' " . datafile)
d=system("awk '{ if (NR == " . step . "+1) printf \"%f\", $4}' " . datafile)
e=system("awk '{ if (NR == " . step . "+1) printf \"%f\", $5}' " . datafile)
# convert parameters to numeric format
a=a+0.
b=b+0.
c=c+0.
d=d+0.
e=e+0.
plot 10**(a + b/x + c*log10(x) + d*x + e*x**2) lt step title ''
if (step == 1) {
unset border
unset xtics
unset ytics
}
}
unset multiplot
set output
With multiplot the border and tics would be redrawn each time, which looks ugly (bolder). For this I unset border, xtics and ytics after the first plot. But in order to have the same margins for all plots I set fixed, absolute margins at the beginning. It would be possible to hold the automatic margins, which are computed with the first plot, but that is a bit lengthy (see the topic 'Gnuplot-defined variables' in the docs).
I also used different linetypes for every plot. The above script gives the output:

Highlight keywords in classic ASP

I have this sentense, "The man went outside".
I also have 4 search criterias I would like to get highligted (ignore the brackets), [went|"an WeNT o"|a|t] with [span id="something"][/span].
I have tried out a lot of stuff but I can't figure out how to do this in classic ASP!? If I insert a somewhere in the text, it will search the HTML code for SPAN too, which is bad or it will not find the text as it has been messed up with HTML code. I also tried inserting on all positions in the original text and even with some magic regular expression which I do not understand but I can't get this working :-/
The search-thing is divided with | and can be anything from 1 to 20 things to search for.
Can anyone help me solving how to do this?
I found and tweaked some code and it works perfectly for me:
Function highlightStr (haystack, needles)
' Taken (and tweaked) from these two sites:
' http://forums.aspfree.com/asp-development-5/asp-highlight-keywords-295641.html
' http://www.eggheadcafe.com/forumarchives/scriptingVisualBasicscript/Jul2005/post23377133.asp
'
' INPUT: haystack = search in this string
' INPUT: needles = searches divided by |... example: this|"is a"|search
' OUTPUT: HTML formatted highlighted string
'
If Len(haystack) > 0 Then
' Delete the first and the last array separator "|" (if any)
If Left(needles,1) = "|" Then needles = Right(needles,Len(needles)-1)
If Right(needles,1) = "|" Then needles = Mid(needles,1,Len(needles)-1)
' Delete a multiple seperator (if any)
needles = Replace(needles,"||","|")
' Delete the exact-search chars (if any)
needles = Replace(needles,"""","")
' Escape all special regular expression chars
needles = Replace(needles,"(","\(")
needles = Replace(needles,")","\)")
needles = Replace(needles,".","\.")
If Len(needles) > 0 Then
haystack = " " & haystack & " "
Set re = New RegExp
re.Pattern = "(" & needles & ")"
re.IgnoreCase = True
re.Global = True
highlightStr = re.Replace(haystack,"<span style='background-color:khaki;'>$&</span>")
Else
highlightStr = haystack
End If
Else
highlightStr = haystack
End If
End Function

Resources