Add keypad mappings

Close #147
This commit is contained in:
Kien N 2012-02-24 01:19:44 +07:00
parent 92b8c399dd
commit f0d2ce1be7
4 changed files with 60 additions and 40 deletions

View File

@ -60,10 +60,10 @@ fu! s:opts()
\ 'PrtClear()': ['<c-u>'], \ 'PrtClear()': ['<c-u>'],
\ 'PrtSelectMove("j")': ['<c-j>', '<down>'], \ 'PrtSelectMove("j")': ['<c-j>', '<down>'],
\ 'PrtSelectMove("k")': ['<c-k>', '<up>'], \ 'PrtSelectMove("k")': ['<c-k>', '<up>'],
\ 'PrtSelectMove("t")': ['<home>'], \ 'PrtSelectMove("t")': ['<Home>', '<kHome>'],
\ 'PrtSelectMove("b")': ['<end>'], \ 'PrtSelectMove("b")': ['<End>', '<kEnd>'],
\ 'PrtSelectMove("u")': ['<PageUp>'], \ 'PrtSelectMove("u")': ['<PageUp>', '<kPageUp>'],
\ 'PrtSelectMove("d")': ['<PageDown>'], \ 'PrtSelectMove("d")': ['<PageDown>', '<kPageDown>'],
\ 'PrtHistory(-1)': ['<c-n>'], \ 'PrtHistory(-1)': ['<c-n>'],
\ 'PrtHistory(1)': ['<c-p>'], \ 'PrtHistory(1)': ['<c-p>'],
\ 'AcceptSelection("e")': ['<cr>', '<2-LeftMouse>'], \ 'AcceptSelection("e")': ['<cr>', '<2-LeftMouse>'],
@ -97,22 +97,6 @@ fu! s:opts()
if type(s:urprtmaps) == 4 if type(s:urprtmaps) == 4
cal extend(s:prtmaps, s:urprtmaps) cal extend(s:prtmaps, s:urprtmaps)
en en
let s:prtunmaps = [
\ 'PrtBS()',
\ 'PrtDelete()',
\ 'PrtDeleteWord()',
\ 'PrtClear()',
\ 'PrtCurStart()',
\ 'PrtCurEnd()',
\ 'PrtCurLeft()',
\ 'PrtCurRight()',
\ 'PrtHistory(-1)',
\ 'PrtHistory(1)',
\ 'PrtInsert("w")',
\ 'PrtInsert("s")',
\ 'PrtInsert("v")',
\ 'PrtInsert("+")',
\ ]
" Global options " Global options
let s:glbs = { 'magic': 1, 'to': 1, 'tm': 0, 'sb': 1, 'hls': 0, 'im': 0, let s:glbs = { 'magic': 1, 'to': 1, 'tm': 0, 'sb': 1, 'hls': 0, 'im': 0,
\ 'report': 9999, 'sc': 0, 'ss': 0, 'siso': 0, 'mfd': 200, 'mouse': 'n', \ 'report': 9999, 'sc': 0, 'ss': 0, 'siso': 0, 'mfd': 200, 'mouse': 'n',
@ -136,6 +120,31 @@ let s:fpats = {
\ '^\S\\?$': '\\?', \ '^\S\\?$': '\\?',
\ } \ }
" Mappings
let s:prtunmaps = [
\ 'PrtBS()',
\ 'PrtDelete()',
\ 'PrtDeleteWord()',
\ 'PrtClear()',
\ 'PrtCurStart()',
\ 'PrtCurEnd()',
\ 'PrtCurLeft()',
\ 'PrtCurRight()',
\ 'PrtHistory(-1)',
\ 'PrtHistory(1)',
\ 'PrtInsert("w")',
\ 'PrtInsert("s")',
\ 'PrtInsert("v")',
\ 'PrtInsert("+")',
\ ]
let s:kprange = {
\ 'Plus': '+',
\ 'Minus': '-',
\ 'Divide': '/',
\ 'Multiply': '*',
\ 'Point': '.',
\ }
" Highlight groups " Highlight groups
let s:hlgrps = { let s:hlgrps = {
\ 'NoEntries': 'Error', \ 'NoEntries': 'Error',
@ -361,18 +370,17 @@ endf
fu! s:Render(lines, pat, ipt) fu! s:Render(lines, pat, ipt)
let lines = a:lines let lines = a:lines
" Setup the match window " Setup the match window
let s:height = min([len(lines), s:winh]) let [&ma, s:height] = [1, min([len(lines), s:winh])]
sil! exe '%d _ | res' s:height sil! exe '%d _ | res' s:height
" Print the new items " Print the new items
if empty(lines) if empty(lines)
setl nocul
let s:matched = [] let s:matched = []
cal setline(1, ' == NO ENTRIES ==') cal setline(1, ' == NO ENTRIES ==')
setl noma nocul
cal s:unmarksigns() cal s:unmarksigns()
if s:dohighlight() | cal clearmatches() | en if s:dohighlight() | cal clearmatches() | en
retu retu
en en
setl cul
" Sort if not MRU " Sort if not MRU
if ( s:itemtype != 2 && !exists('g:ctrlp_nolimit') ) if ( s:itemtype != 2 && !exists('g:ctrlp_nolimit') )
\ || !empty(join(s:prompt, '')) \ || !empty(join(s:prompt, ''))
@ -384,6 +392,7 @@ fu! s:Render(lines, pat, ipt)
let s:matched = copy(lines) let s:matched = copy(lines)
cal map(lines, 's:formatline(v:val, a:ipt)') cal map(lines, 's:formatline(v:val, a:ipt)')
cal setline(1, lines) cal setline(1, lines)
setl noma cul
exe 'keepj norm!' ( s:mwreverse ? 'G' : 'gg' ).'1|' exe 'keepj norm!' ( s:mwreverse ? 'G' : 'gg' ).'1|'
cal s:unmarksigns() cal s:unmarksigns()
cal s:remarksigns() cal s:remarksigns()
@ -623,6 +632,13 @@ fu! s:MapKeys(...)
for each in range(32, 126) for each in range(32, 126)
exe printf(cmd, each, pfunc, escape(nr2char(each), '"|\'), dojmp) exe printf(cmd, each, pfunc, escape(nr2char(each), '"|\'), dojmp)
endfo endfo
let kpcmd = substitute(cmd, 'char-%d', 'k%s', '')
for each in range(0, 9)
exe printf(kpcmd, each, pfunc, each, dojmp)
endfo
for [ke, va] in items(s:kprange)
exe printf(kpcmd, ke, pfunc, va, dojmp)
endfo
" Special keys " Special keys
if a:0 < 2 if a:0 < 2
cal call('s:MapSpecs', a:0 && !a:1 ? [1] : []) cal call('s:MapSpecs', a:0 && !a:1 ? [1] : [])
@ -712,8 +728,8 @@ fu! s:SetWD(...) "{{{1
unl! s:foundroot unl! s:foundroot
endf endf
" * AcceptSelection() {{{1 " * AcceptSelection() {{{1
fu! ctrlp#acceptfile(mode, matchstr, ...) fu! ctrlp#acceptfile(mode, line, ...)
let [md, filpath] = [a:mode, fnamemodify(a:matchstr, ':p')] let [md, filpath] = [a:mode, fnamemodify(a:line, ':p')]
cal s:PrtExit() cal s:PrtExit()
let [bufnr, tail] = [bufnr('^'.filpath.'$'), s:tail()] let [bufnr, tail] = [bufnr('^'.filpath.'$'), s:tail()]
let j2l = a:0 ? a:1 : str2nr(matchstr(tail, '^ +\D*\zs\d\+\ze\D*')) let j2l = a:0 ? a:1 : str2nr(matchstr(tail, '^ +\D*\zs\d\+\ze\D*'))
@ -976,7 +992,7 @@ fu! ctrlp#statusline()
let focus = s:Focus() ? 'prt' : 'win' let focus = s:Focus() ? 'prt' : 'win'
let byfname = s:byfname ? 'file' : 'path' let byfname = s:byfname ? 'file' : 'path'
let marked = s:opmul != '0' ? let marked = s:opmul != '0' ?
\ exists('s:marked') ? ' <'.s:dismrk().'>' : ' <>' : '' \ exists('s:marked') ? ' <'.s:dismrk().'>' : ' <->' : ''
if has_key(s:status, 'main') if has_key(s:status, 'main')
let args = [focus, byfname, s:regexp, prv, item, nxt, marked] let args = [focus, byfname, s:regexp, prv, item, nxt, marked]
let &l:stl = call(s:status['main'], args) let &l:stl = call(s:status['main'], args)
@ -1004,8 +1020,8 @@ fu! ctrlp#progress(enum)
endf endf
" Paths {{{2 " Paths {{{2
fu! s:formatline(str, ipt) fu! s:formatline(str, ipt)
retu '> '.( a:ipt && ( s:winw - ( s:dosigns() ? 2 : 0 ) - 2 ) let cond = a:ipt && ( s:winw - 4 ) < s:strwidth(a:str)
\ < s:strwidth(a:str) ? pathshorten(a:str) : a:str ) retu '> '.( cond ? pathshorten(a:str) : a:str )
endf endf
fu! s:dircompl(be, sd) fu! s:dircompl(be, sd)

View File

@ -165,10 +165,9 @@ only need to keep the lines that youve changed the values (inside []): >
< <
Note: In some terminals, its not possible to remap <c-h> without also changing Note: In some terminals, its not possible to remap <c-h> without also changing
<bs> (|key-codes|). So if pressing <bs> moves the cursor to the left instead of <bs> (|key-codes|). So if pressing <bs> moves the cursor to the left instead of
deleting a char for you, add this to your |vimrc| to change the default <c-h> deleting a char for you, add this to your |vimrc| to disable the default <c-h>
mapping: > mapping: >
let g:ctrlp_prompt_mappings = { let g:ctrlp_prompt_mappings = {
\ 'PrtBS()': ['<bs>', '<c-]>', '<c-h>'],
\ 'PrtCurLeft()': ['<left>', '<c-^>'], \ 'PrtCurLeft()': ['<left>', '<c-^>'],
\ } \ }
< <
@ -213,7 +212,7 @@ Set to 1 to sort the MRU file list to most-recently-entered-buffer order: >
< <
*'g:ctrlp_dotfiles'* *'g:ctrlp_dotfiles'*
Set this to 0 if you dont want |CtrlP| to search for dotfiles and dotdirs: > Set this to 0 if you dont want |CtrlP| to scan for dotfiles and dotdirs: >
let g:ctrlp_dotfiles = 1 let g:ctrlp_dotfiles = 1
< <
You can use |'wildignore'| to exclude anything from the search. You can use |'wildignore'| to exclude anything from the search.
@ -762,6 +761,8 @@ Special thanks:~
=============================================================================== ===============================================================================
CHANGELOG *ctrlp-changelog* CHANGELOG *ctrlp-changelog*
Before 2012/03/01~
+ New option: |g:ctrlp_mruf_last_entered| change MRU to recently-entered. + New option: |g:ctrlp_mruf_last_entered| change MRU to recently-entered.
+ Extend |g:ctrlp_user_command| to support multiple commands. + Extend |g:ctrlp_user_command| to support multiple commands.
@ -854,7 +855,7 @@ Before 2011/09/12~
|g:ctrlp_mruf_max|, |g:ctrlp_mruf_max|,
|g:ctrlp_mruf_exclude|, |g:ctrlp_mruf_exclude|,
|g:ctrlp_mruf_include| |g:ctrlp_mruf_include|
+ New command: |:CtrlPMRUFiles| + New command: |:CtrlPMRU|
First public release: 2011/09/06~ First public release: 2011/09/06~

View File

@ -26,7 +26,7 @@ com! CtrlPCurWD cal ctrlp#init(0, 0)
com! CtrlPCurFile cal ctrlp#init(0, 1) com! CtrlPCurFile cal ctrlp#init(0, 1)
com! CtrlPRoot cal ctrlp#init(0, 2) com! CtrlPRoot cal ctrlp#init(0, 2)
if g:ctrlp_map != '' if g:ctrlp_map != '' && !hasmapto(':<c-u>'.g:ctrlp_cmd.'<cr>', 'n')
exe 'nn <silent>' g:ctrlp_map ':<c-u>'.g:ctrlp_cmd.'<cr>' exe 'nn <silent>' g:ctrlp_map ':<c-u>'.g:ctrlp_cmd.'<cr>'
en en

View File

@ -16,14 +16,17 @@ Full path fuzzy __file__, __buffer__, __mru__ and __tag__ finder for Vim.
Once CtrlP is open: Once CtrlP is open:
* Press `<c-f>` and `<c-b>` to switch between find file, buffer, and MRU file modes. * Press `<c-f>` and `<c-b>` to switch between find file, buffer, and MRU file
modes.
* Press `<c-d>` to switch to filename only search instead of full path. * Press `<c-d>` to switch to filename only search instead of full path.
* Press `<F5>` to purge the cache for the current directory and get new files. * Press `<F5>` to purge the cache for the current directory and get new files.
* Use `*` or `|` in the prompt to submit the string as a Vims regexp pattern. * Use `*` or `|` in the prompt to submit the string as a Vims regexp pattern.
* Or press `<c-r>` to switch to regexp mode. * Or press `<c-r>` to switch to regexp mode.
* End the input string with a colon `:` followed by a command to execute after opening the file. * End the input string with a colon `:` followed by a command to execute after
opening the file.
e.g. `abc:45` will open the file matched the pattern and jump to line 45. e.g. `abc:45` will open the file matched the pattern and jump to line 45.
* Submit two dots `..` as the input string to go backward the directory tree by 1 level. * Submit two dots `..` as the input string to go backward the directory tree by
1 level.
* Use `<c-y>` to create a new file and its parent dirs. * Use `<c-y>` to create a new file and its parent dirs.
* Use `<c-z>` to mark/unmark files and `<c-o>` to open them. * Use `<c-z>` to mark/unmark files and `<c-o>` to open them.
@ -34,7 +37,8 @@ e.g. `abc:45` will open the file matched the pattern and jump to line 45.
let g:ctrlp_map = '<c-p>' let g:ctrlp_map = '<c-p>'
``` ```
* When CtrlP is invoked, it automatically sets the working directory according to this variable: * When CtrlP is invoked, it automatically sets its local working directory
according to this variable:
```vim ```vim
let g:ctrlp_working_path_mode = 2 let g:ctrlp_working_path_mode = 2
@ -48,10 +52,9 @@ e.g. `abc:45` will open the file matched the pattern and jump to line 45.
.hg/ .hg/
.bzr/ .bzr/
_darcs/ _darcs/
root.dir
* If you want to exclude directories or files from the search, you can use the Vims option `wildignore` * If you want to exclude directories or files from the search, you can use the
and/or the option `g:ctrlp_custom_ignore`. Examples: Vims option `wildignore` and/or the option `g:ctrlp_custom_ignore`. Examples:
```vim ```vim
set wildignore+=*/.git/*,*/.hg/*,*/.svn/* " for Linux/MacOSX set wildignore+=*/.git/*,*/.hg/*,*/.svn/* " for Linux/MacOSX