Vim Tips Wiki
(Change <tt> to <code>, perhaps also minor tweak.)
 
(2 intermediate revisions by one other user not shown)
Line 1: Line 1:
 
{{sandbox}}
 
{{sandbox}}
 
<!-- Feel free to experiment below to safely try wiki editing. Remember to click "Preview". -->
 
<!-- Feel free to experiment below to safely try wiki editing. Remember to click "Preview". -->
jo
 
hu
 
vi
 
bul qsrc
 
 
test 1 2 3 4 5.
 
 
<nowiki>"get image size with F4 with perl Image::Size module<br>
 
 
fun! PerlImageSize()<br>
 
 
:g/src<br>
 
 
normal $<br>
 
 
normal N<br>
 
normal 2w<br>
 
perl << EOF<br>
 
use Image::Size;<br />
 
$jo = VIM::Eval("expand('<cfile>')");<br />
 
$size = Image::Size::html_imgsize("$jo");<br />
 
VIM::Eval("setreg('a', '$size')");<br />
 
EOF<br />
 
normal $<br />
 
normal "ap<br />
 
endfun<br />
 
nnoremap <F4> :call PerlImageSize()<CR><br /></nowiki>
 
 
 
:A quick hack to enable generics:
 
:#open your <tt>java_getset.vim</tt> file
 
:#search for definition <tt>let s:variable = ......</tt>
 
:#in that line add the underlined part of: <tt>let s:variable = '\(\s*\)\(\(' . s:modifier . '\s\+\)*\)\(' . s:javaname . <u>s:generics . </u>'\)' . s:brackets . '\s\+\(' . s:javaname . '\)\s*\(;\|=[^;]\+;\)'</tt>
 
:#before that line add: <tt>let s:generics = '\%(\s*\%(<.*>\)\)\='</tt>
 
 
----
 
Hmm, I haven't ever used the Sandbox. I didn't expect to see any content that was clearly put on by another user.
 
 
I don't want to clobber something that another user is working on, but I need to use the Sandbox to figure out wikimarkup.
 
So I am going to append my own experimentation instead of overwriting what I see. Hope that's ok.
 
 
[[User:Perlsomian|Perlsomian]] 04:15, April 2, 2012 (UTC)
 
 
[[Category:Cygwin]]
 
 
This tip pertains to interoperability between the ''Cygwin'' shell and the non-Cygwin
 
Native Windows Application ('''NWApp''') flavor of Vim (Gvim as well).
 
 
In surveying the existing tips on this topic, I've noticed that I've had a difficult
 
time making quick sense of the scripting examples given for addressing the interoperability
 
issues between Cygwin's shell and NWApp Gvim. Part of the reason for this is that the
 
flags or switches for a single most important utility are not fully explained in those tips.
 
That utility is <span title="the Fine Manual for Cygwin utilities">[http://cygwin.com/cygwin-ug-net/using-utils.html#cygpath|"cygpath"]</span>; the
 
purpose of cygpath is pointedly to support enhanced flexibility in how Cygwin can be used
 
to get things done the way you want to do them.
 
 
Some Cygwin users (including people of note - who are considered knowledgeable by others)
 
have a separatist mentality about Cygwin: don't think getting Cygwin and non-Cygwin programs
 
working together to be interesting or appropriate. Yes, this observation is off the point of a tip
 
about Vim, but it is made for a reason: some may find that if they ask questions in various
 
Cygwin venues, that pertain to interoperability, a response may be of the <em>why would you want
 
to do <b>that</b>?!</em> sort. Persevere in working out how to get things done ''your way'', regardless.
 
 
----
 
==Formatting tweaks==
 
For some reason these need to be saved in order to see them, preview doesn't syntax highlight.
 
 
<source lang='vim'>
 
" The default Vim syntax file has limited 'fold' definitions, so define more.
 
 
" define groups that cannot contain the start of a fold
 
syn cluster vimNoFold contains=vimComment,vimLineComment,vimCommentString,vimString,vimSynKeyRegion,vimSynRegPat,vimPatRegion,vimMapLhs,vimOperParen,@EmbeddedScript
 
syn cluster vimEmbeddedScript contains=vimMzSchemeRegion,vimTclRegion,vimPythonRegion,vimRubyRegion,vimPerlRegion
 
 
" fold while loops
 
syn region vimFoldWhile
 
\ start="\<wh\%[ile]\>"
 
\ end="\<endw\%[hile]\>"
 
\ transparent fold
 
\ keepend extend
 
\ containedin=ALLBUT,@vimNoFold
 
\ skip=+"\%(\\"\|[^"]\)\{-}\%("\|$\)\|'[^']\{-}'+ "'
 
 
" fold for loops
 
