Other ged dir相对于模块目录

import os.path
template_dir = os.path.join(os.path.dirname(__file__), 'templates').replace('\\', '/')

Other python搜索 - 替换与n个非嵌套组的匹配

import re


def replace(match, withwhat):
    
    starttext = match.group(0)
    n = len(withwhat)
    off = match.start(0)
    
    tmp = starttext
    for i in range(n):
            delta = len(tmp)-len(starttext)
            tmp = tmp[:match.start(i+1)-off+delta ] + withwhat[i](match.group(i+1)) + tmp[match.end(i+1)-off+delta:]
    return tmp
    
#test
funcs = [lambda x: '1'+x+'1',lambda x: '2'+x+'2']
#regex contains 2 capturing groups
print re.sub(regex, lambda x: replace(x, funcs), text)

Other 通用WordPress正文标记

<body id="<?php echo the_slug(); ?>"<?php global $post; if (is_front_page()) {echo ">";} else {?> class="sub">

Other .vimrc中

set nocompatible
set backspace=indent,eol,start
set nobackup
set mouse=a
set confirm

" Windows settings
source $VIMRUNTIME/mswin.vim
behave mswin

" Turn off bells and flashes
set noerrorbells
if has('autocmd')
    autocmd GUIEnter * set vb t_vb=
endif

" Font and color scheme
"set gfn=Consolas:h10:cANSI
set gfn=Inconsolata:h10:cANSI
"colorscheme fruity
colorscheme wombat

" Detect filetype and use syntax highlighting
filetype on
filetype plugin on
syntax on

" Keep a bunch of command line history
set history=1000

" Save swap files centrally if possible
set dir=c:\\temp

" Show the cursor position and line numbers
set ruler
set number

" Show incomplete commands and enable wild menu
set showcmd
set wildmenu
set wildmode=list:longest

" Enable incremental search but don't highlight matches
set incsearch
set nohlsearch

" Key binding F2 to toggle search highlighting
map <silent> <F2> :set invhlsearch<CR>

" Smart case sensitivity
set ignorecase
set smartcase

" Use spaces instead of tabs
set shiftwidth=4
set tabstop=4
set softtabstop=4
set expandtab

"Enabled auto-indenting
set autoindent
set smartindent
filetype plugin indent on

" Hide toolbar and menubar
set guioptions-=T
set guioptions-=m

" Leave some space at the bottom
set scrolloff=2

" Show matching brace
set showmatch

" Use Windows clipboard
set clipboard+=unnamed

" Set default window size
set lines=50 columns=100

" Don't wrap lines
set nowrap

" Speed optimizations
set lz
set ttyfast

" Automatically set current directory to file's location
set autochdir

" Permit changing buffers without saving
set hidden

" Folding
set foldmethod=marker

" Show tabs and trailing spaces so I can remove them
set list
set listchars=tab:»·,trail:·

" Save/Reload session
set sessionoptions=blank,buffers,curdir,folds,help,resize,tabpages,winsize
nmap <silent> <leader>ss <Esc>:mksession! $VIM/.session<CR>
nmap <silent> <leader>ls <Esc>:source $VIM/.session<CR>

" Convenient command to see the difference between the current buffer and the
" file it was loaded from, thus the changes you made.
command DiffOrig vert new | set bt=nofile | r # | 0d_ | diffthis
        \ | wincmd p | diffthis

" NERDTree settings (launch with \nt or \\)
let g:NERDTreeQuitOnOpen = 1
nmap <silent> <leader>nt <Esc>:NERDTreeToggle<CR>
nmap <silent> <leader>\ <Esc>:NERDTreeToggle<CR>

" bufexplorer settings (launch with \be or \])
nmap <silent> <unique> <leader>] <Esc>:BufExplorer<CR>

" Tab navigation
nmap <silent> <C-t> :tabnew<CR>
nmap <silent> <C-j> gT
nmap <silent> <C-k> gt
nmap <silent> <C-h> :tabfirst<CR>
nmap <silent> <C-l> :tablast<CR>
nmap <silent> <leader>ta <Esc>:tab ball<CR>

" Split window navigation
nmap <c-down> <c-w>w
nmap <c-up> <c-w>W
nmap <c-left> <c-w>h
nmap <c-right> <c-w>l

" Undo in Insert mode (CTRL+Z)
map <c-z> <c-o>u

" Remap omni-completion to CTRL+SPACE
inoremap <C-space> <C-x><C-o>

" Most recently used file list settings
let MRU_Max_Entries = 50

" Use SQL Server syntax file for .sql files
let g:sql_type_default = "sqlserver"

" Functions for cleaning up tabs and spaces
function! RemoveTrailingSpaces()
    %s/\s\+$//e
    %s/
//ge
endfunction

function! ConvertTabsToSpaces()
    %retab
endfunction

function! CleanFile()
    call ConvertTabsToSpaces()
    call RemoveTrailingSpaces()
endfunction

" Key binding \f to clean up file
nmap <silent> <leader>f <Esc>:call CleanFile()<CR>

