Skip to content
Browse files

Updated command-t.vim

  • Loading branch information...
1 parent 40f02d9 commit c00368430ad88c76fa91d6917a7fb02071c89b6d @arthurgeek committed Jan 17, 2012
View
255 doc/command-t.txt
@@ -21,9 +21,9 @@ CONTENTS *command-t-contents*
INTRODUCTION *command-t-intro*
The Command-T plug-in provides an extremely fast, intuitive mechanism for
-opening files with a minimal number of keystrokes. It's named "Command-T"
-because it is inspired by the "Go to File" window bound to Command-T in
-TextMate.
+opening files and buffers with a minimal number of keystrokes. It's named
+"Command-T" because it is inspired by the "Go to File" window bound to
+Command-T in TextMate.
Files are selected by typing characters that appear in their paths, and are
ordered by an algorithm which knows that characters that appear in certain
@@ -240,17 +240,17 @@ you eliminate the discrepancy.
USAGE *command-t-usage*
-Bring up the Command-T match window by typing:
+Bring up the Command-T file window by typing:
<Leader>t
This mapping is set up automatically for you, provided you do not already have
-a mapping for <Leader>t or |:CommandT|. You can also bring up the match window
+a mapping for <Leader>t or |:CommandT|. You can also bring up the file window
by issuing the command:
:CommandT
-A prompt will appear at the bottom of the screen along with a match window
+A prompt will appear at the bottom of the screen along with a file window
showing all of the files in the current directory (as returned by the
|:pwd| command).
@@ -284,36 +284,36 @@ The following mappings are active when the prompt has focus:
<C-a> move the cursor to the start (left)
<C-e> move the cursor to the end (right)
<C-u> clear the contents of the prompt
- <Tab> change focus to the match listing
+ <Tab> change focus to the file listing
-The following mappings are active when the match listing has focus:
+The following mappings are active when the file listing has focus:
<Tab> change focus to the prompt
-The following mappings are active when either the prompt or the match listing
+The following mappings are active when either the prompt or the file listing
has focus:
<CR> open the selected file
<C-CR> open the selected file in a new split window
<C-s> open the selected file in a new split window
<C-v> open the selected file in a new vertical split window
<C-t> open the selected file in a new tab
- <C-j> select next file in the match listing
- <C-n> select next file in the match listing
- <Down> select next file in the match listing
- <C-k> select previous file in the match listing
- <C-p> select previous file in the match listing
- <Up> select previous file in the match listing
- <C-c> cancel (dismisses match listing)
+ <C-j> select next file in the file listing
+ <C-n> select next file in the file listing
+ <Down> select next file in the file listing
+ <C-k> select previous file in the file listing
+ <C-p> select previous file in the file listing
+ <Up> select previous file in the file listing
+ <C-c> cancel (dismisses file listing)
The following is also available on terminals which support it:
- <Esc> cancel (dismisses match listing)
+ <Esc> cancel (dismisses file listing)
Note that the default mappings can be overriden by setting options in your
~/.vimrc file (see the OPTIONS section for a full list of available options).
-In addition, when the match listing has focus, typing a character will cause
+In addition, when the file listing has focus, typing a character will cause
the selection to jump to the first path which begins with that character.
Typing multiple characters consecutively can be used to distinguish between
paths which begin with the same prefix.
@@ -322,31 +322,47 @@ paths which begin with the same prefix.
COMMANDS *command-t-commands*
*:CommandT*
-|:CommandT| Brings up the Command-T match window, starting in the
+|:CommandT| Brings up the Command-T file window, starting in the
current working directory as returned by the|:pwd|
command.
+ *:CommandTBuffer*
+|:CommandTBuffer|Brings up the Command-T buffer window.
+ This works exactly like the standard file window,
+ except that the selection is limited to files that
+ you already have open in buffers.
+
+ *:CommandTJumps*
+|:CommandTJump| Brings up the Command-T jumplist window.
+ This works exactly like the standard file window,
+ except that the selection is limited to files that
+ you already have in the jumplist. Note that jumps
+ can persist across Vim sessions (see Vim's |jumplist|
+ documentation for more info).
+
*:CommandTFlush*
|:CommandTFlush|Instructs the plug-in to flush its path cache, causing
the directory to be rescanned for new or deleted paths
- the next time the match window is shown. In addition, all
+ the next time the file window is shown. In addition, all
configuration settings are re-evaluated, causing any
changes made to settings via the |:let| command to be picked
up.
MAPPINGS *command-t-mappings*
-By default Command-T comes with only one mapping:
+By default Command-T comes with only two mappings:
- <Leader>t bring up the Command-T match window
+ <Leader>t bring up the Command-T file window
+ <Leader>b bring up the Command-T buffer window
However, Command-T won't overwrite a pre-existing mapping so if you prefer
-to define a different mapping use a line like this in your ~/.vimrc:
+to define different mappings use lines like these in your ~/.vimrc:
- nmap <silent> <Leader>t :CommandT<CR>
+ nnoremap <silent> <Leader>t :CommandT<CR>
+ nnoremap <silent> <Leader>b :CommandTBuffer<CR>
-Replacing "<Leader>t" with your mapping of choice.
+Replacing "<Leader>t" or "<Leader>b" with your mapping of choice.
Note that in the case of MacVim you actually can map to Command-T (written
as <D-t> in Vim) in your ~/.gvimrc file if you first unmap the existing menu
@@ -376,46 +392,64 @@ changes via |:let|.
Following is a list of all available options:
- *g:CommandTMaxFiles*
+ *g:CommandTMaxFiles*
|g:CommandTMaxFiles| number (default 10000)
The maximum number of files that will be considered when scanning the
- current directory. Upon reaching this number scanning stops.
+ current directory. Upon reaching this number scanning stops. This
+ limit applies only to file listings and is ignored for buffer
+ listings.
- *g:CommandTMaxDepth*
+ *g:CommandTMaxDepth*
|g:CommandTMaxDepth| number (default 15)
The maximum depth (levels of recursion) to be explored when scanning the
current directory. Any directories at levels beyond this depth will be
skipped.
- *g:CommandTMaxHeight*
+ *g:CommandTMaxCachedDirectories*
+ |g:CommandTMaxCachedDirectories| number (default 1)
+
+ The maximum number of directories whose contents should be cached when
+ recursively scanning. With the default value of 1, each time you change
+ directories the cache will be emptied and Command-T will have to
+ rescan. Higher values will make Command-T hold more directories in the
+ cache, bringing performance at the cost of memory usage. If set to 0,
+ there is no limit on the number of cached directories.
+
+ *g:CommandTMaxHeight*
|g:CommandTMaxHeight| number (default: 0)
The maximum height in lines the match window is allowed to expand to.
If set to 0, the window will occupy as much of the available space as
needed to show matching entries.
- *g:CommandTAlwaysShowDotFiles*
+ *g:CommandTAlwaysShowDotFiles*
|g:CommandTAlwaysShowDotFiles| boolean (default: 0)
- By default Command-T will show dot-files only if the entered search
- string contains a dot that could cause a dot-file to match. When set to
- a non-zero value, this setting instructs Command-T to always include
- matching dot-files in the match list regardless of whether the search
- string contains a dot. See also |g:CommandTNeverShowDotFiles|.
+ When showing the file listing Command-T will by default show dot-files
+ only if the entered search string contains a dot that could cause a
+ dot-file to match. When set to a non-zero value, this setting instructs
+ Command-T to always include matching dot-files in the match list
+ regardless of whether the search string contains a dot. See also
+ |g:CommandTNeverShowDotFiles|. Note that this setting only influences
+ the file listing; the buffer listing treats dot-files like any other
+ file.
- *g:CommandTNeverShowDotFiles*
+ *g:CommandTNeverShowDotFiles*
|g:CommandTNeverShowDotFiles| boolean (default: 0)
- By default Command-T will show dot-files if the entered search string
- contains a dot that could cause a dot-file to match. When set to a
- non-zero value, this setting instructs Command-T to never show dot-files
- under any circumstances. Note that it is contradictory to set both this
- setting and |g:CommandTAlwaysShowDotFiles| to true, and if you do so Vim
- will suffer from headaches, nervous twitches, and sudden mood swings.
-
- *g:CommandTScanDotDirectories*
+ In the file listing, Command-T will by default show dot-files if the
+ entered search string contains a dot that could cause a dot-file to
+ match. When set to a non-zero value, this setting instructs Command-T to
+ never show dot-files under any circumstances. Note that it is
+ contradictory to set both this setting and
+ |g:CommandTAlwaysShowDotFiles| to true, and if you do so Vim will suffer
+ from headaches, nervous twitches, and sudden mood swings. This setting
+ has no effect in buffer listings, where dot files are treated like any
+ other file.
+
+ *g:CommandTScanDotDirectories*
|g:CommandTScanDotDirectories| boolean (default: 0)
Normally Command-T will not recurse into "dot-directories" (directories
@@ -427,23 +461,33 @@ Following is a list of all available options:
(after scanning has been performed), whereas
|g:CommandTScanDotDirectories| affects the behaviour at scan-time.
- Note also that even with this setting on you can still use Command-T to
+ Note also that even with this setting off you can still use Command-T to
open files inside a "dot-directory" such as ~/.vim, but you have to use
the |:cd| command to change into that directory first. For example:
:cd ~/.vim
:CommandT
- *g:CommandTMatchWindowAtTop*
+ *g:CommandTMatchWindowAtTop*
|g:CommandTMatchWindowAtTop| boolean (default: 0)
- When this settings is off (the default) the match window will appear at
+ When this setting is off (the default) the match window will appear at
the bottom so as to keep it near to the prompt. Turning it on causes the
match window to appear at the top instead. This may be preferable if you
want the best match (usually the first one) to appear in a fixed location
on the screen rather than moving as the number of matches changes during
typing.
+ *g:CommandTMatchWindowReverse*
+ |g:CommandTMatchWindowReverse| boolean (default: 0)
+
+ When this setting is off (the default) the matches will appear from
+ top to bottom with the topmost being selected. Turning it on causes the
+ matches to be reversed so the best match is at the bottom and the
+ initially selected match is the bottom most. This may be preferable if
+ you want the best match to appear in a fixed location on the screen
+ but still be near the prompt at the bottom.
+
As well as the basic options listed above, there are a number of settings that
can be used to override the default key mappings used by Command-T. For
example, to set <C-x> as the mapping for cancelling (dismissing) the Command-T
@@ -459,63 +503,63 @@ Following is a list of all map settings and their defaults:
Setting Default mapping(s)
- *g:CommandTBackspaceMap*
+ *g:CommandTBackspaceMap*
|g:CommandTBackspaceMap| <BS>
- *g:CommandTDeleteMap*
+ *g:CommandTDeleteMap*
|g:CommandTDeleteMap| <Del>
- *g:CommandTAcceptSelectionMap*
+ *g:CommandTAcceptSelectionMap*
|g:CommandTAcceptSelectionMap| <CR>
- *g:CommandTAcceptSelectionSplitMap*
+ *g:CommandTAcceptSelectionSplitMap*
|g:CommandTAcceptSelectionSplitMap| <C-CR>
- <C-s>
+ <C-s>
- *g:CommandTAcceptSelectionTabMap*
+ *g:CommandTAcceptSelectionTabMap*
|g:CommandTAcceptSelectionTabMap| <C-t>
- *g:CommandTAcceptSelectionVSplitMap*
+ *g:CommandTAcceptSelectionVSplitMap*
|g:CommandTAcceptSelectionVSplitMap| <C-v>
- *g:CommandTToggleFocusMap*
+ *g:CommandTToggleFocusMap*
|g:CommandTToggleFocusMap| <Tab>
- *g:CommandTCancelMap*
+ *g:CommandTCancelMap*
|g:CommandTCancelMap| <C-c>
- <Esc> (not on all terminals)
+ <Esc> (not on all terminals)
- *g:CommandTSelectNextMap*
+ *g:CommandTSelectNextMap*
|g:CommandTSelectNextMap| <C-n>
- <C-j>
- <Down>
+ <C-j>
+ <Down>
- *g:CommandTSelectPrevMap*
+ *g:CommandTSelectPrevMap*
|g:CommandTSelectPrevMap| <C-p>
- <C-k>
- <Up>
+ <C-k>
+ <Up>
- *g:CommandTClearMap*
+ *g:CommandTClearMap*
|g:CommandTClearMap| <C-u>
- *g:CommandTCursorLeftMap*
+ *g:CommandTCursorLeftMap*
|g:CommandTCursorLeftMap| <Left>
- <C-h>
+ <C-h>
- *g:CommandTCursorRightMap*
+ *g:CommandTCursorRightMap*
|g:CommandTCursorRightMap| <Right>
- <C-l>
+ <C-l>
- *g:CommandTCursorEndMap*
+ *g:CommandTCursorEndMap*
|g:CommandTCursorEndMap| <C-e>
- *g:CommandTCursorStartMap*
+ *g:CommandTCursorStartMap*
|g:CommandTCursorStartMap| <C-a>
In addition to the options provided by Command-T itself, some of Vim's own
settings can be used to control behavior:
- *command-t-wildignore*
+ *command-t-wildignore*
|'wildignore'| string (default: '')
Vim's |'wildignore'| setting is used to determine which files should be
@@ -539,10 +583,17 @@ Command-T is written and maintained by Wincent Colaiuta <win@wincent.com>.
Other contributors that have submitted patches include (in alphabetical
order):
+ Anthony Panozzo
+ Daniel Hahler
Lucas de Vries
+ Marian Schubert
+ Matthew Todd
Mike Lundy
Scott Bronson
+ Steven Moazami
Sung Pae
+ Victor Hugo Borja
+ Woody Peterson
Zak Johnson
As this was the first Vim plug-in I had ever written I was heavily influenced
@@ -571,7 +622,7 @@ The latest release will always be available from there.
Development in progress can be inspected via the project's Git repository
browser at:
- http://git.wincent.com/command-t.git
+ https://wincent.com/repos/command-t
A copy of each release is also available from the official Vim scripts site
at:
@@ -594,7 +645,7 @@ PayPal to win@wincent.com:
LICENSE *command-t-license*
-Copyright 2010 Wincent Colaiuta. All rights reserved.
+Copyright 2010-2011 Wincent Colaiuta. All rights reserved.
Redistribution and use in source and binary forms, with or without
modification, are permitted provided that the following conditions are met:
@@ -617,9 +668,65 @@ CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
POSSIBILITY OF SUCH DAMAGE.
-
HISTORY *command-t-history*
+1.3.1 (18 December 2011)
+
+- fix jumplist navigation under Ruby 1.9.x (patch from Woody Peterson)
+
+1.3 (27 November 2011)
+
+- added the option to maintain multiple caches when changing among
+ directories; see the accompanying |g:CommandTMaxCachedDirectories| setting
+- added the ability to navigate using the Vim jumplist (patch from Marian
+ Schubert)
+
+1.2.1 (30 April 2011)
+
+- Remove duplicate copy of the documentation that was causing "Duplicate tag"
+ errors
+- Mitigate issue with distracting blinking cursor in non-GUI versions of Vim
+ (patch from Steven Moazami)
+
+1.2 (30 April 2011)
+
+- added |g:CommandTMatchWindowReverse| option, to reverse the order of items
+ in the match listing (patch from Steven Moazami)
+
+1.1b2 (26 March 2011)
+
+- fix a glitch in the release process; the plugin itself is unchanged since
+ 1.1b
+
+1.1b (26 March 2011)
+
+- add |:CommandTBuffer| command for quickly selecting among open buffers
+
+1.0.1 (5 January 2011)
+
+- work around bug when mapping |:CommandTFlush|, wherein the default mapping
+ for |:CommandT| would not be set up
+- clean up when leaving the Command-T buffer via unexpected means (such as
+ with <C-W k> or similar)
+
+1.0 (26 November 2010)
+
+- make relative path simplification work on Windows
+
+1.0b (5 November 2010)
+
+- work around platform-specific Vim 7.3 bug seen by some users (wherein
+ Vim always falsely reports to Ruby that the buffer numbers is 0)
+- re-use the buffer that is used to show the match listing, rather than
+ throwing it away and recreating it each time Command-T is shown; this
+ stops the buffer numbers from creeping up needlessly
+
+0.9 (8 October 2010)
+
+- use relative paths when opening files inside the current working directory
+ in order to keep buffer listings as brief as possible (patch from Matthew
+ Todd)
+
0.8.1 (14 September 2010)
- fix mapping issues for users who have set |'notimeout'| (patch from Sung
View
71 doc/tags
@@ -44,7 +44,9 @@
:AcpLock acp.txt /*:AcpLock*
:AcpUnlock acp.txt /*:AcpUnlock*
:CommandT command-t.txt /*:CommandT*
+:CommandTBuffer command-t.txt /*:CommandTBuffer*
:CommandTFlush command-t.txt /*:CommandTFlush*
+:CommandTJumps command-t.txt /*:CommandTJumps*
:LAck ack.txt /*:LAck*
:LAckAdd ack.txt /*:LAckAdd*
:MatchDebug matchit.txt /*:MatchDebug*
@@ -74,12 +76,12 @@ NERDComComment NERD_commenter.txt /*NERDComComment*
NERDComCredits NERD_commenter.txt /*NERDComCredits*
NERDComDefaultDelims NERD_commenter.txt /*NERDComDefaultDelims*
NERDComEOLComment NERD_commenter.txt /*NERDComEOLComment*
-NERDComFiletypes NERD_commenter.txt /*NERDComFiletypes*
NERDComFunctionality NERD_commenter.txt /*NERDComFunctionality*
NERDComFunctionalityDetails NERD_commenter.txt /*NERDComFunctionalityDetails*
NERDComFunctionalitySummary NERD_commenter.txt /*NERDComFunctionalitySummary*
NERDComHeuristics NERD_commenter.txt /*NERDComHeuristics*
NERDComInsertComment NERD_commenter.txt /*NERDComInsertComment*
+NERDComInstallation NERD_commenter.txt /*NERDComInstallation*
NERDComInvertComment NERD_commenter.txt /*NERDComInvertComment*
NERDComIssues NERD_commenter.txt /*NERDComIssues*
NERDComLicense NERD_commenter.txt /*NERDComLicense*
@@ -191,6 +193,52 @@ command-t.txt command-t.txt /*command-t.txt*
config/rails.vim rails.txt /*config\/rails.vim*
cs surround.txt /*cs*
ds surround.txt /*ds*
+ft-ruby-omni ft-ruby-omni.txt /*ft-ruby-omni*
+ft-ruby-syntax ft-ruby-syntax.txt /*ft-ruby-syntax*
+fugitive fugitive.txt /*fugitive*
+fugitive#statusline() fugitive.txt /*fugitive#statusline()*
+fugitive-:Gblame fugitive.txt /*fugitive-:Gblame*
+fugitive-:Gbrowse fugitive.txt /*fugitive-:Gbrowse*
+fugitive-:Gcd fugitive.txt /*fugitive-:Gcd*
+fugitive-:Gcommit fugitive.txt /*fugitive-:Gcommit*
+fugitive-:Gdiff fugitive.txt /*fugitive-:Gdiff*
+fugitive-:Ge fugitive.txt /*fugitive-:Ge*
+fugitive-:Gedit fugitive.txt /*fugitive-:Gedit*
+fugitive-:Ggrep fugitive.txt /*fugitive-:Ggrep*
+fugitive-:Git fugitive.txt /*fugitive-:Git*
+fugitive-:Git! fugitive.txt /*fugitive-:Git!*
+fugitive-:Glcd fugitive.txt /*fugitive-:Glcd*
+fugitive-:Glog fugitive.txt /*fugitive-:Glog*
+fugitive-:Gmove fugitive.txt /*fugitive-:Gmove*
+fugitive-:Gpedit fugitive.txt /*fugitive-:Gpedit*
+fugitive-:Gpedit! fugitive.txt /*fugitive-:Gpedit!*
+fugitive-:Gread fugitive.txt /*fugitive-:Gread*
+fugitive-:Gread! fugitive.txt /*fugitive-:Gread!*
+fugitive-:Gremove fugitive.txt /*fugitive-:Gremove*
+fugitive-:Gsdiff fugitive.txt /*fugitive-:Gsdiff*
+fugitive-:Gsplit fugitive.txt /*fugitive-:Gsplit*
+fugitive-:Gsplit! fugitive.txt /*fugitive-:Gsplit!*
+fugitive-:Gstatus fugitive.txt /*fugitive-:Gstatus*
+fugitive-:Gtabedit fugitive.txt /*fugitive-:Gtabedit*
+fugitive-:Gtabedit! fugitive.txt /*fugitive-:Gtabedit!*
+fugitive-:Gvdiff fugitive.txt /*fugitive-:Gvdiff*
+fugitive-:Gvsplit fugitive.txt /*fugitive-:Gvsplit*
+fugitive-:Gvsplit! fugitive.txt /*fugitive-:Gvsplit!*
+fugitive-:Gwq fugitive.txt /*fugitive-:Gwq*
+fugitive-:Gwrite fugitive.txt /*fugitive-:Gwrite*
+fugitive-<CR> fugitive.txt /*fugitive-<CR>*
+fugitive-C fugitive.txt /*fugitive-C*
+fugitive-O fugitive.txt /*fugitive-O*
+fugitive-P fugitive.txt /*fugitive-P*
+fugitive-a fugitive.txt /*fugitive-a*
+fugitive-about fugitive.txt /*fugitive-about*
+fugitive-commands fugitive.txt /*fugitive-commands*
+fugitive-mappings fugitive.txt /*fugitive-mappings*
+fugitive-o fugitive.txt /*fugitive-o*
+fugitive-revision fugitive.txt /*fugitive-revision*
+fugitive-statusline fugitive.txt /*fugitive-statusline*
+fugitive-~ fugitive.txt /*fugitive-~*
+fugitive.txt fugitive.txt /*fugitive.txt*
g% matchit.txt /*g%*
g:CommandTAcceptSelectionMap command-t.txt /*g:CommandTAcceptSelectionMap*
g:CommandTAcceptSelectionSplitMap command-t.txt /*g:CommandTAcceptSelectionSplitMap*
@@ -206,6 +254,8 @@ g:CommandTCursorRightMap command-t.txt /*g:CommandTCursorRightMap*
g:CommandTCursorStartMap command-t.txt /*g:CommandTCursorStartMap*
g:CommandTDeleteMap command-t.txt /*g:CommandTDeleteMap*
g:CommandTMatchWindowAtTop command-t.txt /*g:CommandTMatchWindowAtTop*
+g:CommandTMatchWindowReverse command-t.txt /*g:CommandTMatchWindowReverse*
+g:CommandTMaxCachedDirectories command-t.txt /*g:CommandTMaxCachedDirectories*
g:CommandTMaxDepth command-t.txt /*g:CommandTMaxDepth*
g:CommandTMaxFiles command-t.txt /*g:CommandTMaxFiles*
g:CommandTMaxHeight command-t.txt /*g:CommandTMaxHeight*
@@ -240,9 +290,11 @@ g:acp_completeoptPreview acp.txt /*g:acp_completeoptPreview*
g:acp_enableAtStartup acp.txt /*g:acp_enableAtStartup*
g:acp_ignorecaseOption acp.txt /*g:acp_ignorecaseOption*
g:acp_mappingDriven acp.txt /*g:acp_mappingDriven*
+g:bufExplorerChgWin bufexplorer.txt /*g:bufExplorerChgWin*
g:bufExplorerDefaultHelp bufexplorer.txt /*g:bufExplorerDefaultHelp*
g:bufExplorerDetailedHelp bufexplorer.txt /*g:bufExplorerDetailedHelp*
g:bufExplorerFindActive bufexplorer.txt /*g:bufExplorerFindActive*
+g:bufExplorerFuncRef bufexplorer.txt /*g:bufExplorerFuncRef*
g:bufExplorerReverseSort bufexplorer.txt /*g:bufExplorerReverseSort*
g:bufExplorerShowDirectories bufexplorer.txt /*g:bufExplorerShowDirectories*
g:bufExplorerShowRelativePath bufexplorer.txt /*g:bufExplorerShowRelativePath*
@@ -261,7 +313,6 @@ g:rails_history_size rails.txt /*g:rails_history_size*
g:rails_mappings rails.txt /*g:rails_mappings*
g:rails_menu rails.txt /*g:rails_menu*
g:rails_modelines rails.txt /*g:rails_modelines*
-g:rails_statusline rails.txt /*g:rails_statusline*
g:rails_syntax rails.txt /*g:rails_syntax*
g:rails_tabstop rails.txt /*g:rails_tabstop*
g:rails_url rails.txt /*g:rails_url*
@@ -311,8 +362,6 @@ rails-'pa' rails.txt /*rails-'pa'*
rails-'path' rails.txt /*rails-'path'*
rails-'shiftwidth' rails.txt /*rails-'shiftwidth'*
rails-'softtabstop' rails.txt /*rails-'softtabstop'*
-rails-'statusline' rails.txt /*rails-'statusline'*
-rails-'stl' rails.txt /*rails-'stl'*
rails-'sts' rails.txt /*rails-'sts'*
rails-'sua' rails.txt /*rails-'sua'*
rails-'suffixesadd' rails.txt /*rails-'suffixesadd'*
@@ -372,10 +421,10 @@ rails-:Rplugin rails.txt /*rails-:Rplugin*
rails-:Rpp rails.txt /*rails-:Rpp*
rails-:Rpreview rails.txt /*rails-:Rpreview*
rails-:Rpreview! rails.txt /*rails-:Rpreview!*
-rails-:Rproject rails.txt /*rails-:Rproject*
rails-:Rrefresh rails.txt /*rails-:Rrefresh*
rails-:Rrefresh! rails.txt /*rails-:Rrefresh!*
rails-:Rrunner rails.txt /*rails-:Rrunner*
+rails-:Rschema rails.txt /*rails-:Rschema*
rails-:Rscript rails.txt /*rails-:Rscript*
rails-:Rserver rails.txt /*rails-:Rserver*
rails-:Rserver! rails.txt /*rails-:Rserver!*
@@ -397,14 +446,11 @@ rails-alternate-related rails.txt /*rails-alternate-related*
rails-autocommands rails.txt /*rails-autocommands*
rails-commands rails.txt /*rails-commands*
rails-configuration rails.txt /*rails-configuration*
-rails-configure-vim rails.txt /*rails-configure-vim*
rails-cream rails.txt /*rails-cream*
rails-custom-navigation rails.txt /*rails-custom-navigation*
rails-dbext rails.txt /*rails-dbext*
rails-gf rails.txt /*rails-gf*
rails-global-settings rails.txt /*rails-global-settings*
-rails-install-plugin rails.txt /*rails-install-plugin*
-rails-installation rails.txt /*rails-installation*
rails-integration rails.txt /*rails-integration*
rails-introduction rails.txt /*rails-introduction*
rails-license rails.txt /*rails-license*
@@ -436,8 +482,14 @@ rails-template-types rails.txt /*rails-template-types*
rails-type-navigation rails.txt /*rails-type-navigation*
rails-vim-integration rails.txt /*rails-vim-integration*
rails.txt rails.txt /*rails.txt*
+ruby.vim ft-ruby-syntax.txt /*ruby.vim*
+rubyrefactoring rubyrefactoring.txt /*rubyrefactoring*
+rubyrefactoring-author rubyrefactoring.txt /*rubyrefactoring-author*
+rubyrefactoring-commands rubyrefactoring.txt /*rubyrefactoring-commands*
+rubyrefactoring-mappings rubyrefactoring.txt /*rubyrefactoring-mappings*
+rubyrefactoring-usageexamples rubyrefactoring.txt /*rubyrefactoring-usageexamples*
+rubyrefactoring.txt rubyrefactoring.txt /*rubyrefactoring.txt*
surround surround.txt /*surround*
-surround-author surround.txt /*surround-author*
surround-customizing surround.txt /*surround-customizing*
surround-issues surround.txt /*surround-issues*
surround-mappings surround.txt /*surround-mappings*
@@ -467,7 +519,6 @@ v_]% matchit.txt /*v_]%*
v_a% matchit.txt /*v_a%*
v_g% matchit.txt /*v_g%*
vgS surround.txt /*vgS*
-vs surround.txt /*vs*
yS surround.txt /*yS*
ySS surround.txt /*ySS*
yankring yankring.txt /*yankring*
View
34 plugin/command-t.vim
@@ -1,5 +1,5 @@
" command-t.vim
-" Copyright 2010 Wincent Colaiuta. All rights reserved.
+" Copyright 2010-2011 Wincent Colaiuta. All rights reserved.
"
" Redistribution and use in source and binary forms, with or without
" modification, are permitted provided that the following conditions are met:
@@ -27,11 +27,17 @@ if exists("g:command_t_loaded")
endif
let g:command_t_loaded = 1
-command -nargs=? -complete=dir CommandT call <SID>CommandTShow(<q-args>)
+command CommandTBuffer call <SID>CommandTShowBufferFinder()
+command CommandTJump call <SID>CommandTShowJumpFinder()
+command -nargs=? -complete=dir CommandT call <SID>CommandTShowFileFinder(<q-args>)
command CommandTFlush call <SID>CommandTFlush()
-if !hasmapto('CommandT')
- silent! nmap <unique> <silent> <Leader>t :CommandT<CR>
+if !hasmapto(':CommandT<CR>')
+ silent! nnoremap <unique> <silent> <Leader>t :CommandT<CR>
+endif
+
+if !hasmapto(':CommandTBuffer<CR>')
+ silent! nnoremap <unique> <silent> <Leader>b :CommandTBuffer<CR>
endif
function s:CommandTRubyWarning()
@@ -41,9 +47,25 @@ function s:CommandTRubyWarning()
echohl none
endfunction
-function s:CommandTShow(arg)
+function s:CommandTShowBufferFinder()
+ if has('ruby')
+ ruby $command_t.show_buffer_finder
+ else
+ call s:CommandTRubyWarning()
+ endif
+endfunction
+
+function s:CommandTShowFileFinder(arg)
+ if has('ruby')
+ ruby $command_t.show_file_finder
+ else
+ call s:CommandTRubyWarning()
+ endif
+endfunction
+
+function s:CommandTShowJumpFinder()
if has('ruby')
- ruby $command_t.show
+ ruby $command_t.show_jump_finder
else
call s:CommandTRubyWarning()
endif
View
111 ruby/command-t/controller.rb
@@ -1,4 +1,4 @@
-# Copyright 2010 Wincent Colaiuta. All rights reserved.
+# Copyright 2010-2011 Wincent Colaiuta. All rights reserved.
#
# Redistribution and use in source and binary forms, with or without
# modification, are permitted provided that the following conditions are met:
@@ -21,31 +21,39 @@
# ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
# POSSIBILITY OF SUCH DAMAGE.
-require 'command-t/finder'
+require 'command-t/finder/buffer_finder'
+require 'command-t/finder/jump_finder'
+require 'command-t/finder/file_finder'
require 'command-t/match_window'
require 'command-t/prompt'
+require 'command-t/vim/path_utilities'
module CommandT
class Controller
+ include VIM::PathUtilities
+
def initialize
@prompt = Prompt.new
- set_up_max_height
- set_up_finder
end
- def show
+ def show_buffer_finder
+ @path = VIM::pwd
+ @active_finder = buffer_finder
+ show
+ end
+
+ def show_jump_finder
+ @path = VIM::pwd
+ @active_finder = jump_finder
+ show
+ end
+
+ def show_file_finder
# optional parameter will be desired starting directory, or ""
- @path = File.expand_path(::VIM::evaluate('a:arg'), VIM::pwd)
- @finder.path = @path
- @initial_window = $curwin
- @initial_buffer = $curbuf
- @match_window = MatchWindow.new \
- :prompt => @prompt,
- :match_window_at_top => get_bool('g:CommandTMatchWindowAtTop')
- @focus = @prompt
- @prompt.focus
- register_for_key_presses
- clear # clears prompt and list matches
+ @path = File.expand_path(::VIM::evaluate('a:arg'), VIM::pwd)
+ @active_finder = file_finder
+ file_finder.path = @path
+ show
rescue Errno::ENOENT
# probably a problem with the optional parameter
@match_window.print_no_such_file_or_directory
@@ -54,13 +62,19 @@ def show
def hide
@match_window.close
if VIM::Window.select @initial_window
- ::VIM::command "silent b #{@initial_buffer.number}"
+ if @initial_buffer.number == 0
+ # upstream bug: buffer number misreported as 0
+ # see: https://wincent.com/issues/1617
+ ::VIM::command "silent b #{@initial_buffer.name}"
+ else
+ ::VIM::command "silent b #{@initial_buffer.number}"
+ end
end
end
def flush
- set_up_max_height
- set_up_finder
+ @max_height = nil
+ @file_finder = nil
end
def handle_key
@@ -95,11 +109,7 @@ def accept_selection options = {}
def toggle_focus
@focus.unfocus # old focus
- if @focus == @prompt
- @focus = @match_window
- else
- @focus = @prompt
- end
+ @focus = @focus == @prompt ? @match_window : @prompt
@focus.focus # new focus
end
@@ -136,19 +146,31 @@ def cursor_start
@prompt.cursor_start if @focus == @prompt
end
+ def leave
+ @match_window.leave
+ end
+
+ def unload
+ @match_window.unload
+ end
+
private
- def set_up_max_height
- @max_height = get_number('g:CommandTMaxHeight') || 0
+ def show
+ @initial_window = $curwin
+ @initial_buffer = $curbuf
+ @match_window = MatchWindow.new \
+ :prompt => @prompt,
+ :match_window_at_top => get_bool('g:CommandTMatchWindowAtTop'),
+ :match_window_reverse => get_bool('g:CommandTMatchWindowReverse')
+ @focus = @prompt
+ @prompt.focus
+ register_for_key_presses
+ clear # clears prompt and lists matches
end
- def set_up_finder
- @finder = CommandT::Finder.new nil,
- :max_files => get_number('g:CommandTMaxFiles'),
- :max_depth => get_number('g:CommandTMaxDepth'),
- :always_show_dot_files => get_bool('g:CommandTAlwaysShowDotFiles'),
- :never_show_dot_files => get_bool('g:CommandTNeverShowDotFiles'),
- :scan_dot_directories => get_bool('g:CommandTScanDotDirectories')
+ def max_height
+ @max_height ||= get_number('g:CommandTMaxHeight') || 0
end
def exists? name
@@ -216,6 +238,7 @@ def ensure_appropriate_window_selection
def open_selection selection, options = {}
command = options[:command] || default_open_command
selection = File.expand_path selection, @path
+ selection = relative_path_under_working_directory selection
selection = sanitize_path_string selection
ensure_appropriate_window_selection
::VIM::command "silent #{command} #{selection}"
@@ -277,13 +300,31 @@ def register_for_key_presses
def match_limit
limit = VIM::Screen.lines - 5
limit = 1 if limit < 0
- limit = [limit, @max_height].min if @max_height > 0
+ limit = [limit, max_height].min if max_height > 0
limit
end
def list_matches
- matches = @finder.sorted_matches_for @prompt.abbrev, :limit => match_limit
+ matches = @active_finder.sorted_matches_for @prompt.abbrev, :limit => match_limit
@match_window.matches = matches
end
+
+ def buffer_finder
+ @buffer_finder ||= CommandT::BufferFinder.new
+ end
+
+ def file_finder
+ @file_finder ||= CommandT::FileFinder.new nil,
+ :max_depth => get_number('g:CommandTMaxDepth'),
+ :max_files => get_number('g:CommandTMaxFiles'),
+ :max_caches => get_number('g:CommandTMaxCachedDirectories'),
+ :always_show_dot_files => get_bool('g:CommandTAlwaysShowDotFiles'),
+ :never_show_dot_files => get_bool('g:CommandTNeverShowDotFiles'),
+ :scan_dot_directories => get_bool('g:CommandTScanDotDirectories')
+ end
+
+ def jump_finder
+ @jump_finder ||= CommandT::JumpFinder.new
+ end
end # class Controller
end # module commandT
View
2 ruby/command-t/ext.c
@@ -60,6 +60,6 @@ void Init_ext()
// methods
rb_define_method(cCommandTMatcher, "initialize", CommandTMatcher_initialize, -1);
- rb_define_method(cCommandTMatcher, "sorted_matches_for", CommandTMatcher_sorted_matchers_for, 2);
+ rb_define_method(cCommandTMatcher, "sorted_matches_for", CommandTMatcher_sorted_matches_for, 2);
rb_define_method(cCommandTMatcher, "matches_for", CommandTMatcher_matches_for, 1);
}
View
9 ruby/command-t/finder.rb
@@ -1,4 +1,4 @@
-# Copyright 2010 Wincent Colaiuta. All rights reserved.
+# Copyright 2010-2011 Wincent Colaiuta. All rights reserved.
#
# Redistribution and use in source and binary forms, with or without
# modification, are permitted provided that the following conditions are met:
@@ -22,16 +22,17 @@
# POSSIBILITY OF SUCH DAMAGE.
require 'command-t/ext' # CommandT::Matcher
-require 'command-t/scanner'
module CommandT
# Encapsulates a Scanner instance (which builds up a list of available files
# in a directory) and a Matcher instance (which selects from that list based
# on a search string).
+ #
+ # Specialized subclasses use different kinds of scanners adapted for
+ # different kinds of search (files, buffers).
class Finder
def initialize path = Dir.pwd, options = {}
- @scanner = Scanner.new path, options
- @matcher = Matcher.new @scanner, options
+ raise RuntimeError, 'Subclass responsibility'
end
# Options:
View
35 ruby/command-t/finder/buffer_finder.rb
@@ -0,0 +1,35 @@
+# Copyright 2010-2011 Wincent Colaiuta. All rights reserved.
+#
+# Redistribution and use in source and binary forms, with or without
+# modification, are permitted provided that the following conditions are met:
+#
+# 1. Redistributions of source code must retain the above copyright notice,
+# this list of conditions and the following disclaimer.
+# 2. Redistributions in binary form must reproduce the above copyright notice,
+# this list of conditions and the following disclaimer in the documentation
+# and/or other materials provided with the distribution.
+#
+# THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
+# AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
+# IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
+# ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDERS OR CONTRIBUTORS BE
+# LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
+# CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
+# SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
+# INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
+# CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
+# ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
+# POSSIBILITY OF SUCH DAMAGE.
+
+require 'command-t/ext' # CommandT::Matcher
+require 'command-t/scanner/buffer_scanner'
+require 'command-t/finder'
+
+module CommandT
+ class BufferFinder < Finder
+ def initialize
+ @scanner = BufferScanner.new
+ @matcher = Matcher.new @scanner, :always_show_dot_files => true
+ end
+ end # class BufferFinder
+end # CommandT
View
35 ruby/command-t/finder/file_finder.rb
@@ -0,0 +1,35 @@
+# Copyright 2010-2011 Wincent Colaiuta. All rights reserved.
+#
+# Redistribution and use in source and binary forms, with or without
+# modification, are permitted provided that the following conditions are met:
+#
+# 1. Redistributions of source code must retain the above copyright notice,
+# this list of conditions and the following disclaimer.
+# 2. Redistributions in binary form must reproduce the above copyright notice,
+# this list of conditions and the following disclaimer in the documentation
+# and/or other materials provided with the distribution.
+#
+# THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
+# AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
+# IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
+# ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDERS OR CONTRIBUTORS BE
+# LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
+# CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
+# SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
+# INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
+# CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
+# ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
+# POSSIBILITY OF SUCH DAMAGE.
+
+require 'command-t/ext' # CommandT::Matcher
+require 'command-t/finder'
+require 'command-t/scanner/file_scanner'
+
+module CommandT
+ class FileFinder < Finder
+ def initialize path = Dir.pwd, options = {}
+ @scanner = FileScanner.new path, options
+ @matcher = Matcher.new @scanner, options
+ end
+ end # class FileFinder
+end # CommandT
View
35 ruby/command-t/finder/jump_finder.rb
@@ -0,0 +1,35 @@
+# Copyright 2011 Wincent Colaiuta. All rights reserved.
+#
+# Redistribution and use in source and binary forms, with or without
+# modification, are permitted provided that the following conditions are met:
+#
+# 1. Redistributions of source code must retain the above copyright notice,
+# this list of conditions and the following disclaimer.
+# 2. Redistributions in binary form must reproduce the above copyright notice,
+# this list of conditions and the following disclaimer in the documentation
+# and/or other materials provided with the distribution.
+#
+# THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
+# AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
+# IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
+# ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDERS OR CONTRIBUTORS BE
+# LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
+# CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
+# SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
+# INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
+# CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
+# ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
+# POSSIBILITY OF SUCH DAMAGE.
+
+require 'command-t/ext' # CommandT::Matcher
+require 'command-t/scanner/jump_scanner'
+require 'command-t/finder'
+
+module CommandT
+ class JumpFinder < Finder
+ def initialize
+ @scanner = JumpScanner.new
+ @matcher = Matcher.new @scanner, :always_show_dot_files => true
+ end
+ end # class JumpFinder
+end # module CommandT
View
142 ruby/command-t/match_window.rb
@@ -1,4 +1,4 @@
-# Copyright 2010 Wincent Colaiuta. All rights reserved.
+# Copyright 2010-2011 Wincent Colaiuta. All rights reserved.
#
# Redistribution and use in source and binary forms, with or without
# modification, are permitted provided that the following conditions are met:
@@ -29,15 +29,18 @@ class MatchWindow
@@selection_marker = '> '
@@marker_length = @@selection_marker.length
@@unselected_marker = ' ' * @@marker_length
+ @@buffer = nil
def initialize options = {}
@prompt = options[:prompt]
+ @reverse_list = options[:match_window_reverse]
# save existing window dimensions so we can restore them later
@windows = []
(0..(::VIM::Window.count - 1)).each do |i|
- window = OpenStruct.new :index => i, :height => ::VIM::Window[i].height
- @windows << window
+ @windows << OpenStruct.new(:index => i,
+ :height => ::VIM::Window[i].height,
+ :width => ::VIM::Window[i].width)
end
# global settings (must manually save and restore)
@@ -52,28 +55,35 @@ def initialize options = {}
::VIM::set_option 'sidescrolloff=0' # don't sidescroll automatically
::VIM::set_option 'noequalalways' # don't auto-balance window sizes
- # create match window and set it up
+ # show match window
split_location = options[:match_window_at_top] ? 'topleft' : 'botright'
- split_command = "silent! #{split_location} 1split GoToFile"
- [
- split_command,
- 'setlocal bufhidden=delete', # delete buf when no longer displayed
- 'setlocal buftype=nofile', # buffer is not related to any file
- 'setlocal nomodifiable', # prevent manual edits
- 'setlocal noswapfile', # don't create a swapfile
- 'setlocal nowrap', # don't soft-wrap
- 'setlocal nonumber', # don't show line numbers
- 'setlocal nolist', # don't use List mode (visible tabs etc)
- 'setlocal foldcolumn=0', # don't show a fold column at side
- 'setlocal foldlevel=99', # don't fold anything
- 'setlocal nocursorline', # don't highlight line cursor is on
- 'setlocal nospell', # spell-checking off
- 'setlocal nobuflisted', # don't show up in the buffer list
- 'setlocal textwidth=0' # don't hard-wrap (break long lines)
- ].each { |command| ::VIM::command command }
-
- # sanity check: make sure the buffer really was created
- raise "Can't find buffer" unless $curbuf.name.match /GoToFile/
+ if @@buffer # still have buffer from last time
+ ::VIM::command "silent! #{split_location} #{@@buffer.number}sbuffer"
+ raise "Can't re-open GoToFile buffer" unless $curbuf.number == @@buffer.number
+ $curwin.height = 1
+ else # creating match window for first time and set it up
+ split_command = "silent! #{split_location} 1split GoToFile"
+ [
+ split_command,
+ 'setlocal bufhidden=unload', # unload buf when no longer displayed
+ 'setlocal buftype=nofile', # buffer is not related to any file
+ 'setlocal nomodifiable', # prevent manual edits
+ 'setlocal noswapfile', # don't create a swapfile
+ 'setlocal nowrap', # don't soft-wrap
+ 'setlocal nonumber', # don't show line numbers
+ 'setlocal nolist', # don't use List mode (visible tabs etc)
+ 'setlocal foldcolumn=0', # don't show a fold column at side
+ 'setlocal foldlevel=99', # don't fold anything
+ 'setlocal nocursorline', # don't highlight line cursor is on
+ 'setlocal nospell', # spell-checking off
+ 'setlocal nobuflisted', # don't show up in the buffer list
+ 'setlocal textwidth=0' # don't hard-wrap (break long lines)
+ ].each { |command| ::VIM::command command }
+
+ # sanity check: make sure the buffer really was created
+ raise "Can't find GoToFile buffer" unless $curbuf.name.match /GoToFile\z/
+ @@buffer = $curbuf
+ end
# syntax coloring
if VIM::has_syntax?
@@ -89,16 +99,43 @@ def initialize options = {}
hide_cursor
end
+ # perform cleanup using an autocmd to ensure we don't get caught out
+ # by some unexpected means of dismissing or leaving the Command-T window
+ # (eg. <C-W q>, <C-W k> etc)
+ ::VIM::command 'autocmd! * <buffer>'
+ ::VIM::command 'autocmd BufLeave <buffer> ruby $command_t.leave'
+ ::VIM::command 'autocmd BufUnload <buffer> ruby $command_t.unload'
@has_focus = false
@selection = nil
@abbrev = ''
@window = $curwin
- @buffer = $curbuf
end
def close
- ::VIM::command "bwipeout! #{@buffer.number}"
+ # Workaround for upstream bug in Vim 7.3 on some platforms
+ #
+ # On some platforms, $curbuf.number always returns 0. One workaround is
+ # to build Vim with --disable-largefile, but as this is producing lots of
+ # support requests, implement the following fallback to the buffer name
+ # instead, at least until upstream gets fixed.
+ #
+ # For more details, see: https://wincent.com/issues/1617
+ if $curbuf.number == 0
+ # use bwipeout as bunload fails if passed the name of a hidden buffer
+ ::VIM::command 'bwipeout! GoToFile'
+ @@buffer = nil
+ else
+ ::VIM::command "bunload! #{@@buffer.number}"
+ end
+ end
+
+ def leave
+ close
+ unload
+ end
+
+ def unload
restore_window_dimensions
@settings.restore
@prompt.dispose
@@ -118,6 +155,7 @@ def select_next
@selection += 1
print_match(@selection - 1) # redraw old selection (removes marker)
print_match(@selection) # redraw new selection (adds marker)
+ move_cursor_to_selected_line
else
# (possibly) loop or scroll
end
@@ -128,16 +166,19 @@ def select_prev
@selection -= 1
print_match(@selection + 1) # redraw old selection (removes marker)
print_match(@selection) # redraw new selection (adds marker)
+ move_cursor_to_selected_line
else
# (possibly) loop or scroll
end
end
def matches= matches
+ matches = matches.reverse if @reverse_list
if matches != @matches
- @matches = matches
- @selection = 0
+ @matches = matches
+ @selection = @reverse_list ? @matches.length - 1 : 0
print_matches
+ move_cursor_to_selected_line
end
end
@@ -192,26 +233,42 @@ def print_no_such_file_or_directory
private
+ def move_cursor_to_selected_line
+ # on some non-GUI terminals, the cursor doesn't hide properly
+ # so we move the cursor to prevent it from blinking away in the
+ # upper-left corner in a distracting fashion
+ @window.cursor = [@selection + 1, 0]
+ end
+
def print_error msg
return unless VIM::Window.select(@window)
unlock
clear
@window.height = 1
- @buffer[1] = "-- #{msg} --"
+ @@buffer[1] = "-- #{msg} --"
lock
end
def restore_window_dimensions
- # sort from tallest to shortest
- @windows.sort! { |a, b| b.height <=> a.height }
+ # sort from tallest to shortest, tie-breaking on window width
+ @windows.sort! do |a, b|
+ order = b.height <=> a.height
+ if order.zero?
+ b.width <=> a.width
+ else
+ order
+ end
+ end
# starting with the tallest ensures that there are no constraints
# preventing windows on the side of vertical splits from regaining
# their original full size
@windows.each do |w|
# beware: window may be nil
- window = ::VIM::Window[w.index]
- window.height = w.height if window
+ if window = ::VIM::Window[w.index]
+ window.height = w.height
+ window.width = w.width
+ end
end
end
@@ -231,7 +288,7 @@ def match_text_for_idx idx
def print_match idx
return unless VIM::Window.select(@window)
unlock
- @buffer[idx + 1] = match_text_for_idx idx
+ @@buffer[idx + 1] = match_text_for_idx idx
lock
end
@@ -252,10 +309,10 @@ def print_matches
@window.height = actual_lines
(1..actual_lines).each do |line|
idx = line - 1
- if @buffer.count >= line
- @buffer[line] = match_text_for_idx idx
+ if @@buffer.count >= line
+ @@buffer[line] = match_text_for_idx idx
else
- @buffer.append line - 1, match_text_for_idx(idx)
+ @@buffer.append line - 1, match_text_for_idx(idx)
end
end
lock
@@ -292,20 +349,13 @@ def clear
end
def get_cursor_highlight
- # as :highlight returns nothing and only prints,
- # must redirect its output to a variable
- ::VIM::command 'silent redir => g:command_t_cursor_highlight'
-
- # force 0 verbosity to ensure origin information isn't printed as well
- ::VIM::command 'silent! 0verbose highlight Cursor'
- ::VIM::command 'silent redir END'
-
# there are 3 possible formats to check for, each needing to be
# transformed in a certain way in order to reapply the highlight:
# Cursor xxx guifg=bg guibg=fg -> :hi! Cursor guifg=bg guibg=fg
# Cursor xxx links to SomethingElse -> :hi! link Cursor SomethingElse
# Cursor xxx cleared -> :hi! clear Cursor
- highlight = ::VIM::evaluate 'g:command_t_cursor_highlight'
+ highlight = VIM::capture 'silent! 0verbose highlight Cursor'
+
if highlight =~ /^Cursor\s+xxx\s+links to (\w+)/
"link Cursor #{$~[1]}"
elsif highlight =~ /^Cursor\s+xxx\s+cleared/
View
4 ruby/command-t/matcher.c
@@ -96,7 +96,7 @@ VALUE CommandTMatcher_initialize(int argc, VALUE *argv, VALUE self)
return Qnil;
}
-VALUE CommandTMatcher_sorted_matchers_for(VALUE self, VALUE abbrev, VALUE options)
+VALUE CommandTMatcher_sorted_matches_for(VALUE self, VALUE abbrev, VALUE options)
{
// process optional options hash
VALUE limit_option = CommandT_option_from_hash("limit", options);
@@ -115,7 +115,7 @@ VALUE CommandTMatcher_sorted_matchers_for(VALUE self, VALUE abbrev, VALUE option
// apply optional limit option
long limit = NIL_P(limit_option) ? 0 : NUM2LONG(limit_option);
- if (limit == 0 || RARRAY_LEN(matches)< limit)
+ if (limit == 0 || RARRAY_LEN(matches) < limit)
limit = RARRAY_LEN(matches);
// will return an array of strings, not an array of Match objects
View
2 ruby/command-t/matcher.h
@@ -24,7 +24,7 @@
#include <ruby.h>
extern VALUE CommandTMatcher_initialize(int argc, VALUE *argv, VALUE self);
-extern VALUE CommandTMatcher_sorted_matchers_for(VALUE self, VALUE abbrev, VALUE options);
+extern VALUE CommandTMatcher_sorted_matches_for(VALUE self, VALUE abbrev, VALUE options);
// most likely the function will be subsumed by the sorted_matcher_for function
extern VALUE CommandTMatcher_matches_for(VALUE self, VALUE abbrev);
View
69 ruby/command-t/scanner.rb
@@ -1,4 +1,4 @@
-# Copyright 2010 Wincent Colaiuta. All rights reserved.
+# Copyright 2010-2011 Wincent Colaiuta. All rights reserved.
#
# Redistribution and use in source and binary forms, with or without
# modification, are permitted provided that the following conditions are met:
@@ -24,70 +24,5 @@
require 'command-t/vim'
module CommandT
- # Reads the current directory recursively for the paths to all regular files.
- class Scanner
- class FileLimitExceeded < ::RuntimeError; end
-
- def initialize path = Dir.pwd, options = {}
- @path = path
- @max_depth = options[:max_depth] || 15
- @max_files = options[:max_files] || 10_000
- @scan_dot_directories = options[:scan_dot_directories] || false
- end
-
- def paths
- return @paths unless @paths.nil?
- begin
- @paths = []
- @depth = 0
- @files = 0
- @prefix_len = @path.chomp('/').length
- add_paths_for_directory @path, @paths
- rescue FileLimitExceeded
- end
- @paths
- end
-
- def flush
- @paths = nil
- end
-
- def path= str
- if @path != str
- @path = str
- flush
- end
- end
-
- private
-
- def path_excluded? path
- # first strip common prefix (@path) from path to match VIM's behavior
- path = path[(@prefix_len + 1)..-1]
- path = VIM::escape_for_single_quotes path
- ::VIM::evaluate("empty(expand(fnameescape('#{path}')))").to_i == 1
- end
-
- def add_paths_for_directory dir, accumulator
- Dir.foreach(dir) do |entry|
- next if ['.', '..'].include?(entry)
- path = File.join(dir, entry)
- unless path_excluded?(path)
- if File.file?(path)
- @files += 1
- raise FileLimitExceeded if @files > @max_files
- accumulator << path[@prefix_len + 1..-1]
- elsif File.directory?(path)
- next if @depth >= @max_depth
- next if (entry.match(/\A\./) && !@scan_dot_directories)
- @depth += 1
- add_paths_for_directory path, accumulator
- @depth -= 1
- end
- end
- end
- rescue Errno::EACCES
- # skip over directories for which we don't have access
- end
- end # class Scanner
+ class Scanner; end
end # module CommandT
View
42 ruby/command-t/scanner/buffer_scanner.rb
@@ -0,0 +1,42 @@
+# Copyright 2010-2011 Wincent Colaiuta. All rights reserved.
+#
+# Redistribution and use in source and binary forms, with or without
+# modification, are permitted provided that the following conditions are met:
+#
+# 1. Redistributions of source code must retain the above copyright notice,
+# this list of conditions and the following disclaimer.
+# 2. Redistributions in binary form must reproduce the above copyright notice,
+# this list of conditions and the following disclaimer in the documentation
+# and/or other materials provided with the distribution.
+#
+# THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
+# AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
+# IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
+# ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDERS OR CONTRIBUTORS BE
+# LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
+# CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
+# SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
+# INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
+# CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
+# ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
+# POSSIBILITY OF SUCH DAMAGE.
+
+require 'command-t/vim'
+require 'command-t/vim/path_utilities'
+require 'command-t/scanner'
+
+module CommandT
+ # Returns a list of all open buffers.
+ class BufferScanner < Scanner
+ include VIM::PathUtilities
+
+ def paths
+ (0..(::VIM::Buffer.count - 1)).map do |n|
+ buffer = ::VIM::Buffer[n]
+ if buffer.name # beware, may be nil
+ relative_path_under_working_directory buffer.name
+ end
+ end.compact
+ end
+ end # class BufferScanner
+end # module CommandT
View
101 ruby/command-t/scanner/file_scanner.rb
@@ -0,0 +1,101 @@
+# Copyright 2010-2011 Wincent Colaiuta. All rights reserved.
+#
+# Redistribution and use in source and binary forms, with or without
+# modification, are permitted provided that the following conditions are met:
+#
+# 1. Redistributions of source code must retain the above copyright notice,
+# this list of conditions and the following disclaimer.
+# 2. Redistributions in binary form must reproduce the above copyright notice,
+# this list of conditions and the following disclaimer in the documentation
+# and/or other materials provided with the distribution.
+#
+# THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
+# AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
+# IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
+# ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDERS OR CONTRIBUTORS BE
+# LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
+# CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
+# SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
+# INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
+# CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
+# ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
+# POSSIBILITY OF SUCH DAMAGE.
+
+require 'command-t/vim'
+require 'command-t/scanner'
+
+module CommandT
+ # Reads the current directory recursively for the paths to all regular files.
+ class FileScanner < Scanner
+ class FileLimitExceeded < ::RuntimeError; end
+ attr_accessor :path
+
+ def initialize path = Dir.pwd, options = {}
+ @paths = {}
+ @paths_keys = []
+ @path = path
+ @max_depth = options[:max_depth] || 15
+ @max_files = options[:max_files] || 10_000
+ @max_caches = options[:max_caches] || 1
+ @scan_dot_directories = options[:scan_dot_directories] || false
+ end
+
+ def paths
+ return @paths[@path] if @paths.has_key?(@path)
+ begin
+ ensure_cache_under_limit
+ @paths[@path] = []
+ @depth = 0
+ @files = 0
+ @prefix_len = @path.chomp('/').length
+ add_paths_for_directory @path, @paths[@path]
+ rescue FileLimitExceeded
+ end
+ @paths[@path]
+ end
+
+ def flush
+ @paths = {}
+ end
+
+ private
+
+ def ensure_cache_under_limit
+ # Ruby 1.8 doesn't have an ordered hash, so use a separate stack to
+ # track and expire the oldest entry in the cache
+ if @max_caches > 0 && @paths_keys.length >= @max_caches
+ @paths.delete @paths_keys.shift
+ end
+ @paths_keys << @path
+ end
+
+ def path_excluded? path
+ # first strip common prefix (@path) from path to match VIM's behavior
+ path = path[(@prefix_len + 1)..-1]
+ path = VIM::escape_for_single_quotes path
+ ::VIM::evaluate("empty(expand(fnameescape('#{path}')))").to_i == 1
+ end
+
+ def add_paths_for_directory dir, accumulator
+ Dir.foreach(dir) do |entry|
+ next if ['.', '..'].include?(entry)
+ path = File.join(dir, entry)
+ unless path_excluded?(path)
+ if File.file?(path)
+ @files += 1
+ raise FileLimitExceeded if @files > @max_files
+ accumulator << path[@prefix_len + 1..-1]
+ elsif File.directory?(path)
+ next if @depth >= @max_depth
+ next if (entry.match(/\A\./) && !@scan_dot_directories)
+ @depth += 1
+ add_paths_for_directory path, accumulator
+ @depth -= 1
+ end
+ end
+ end
+ rescue Errno::EACCES
+ # skip over directories for which we don't have access
+ end
+ end # class FileScanner
+end # module CommandT
View
53 ruby/command-t/scanner/jump_scanner.rb
@@ -0,0 +1,53 @@
+# Copyright 2011 Wincent Colaiuta. All rights reserved.
+#
+# Redistribution and use in source and binary forms, with or without
+# modification, are permitted provided that the following conditions are met:
+#
+# 1. Redistributions of source code must retain the above copyright notice,
+# this list of conditions and the following disclaimer.
+# 2. Redistributions in binary form must reproduce the above copyright notice,
+# this list of conditions and the following disclaimer in the documentation
+# and/or other materials provided with the distribution.
+#
+# THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
+# AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
+# IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
+# ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDERS OR CONTRIBUTORS BE
+# LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
+# CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
+# SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
+# INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
+# CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
+# ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
+# POSSIBILITY OF SUCH DAMAGE.
+
+require 'command-t/vim'
+require 'command-t/vim/path_utilities'
+require 'command-t/scanner'
+
+module CommandT
+ # Returns a list of files in the jumplist.
+ class JumpScanner < Scanner
+ include VIM::PathUtilities
+
+ def paths
+ jumps_with_filename = jumps.lines.select do |line|
+ line_contains_filename?(line)
+ end
+ filenames = jumps_with_filename[1..-2].map do |line|
+ relative_path_under_working_directory line.split[3]
+ end
+ filenames.sort.uniq
+ end
+
+ private
+
+ def line_contains_filename? line
+ line.split.count > 3
+ end
+
+ def jumps
+ VIM::capture 'silent jumps'
+ end
+ end # class JumpScanner
+end # module CommandT
View
10 ruby/command-t/stub.rb
@@ -1,4 +1,4 @@
-# Copyright 2010 Wincent Colaiuta. All rights reserved.
+# Copyright 2010-2011 Wincent Colaiuta. All rights reserved.
#
# Redistribution and use in source and binary forms, with or without
# modification, are permitted provided that the following conditions are met:
@@ -27,12 +27,8 @@ class Stub
'Please see INSTALLATION and TROUBLE-SHOOTING in the help',
'For more information type: :help command-t']
- def show
- warn *@@load_error
- end
-
- def flush
- warn *@@load_error
+ [:flush, :show_buffer_finder, :show_file_finder].each do |method|
+ define_method(method.to_sym) { warn *@@load_error }
end
private
View
10 ruby/command-t/vim.rb
@@ -1,4 +1,4 @@
-# Copyright 2010 Wincent Colaiuta. All rights reserved.
+# Copyright 2010-2011 Wincent Colaiuta. All rights reserved.
#
# Redistribution and use in source and binary forms, with or without
# modification, are permitted provided that the following conditions are met:
@@ -34,6 +34,14 @@ def self.pwd
::VIM::evaluate 'getcwd()'
end
+ # Execute cmd, capturing the output into a variable and returning it.
+ def self.capture cmd
+ ::VIM::command 'silent redir => g:command_t_captured_output'
+ ::VIM::command cmd
+ ::VIM::command 'silent redir END'
+ ::VIM::evaluate 'g:command_t_captured_output'
+ end
+
# Escape a string for safe inclusion in a Vim single-quoted string
# (single quotes escaped by doubling, everything else is literal)
def self.escape_for_single_quotes str
View
40 ruby/command-t/vim/path_utilities.rb
@@ -0,0 +1,40 @@
+# Copyright 2010-2011 Wincent Colaiuta. All rights reserved.
+#
+# Redistribution and use in source and binary forms, with or without
+# modification, are permitted provided that the following conditions are met:
+#
+# 1. Redistributions of source code must retain the above copyright notice,
+# this list of conditions and the following disclaimer.
+# 2. Redistributions in binary form must reproduce the above copyright notice,
+# this list of conditions and the following disclaimer in the documentation
+# and/or other materials provided with the distribution.
+#
+# THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
+# AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
+# IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
+# ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDERS OR CONTRIBUTORS BE
+# LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
+# CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
+# SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
+# INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
+# CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
+# ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
+# POSSIBILITY OF SUCH DAMAGE.
+
+require 'command-t/vim'
+
+module CommandT
+ module VIM
+ module PathUtilities
+
+ private
+
+ def relative_path_under_working_directory path
+ # any path under the working directory will be specified as a relative
+ # path to improve the readability of the buffer list etc
+ pwd = File.expand_path(VIM::pwd) + '/'
+ path.index(pwd) == 0 ? path[pwd.length..-1] : path
+ end
+ end # module PathUtilities
+ end # module VIM
+end # module CommandT

0 comments on commit c003684

Please sign in to comment.
Something went wrong with that request. Please try again.