On Friday 24 July 2009 18:49:10 Steve Bertrand wrote:
> Forgive the verbosity.

Forgiven, yet snipped ;)

> My desires/don't mind:
>
> - easily set tab width
See securemodelines.vim below sig. Put in $LOCALBASE/share/vim/vim72/plugin.

And the modeline below in C-style comments, within the first or last 5 lines 
of a file will set the TabStop to 4, will use 4 for ShiftWith (Number of 
spaces to use for each step of (auto)indent.), set the TextWidth to 78, will 
NOt ExpandTabs to spaces, enable AutoIndent if syntax is recognized.

/*
 * vim: ts=4 sw=4 noet tw=78 ai
 */

Additionally you want to copy $LOCALBASE/share/vim/vim72/vimrc_example.vim to 
~/.vimrc so you're not stuck in vi compatible mode.

> - fingers near home row
Home/End works, as well as ctrl-a/crtl-e in edit mode.

> - I'm competent/comfortable with CTRL, SHFT etc
Ctrl-R is redo, Ctrl-L refresh screen, shift-; aka : activates command line, 
some useful ones:
:r /foo/bar
   Read file /foo/bar into current position
:r!make -C /usr/ports/editors/vim -V MAINTAINER
   Read output of command into current position (this particular one is handy 
for send-pr)
:set paste
:set nopaste
   Turn off/on auto indenting, so that the OS/Desktop buffer can be pasted 
unmodified.
:split
   Split current file into two windows, switchable with two times ctrl-w
:split ../include/foo.h
   Split current file into two windows, where the top one now loads 
../include/foo.h
:vsplit
   Split windows vertically, rather then horizontally

Split is repeatable and will keep adding virtual windows. Use :close or :quit 
to close a window.

> - *very* quick basic movements within a file (preferably a single
> keyboard gesture will pg-up/dn, end of line, start of line, top, bot,
> erase line, cp line, insert line etc)
pg-up/dn, works
$, for EOL, ^ for SOL
gg for top of file, G for EOF
dd for erase line, or S for erase and insert ("Substitute")
yy for yank line, I for insert SOL, A for insert EOL
v for visual mode, which allows selecting regions to do "stuff" with.

> - smooth copy/paste with a mouse if I want to transfer from devel box to
> my workstation, and back into a different window
It's turned on by default in .vimrc, but I turned it off cause Konsole allows 
me to copy/paste to my desktop. By default vim uses it's own clipboard, which 
means it's limited to current instance or requires closing of vim, so that the 
new instance reads the clipboard contents from ~/.viminfo. If your client 
doesn't copy/paste smoothly, this might be an issue.

> - syntax highlighting (opening/closing braces/brackets/parens) would be
> really nice, but since my win32 client seems black/white, I think this
> is a pipe dream. I can easily live without this. As a matter of fact, I
> negate this statement

Syntax highlighting depends on what your client can support and what terminal 
emulation you're advertising. The default .vimrc mentioned above respects 
$TERM and checks it's termcap for color support. So, this depends more on how 
much time you want to spend figuring out why your terminal emulation doesn't 
support colors. Also, the default assumed background is light, if you're 
really using a dark background (white on black terminal), you will want to 
add:
set bg=dark

to .vimrc.
The used colorscheme then changes accordingly.