" Format of GUI tab label
function! GuiTabLabel()
    " add the tab number
    let label = '['.tabpagenr()

    " modified since the last save?
    let buflist = tabpagebuflist(v:lnum)
    for bufnr in buflist
        if getbufvar(bufnr, '&modified')
            let label .= '*'
            break
        endif
    endfor

    " count number of open windows in the tab
    let wincount = tabpagewinnr(v:lnum, '$')
    if wincount > 1
        let label .= ', '.wincount
    endif
    let label .= '] '

    " add the file name without path information
    let n = bufname(buflist[tabpagewinnr(v:lnum) - 1])
    let label .= fnamemodify(n, ':t')

    return label
endfunction
set guitablabel=%{GuiTabLabel()}

" C-specific settings
set makeprg=gcc\ -o\ %<\ %
:command -nargs=* Make make <args> | cwindow 3

" Python-specific settings
autocmd BufRead *.py set smartindent cinwords=if,elif,else,for,while,try,except,finally,def,class
autocmd BufWritePre *.py normal m`:%s/\s\+$//e ``
autocmd BufRead *.py set makeprg=python\ -c\ \"import\ py_compile,sys;\ sys.stderr=sys.stdout;\ py_compile.compile(r'%')\"
autocmd BufRead *.py set efm=%C\ %.%#,%A\ \ File\ \"%f\"\\,\ line\ %l%.%#,%Z%[%^\ ]%\\@=%m
autocmd FileType python set omnifunc=pythoncomplete#Complete

" Special functions for debugging/launching Python scripts
" http://www.petersblog.org/node/752
python << EOF
import vim
import string

def SetBreakpoint():
    import re

    nLine = int(vim.eval('line(".")'))

    strLine = vim.current.line
    strWhite = re.search('^(\s*)', strLine).group(1)

    vim.current.buffer.append(
     "%(space)spdb.set_trace() %(mark)s Breakpoint %(mark)s" %
       {'space':strWhite, 'mark': '#' * 30}, nLine - 1)

    for strLine in vim.current.buffer:
        if strLine == "import pdb":
            break
    else:
        vim.current.buffer.append('import pdb', 0)
        vim.command('normal j1')

vim.command('map <f7> :py SetBreakpoint()<cr>')

def RemoveBreakpoints():
    import re

    nCurrentLine = int(vim.eval('line(".")'))

    nLines = []
    nLine = 1
    for strLine in vim.current.buffer:
        if strLine == 'import pdb' or strLine.lstrip()[:15] == 'pdb.set_trace()':
            nLines.append(nLine)
        nLine += 1

    nLines.reverse()

    for nLine in nLines:
        vim.command('normal %dG' % nLine)
        vim.command('normal dd')
        if nLine < nCurrentLine:
            nCurrentLine -= 1

    vim.command('normal %dG' % nCurrentLine)

vim.command('map <s-f7> :py RemoveBreakpoints()<cr>')

def RunDebugger():
    vim.command('wall')
    strFile = vim.eval("g:mainfile")
    winos = vim.eval('has("win32")')
    if string.atoi(winos):
        vim.command("!start python -m pdb %s" % strFile)
    else:
        vim.command("!xterm -e python -m pdb %s&" % strFile)

def RunNormal():
    vim.command('wall')
    strFile = vim.eval('expand("%:p")')
    winos = vim.eval('has("win32")')
    if string.atoi(winos):
        vim.command("!start python %s" % strFile)
    else:
        vim.command("!xterm -e python %s&" % strFile)

def RunNormalInDebugMode():
    vim.command('wall')
    strFile = vim.eval('expand("%:p")')
    winos = vim.eval('has("win32")')
    if string.atoi(winos):
        vim.command("!start python %s --debug-mode" % strFile)
    else:
        vim.command("!xterm -e python %s --debug-mode&" % strFile)

vim.command('map <s-f12> :py RunDebugger()<cr>')
vim.command('map <f5> :py RunNormal()<cr>')
vim.command('map <s-f5> :py RunNormalInDebugMode()<cr>')
EOF

Other 重复上一个Ex命令

@:

Other 重复上一次视觉选择

gv

Other ThunderBoltAS3记录器

import org.osflash.thunderbolt.Logger;

var myNumber: int = 5;
var myString2: String = "Lorem ipsum";
Logger.error ("Logging two objects: A number typed as int and a string", myNumber, myString);

Other 计算文件夹中的文件

find . -type f | wc -l

Other 双宏猎人哇

Macro 1:

#showtooltip Tir assuré
/console Sound_EnableSFX 0
/cast !Tir automatique
/click [target=pettarget,exists] MultiBarBottomLeftButton3
/cast Tir assuré
/console Sound_EnableSFX 1
/script UIErrorsFrame:Clear()

Macro 2:

#showtooltip Ordre de tuer
/cast Souffle de foudre
/castsequence reset=4 Ordre de tuer, !Tir automatique, !Tir automatique, !Tir automatique

Other VCard Hello World

BEGIN:VCARD
VERSION:3.0
N:Mustermann;Hans
FN:Hans Mustermann
ORG:Wikipedia
URL:http://de.wikipedia.org/
EMAIL;TYPE=INTERNET:hans.mustermann@example.org
END:VCARD