syn region vimFoldFor
 
\ start="\v<for>%(\s*\n\s*\\)?\s*\k+%(\s*\n\s*\\\s*)?\s*<in>"
 
\ end="\<endfo\%[r]\>"
 
\ transparent fold
 
\ keepend extend
 
\ containedin=ALLBUT,@vimNoFold
 
\ skip=+"\%(\\"\|[^"]\)\{-}\%("\|$\)\|'[^']\{-}'+ "'wiki syntax highlighting'
 
 
" fold if...else...endif constructs
 
"
 
" note that 'endif' has a shorthand which can also match many other end patterns
 
" if we did not include the word boundary \> pattern, and also it may match
 
" syntax end=/pattern/ elements, so we must explicitly exclude these
 
syn region vimFoldIfContainer
 
\ start="\<if\>"
 
\ end="\<en\%[dif]\>=\@!"
 
\ transparent
 
\ keepend extend
 
\ containedin=ALLBUT,@vimNoFold
 
\ contains=NONE
 
\ skip=+"\%(\\"\|[^"]\)\{-}\%("\|$\)\|'[^']\{-}'+ "'wiki syntax highlighting'
 
syn region vimFoldIf
 
\ start="\<if\>"
 
\ end="^\s*\\\?\s*else\%[if]\>"ms=s-1,me=s-1
 
\ fold transparent
 
\ keepend
 
\ contained containedin=vimFoldIfContainer
 
\ nextgroup=vimFoldElseIf,vimFoldElse
 
\ contains=TOP
 
\ skip=+"\%(\\"\|[^"]\)\{-}\%("\|$\)\|'[^']\{-}'+ "'wiki syntax highlighting'
 
syn region vimFoldElseIf
 
\ start="\<else\%[if]\>"
 
\ end="^\s*\\\?\s*else\%[if]\>"ms=s-1,me=s-1
 
\ fold transparent
 
\ keepend
 
\ contained containedin=vimFoldIfContainer
 
\ nextgroup=vimFoldElseIf,vimFoldElse
 
\ contains=TOP
 
\ skip=+"\%(\\"\|[^"]\)\{-}\%("\|$\)\|'[^']\{-}'+ "'wiki syntax highlighting'
 
syn region vimFoldElse
 
\ start="\<el\%[se]\>"
 
\ end="\<en\%[dif]\>=\@!"
 
\ fold transparent
 
\ keepend
 
\ contained containedin=vimFoldIfContainer
 
\ contains=TOP
 
\ skip=+"\%(\\"\|[^"]\)\{-}\%("\|$\)\|'[^']\{-}'+ "'wiki syntax highlighting'
 
 
" fold try...catch...finally...endtry constructs
 
syn region vimFoldTryContainer
 
\ start="\<try\>"
 
\ end="\<endt\%[ry]\>"
 
\ transparent
 
\ keepend extend
 
\ containedin=ALLBUT,@vimNoFold
 
\ contains=NONE
 
\ skip=+"\%(\\"\|[^"]\)\{-}\%("\|$\)\|'[^']\{-}'+ "'wiki syntax highlighting'
 
syn region vimFoldTry
 
\ start="\<try\>"
 
\ end="^\s*\\\?\s*\(fina\%[lly]\|cat\%[ch]\)\>"ms=s-1,me=s-1
 
\ fold transparent
 
\ keepend
 
\ contained containedin=vimFoldTryContainer
 
\ nextgroup=vimFoldCatch,vimFoldFinally
 