> - simple in-editor search/replace would be a nice-have (especially if it
> either understood everything as text, or comprehended Perl-type regexp

:%s/search/replace/g replaces all occurrences in a file, using a dialect of 
basic re. You will want to read :help sub-replace-special and :help pattern.

> - be able to have multiple files open simultaneously for editing, and an
> easy way to flip back and forth (a virtual 'tab' system, if you please)

ctrl-w ctrl-w you'll get used to.

To use securemodelines.vim, put in .vimrc:
set modelines=0
let g:secure_modelines_allowed_items = [
                \ "textwidth",   "tw",
                \ "softtabstop", "sts",
                \ "tabstop",     "ts",
                \ "shiftwidth",  "sw",
                \ "expandtab",   "et",   "noexpandtab", "noet",
                \ "filetype",    "ft",
                \ "foldmethod",  "fdm",
                \ "readonly",    "ro",   "noreadonly", "noro",
                \ "backup",      "bkp",  "nobackup", "nobkp",
                \ "autoindent",  "ai",
                \ "syntax",      "syn"
                \ ]

-- 
Mel

" vim: set sw=4 sts=4 et ft=vim :
" Script:           securemodelines.vim
" Version:          20070518
" Author:           Ciaran McCreesh <ciar...@ciaranm.org>
" Homepage:         http://ciaranm.org/tag/securemodelines
" Requires:         Vim 7
" License:          Redistribute under the same terms as Vim itself
" Purpose:          A secure alternative to modelines

if &compatible || v:version < 700
    finish
endif

if (! exists("g:secure_modelines_allowed_items"))
    let g:secure_modelines_allowed_items = [
                \ "textwidth",   "tw",
                \ "softtabstop", "sts",
                \ "tabstop",     "ts",
                \ "shiftwidth",  "sw",
                \ "expandtab",   "et",   "noexpandtab", "noet",
                \ "filetype",    "ft",
                \ "foldmethod",  "fdm",
                \ "readonly",    "ro",   "noreadonly", "noro",
                \ "rightleft",   "rl",   "norightleft", "norl"
                \ ]
endif

if (! exists("g:secure_modelines_verbose"))
    let g:secure_modelines_verbose = 0
endif

if (! exists("g:secure_modelines_modelines"))
    let g:secure_modelines_modelines=5
endif

if (! exists("g:secure_modelines_leave_modeline"))
    if &modeline
        set nomodeline
        if g:secure_modelines_verbose
            echohl WarningMsg
            echo "Forcibly disabling internal modelines for 
securemodelines.vim"
            echohl None
        endif
    endif
endif

fun! <SID>IsInList(list, i) abort
    for l:item in a:list
        if a:i == l:item
            return 1
        endif
    endfor
    return 0
endfun

fun! <SID>DoOne(item) abort
    let l:matches = matchlist(a:item, '^\([a-z]\+\)\%(=[a-zA-Z0-9_\-.]\+\)\?
$')
    if len(l:matches) > 0
        if <SID>IsInList(g:secure_modelines_allowed_items, l:matches[1])
            exec "setlocal " . a:item
        elseif g:secure_modelines_verbose
            echohl WarningMsg
            echo "Ignoring '" . a:item . "' in modeline"
            echohl None
        endif
    endif
endfun

fun! <SID>DoNoSetModeline(line) abort
    for l:item in split(a:line, '[ \t:]')
        call <SID>DoOne(l:item)
    endfor
endfun

fun! <SID>DoSetModeline(line) abort
    for l:item in split(a:line)
        call <SID>DoOne(l:item)
    endfor
endfun

fun! <SID>CheckVersion(op, ver) abort
    if a:op == "="
        return v:version != a:ver
    elseif a:op == "<"
        return v:version < a:ver
    elseif a:op == ">"
        return v:version >= a:ver
    else
        return 0
    endif
endfun

fun! <SID>DoModeline(line) abort
    let l:matches = matchlist(a:line, '\%(\S\@<!\%(vi\|vim\([<>=]\?
\)\([0-9]\+\)\?\)\|\sex\):\s\+set\?\s\+\([^:]\+\):\...@!')
    if len(l:matches) > 0
        let l:operator = ">"
        if len(l:matches[1]) > 0
            let l:operator = l:matches[1]
        endif
        if len(l:matches[2]) > 0
            if <SID>CheckVersion(l:operator, l:matches[2]) ? 0 : 1
                return
            endif
        endif
        return <SID>DoSetModeline(l:matches[3])
    endif

    let l:matches = matchlist(a:line, '\%(\S\@<!\%(vi\|vim\([<>=]\?
\)\([0-9]\+\)\?\)\|\sex\):\(.\+\)')
    if len(l:matches) > 0
        let l:operator = ">"
        if len(l:matches[1]) > 0
            let l:operator = l:matches[1]
        endif
        if len(l:matches[2]) > 0
            if <SID>CheckVersion(l:operator, l:matches[2]) ? 0 : 1
                return
            endif
        endif
        return <SID>DoNoSetModeline(l:matches[3])
    endif
endfun

fun! <SID>DoModelines() abort
    if line("$") > g:secure_modelines_modelines
        let l:lines={ }
        call map(filter(getline(1, g:secure_modelines_modelines) +
                    \ getline(line("$") - g:secure_modelines_modelines, "$"),
                    \ 'v:val =~ ":"'), 'extend(l:lines, { v:val : 0 } )')
        for l:line in keys(l:lines)
            call <SID>DoModeline(l:line)
        endfor
    else
        for l:line in getline(1, "$")
            call <SID>DoModeline(l:line)
        endfor
    endif
endfun

fun! SecureModelines_DoModelines() abort
    call <SID>DoModelines()
endfun

aug SecureModeLines
    au!
    au BufRead * :call <SID>DoModelines()
aug END


_______________________________________________
freebsd-questions@freebsd.org mailing list
http://lists.freebsd.org/mailman/listinfo/freebsd-questions
To unsubscribe, send any mail to "freebsd-questions-unsubscr...@freebsd.org"

Reply via email to