\ contains=TOP
 
\ skip=+"\%(\\"\|[^"]\)\{-}\%("\|$\)\|'[^']\{-}'+ "'wiki syntax highlighting'
 
syn region vimFoldCatch
 
\ start="\<cat\%[ch]\>"
 
\ end="^\s*\\\?\s*\(cat\%[ch]\|fina\%[lly]\)\>"ms=s-1,me=s-1
 
\ fold transparent
 
\ keepend
 
\ contained containedin=vimFoldTryContainer
 
\ nextgroup=vimFoldCatch,vimFoldFinally
 
\ contains=TOP
 
\ skip=+"\%(\\"\|[^"]\)\{-}\%("\|$\)\|'[^']\{-}'+ "'wiki syntax highlighting'
 
syn region vimFoldFinally
 
\ start="\<fina\%[lly]\>"
 
\ end="\<endt\%[ry]\>"
 
\ fold transparent
 
\ keepend
 
\ contained containedin=vimFoldTryContainer
 
\ contains=TOP
 
\ skip=+"\%(\\"\|[^"]\)\{-}\%("\|$\)\|'[^']\{-}'+ "'wiki syntax highlighting'
 
 
" Folding of functions and augroups is built-in since VIM 7.2 (it was introduced
 
" with vim.vim version 7.1-76) if g:vimsyn_folding contains 'a' and 'f', so set
 
" this variable if you want it. (Also in older VIM versions.)
 
if v:version <= 701 && exists('g:vimsyn_folding')
 
" Starting with VIM 7.2, this is built-in. Retrofit for older versions unless
 
" VIM 7.1 already has it patched in.
 
let s:vimsyn_folding = g:vimsyn_folding
 
if v:version == 701
 
" Special check for VIM 7.1: Since we cannot check for that particular
 
" version of the runtime file, check one of the associated group names
 
" itself for the 'fold' keyword.
 
redir => s:synoutput
 
silent! syn list vimFuncBody
 
redir END
 
if s:synoutput =~ 'fold'
 
" No need to retrofit, this vim.vim version already supports folding.
 
let s:vimsyn_folding = ''
 
endif
 
unlet s:synoutput
 
endif
 
 
if s:vimsyn_folding =~# 'f'
 
" fold functions
 
syn region vimFoldFunction
 
\ start="\<fu\%[nction]!\=\s\+\%(<[sS][iI][dD]>\|[sSgGbBwWtTlL]:\)\?\%(\i\|[#.]\|{.\{-1,}}\)*\ze\s*("
 
\ end="\<endfu\%[nction]\>"
 
\ transparent fold
 
\ keepend extend
 
\ containedin=ALLBUT,@vimNoFold
 
\ skip=+"\%(\\"\|[^"]\)\{-}\%("\|$\)\|'[^']\{-}'+ "'wiki syntax highlighting'
 
endif
 
 
" fold augroups
 
if s:vimsyn_folding =~# 'a'
 
syn region vimFoldAugroup
 
\ start="\<aug\%[roup]\ze\s\+\(END\>\)\@!"
 
\ end="\<aug\%[roup]\s\+END\>"
 
\ transparent fold
 
\ keepend extend
 
\ containedin=ALLBUT,@vimNoFold
 
\ skip=+"\%(\\"\|[^"]\)\{-}\%("\|$\)\|'[^']\{-}'+ "'wiki syntax highlighting'
 
endif
 
unlet s:vimsyn_folding
 
endif
 
</source>
 

Latest revision as of 08:39, 15 July 2012

Welcome to the Vim Tips Wiki's sandbox!
This page exists so that you can practice editing or formatting (see Editing help) without changing any serious content. Feel free to try wiki editing out here first.
There is a tutorial on the Central (coordinating) Wikia that will step you through more of the things you can do. Wiki allow for rather complicated formatting. It can look overwhelming when you begin, but don't let it worry you. Just start with the basics... enter some text, and learn the other pieces as you go. Your content contributions are welcome and important. The wiki is a collaborative effort and others can help with formatting and other improvements.
Best wishes!