Skip to content

Commit 6bac77c

Browse files
Git-Support: Better handling of cmd.-line maps.
- Better handling of cmd.-line maps. - Minor fixes. - Extended and corrected the documentation.
1 parent 5f0c9c4 commit 6bac77c

7 files changed

Lines changed: 123 additions & 41 deletions

File tree

doc/gitsupport.txt

Lines changed: 34 additions & 21 deletions
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,8 @@
1-
*gitsupport.txt* Git Support June 28 2014
1+
*gitsupport.txt* Git Support Aug 21 2014
22

33
Git Support *git-support* *gitsupport*
44

5-
Plug-in version 0.9.2pre
5+
Plug-in version 0.9.2
66
for Vim version 7.0 and above
77
Wolfgang Mehner <wolfgang-mehner at web.de>
88

@@ -111,6 +111,7 @@ run the commands in every subdirectory of the project.
111111
|:GitStash| [<args>] (run) git stash <args>
112112
|:GitStash| list [<args>] (buf) git stash list <args>
113113
|:GitStash| show [<args>] (buf) git stash show <args>
114+
|:GitSlist| (buf) git stash list
114115
|:GitStatus| [<path>] (buf) git status
115116
|:GitTag| (buf) git tag
116117
|:GitTag| <args> (run) git tag <args>
@@ -136,6 +137,12 @@ When called without arguments, the commands GitBranch and GitRemote open a
136137
buffer, otherwise they run the respective Git command with the given
137138
arguments.
138139

140+
Names of Git objects can be completed while on the Vim command-line, similar
141+
to the way words can be completed in buffers using CTRL-P (see |i_CTRL-P|).
142+
The names of branches, commands, remotes and tags can be completed that way.
143+
This feature has to be enabled by hand, see |gitsupport-cmds-cmd-line| for
144+
details.
145+
139146
------------------------------------------------------------------------------
140147
2.1 MENU *gitsupport-overview-menu*
141148
------------------------------------------------------------------------------
@@ -280,20 +287,20 @@ The second version executes "git branch ...".
280287
*:GitCheckout*
281288
:GitCheckout [<args>] ~
282289

283-
Executes "git checkout ...". If no arguments are given, checks out the current
284-
file.
290+
Executes "git checkout ...".
285291

286292
Examples:
287293

288294
Check out the file in the current buffer: >
289-
:GitCheckout
290-
Is equivalent to: >
291-
git checkout -- <currentfile>
295+
:GitCheckout -- %
292296
(Might require running ":e" to update the buffer itself.)
293297

294298
Check out the branch "master": >
295299
:GitCheckout master
296300
301+
Settings:
302+
- |g:Git_CheckoutExpandEmpty|
303+
297304
------------------------------------------------------------------------------
298305
*:GitCommit* *:GitCommitFile* *:GitCommitMsg*
299306
:GitCommit [<args>] ~
@@ -520,15 +527,15 @@ Is equivalent to: >
520527
*:GitReset*
521528
:GitReset [<args>] ~
522529

523-
Executes "git reset ...". If no arguments are given, resets the current
524-
buffer.
530+
Executes "git reset ...".
525531

526532
Example:
527533

528534
Reset the current file: >
529-
:GitReset
530-
Is equivalent to: >
531-
git reset -- <currentfile>
535+
:GitReset -- %
536+
537+
Settings:
538+
- |g:Git_ResetExpandEmpty|
532539

533540
------------------------------------------------------------------------------
534541
*:GitShow*
@@ -546,13 +553,15 @@ separate buffer is opened.
546553
----------------------------------------------------------------------------
547554

548555
------------------------------------------------------------------------------
549-
*:GitStash*
556+
*:GitStash* *:GitSlist*
550557
:GitStash [<args>] ~
551558
:GitStash list [<args>] ~
552559
:GitStash show [<args>] ~
560+
:GitSlist ~
553561

554562
The first version executes "git stash ...". The second and third version open
555-
buffers listing the stashes or showing a stash.
563+
buffers listing the stashes or showing a stash. The command ":GitSlist" is a
564+
shorthand for ":GitStash list"
556565

557566
The buffer for ":GitStash list" defines the following maps:
558567

@@ -691,17 +700,21 @@ Shows the plug-in settings. The second version is verbose.
691700
------------------------------------------------------------------------------
692701
3.1 COMMAND-LINE COMPLETION *gitsupport-cmds-cmd-line*
693702
------------------------------------------------------------------------------
694-
*GitS_CmdLineComplete()*
703+
*g:Git_MapCompleteBranch* *g:Git_MapCompleteCommand*
704+
*g:Git_MapCompleteRemote* *g:Git_MapCompleteTag*
695705
The user can configure maps to complete the names of branches, remotes, tags
696706
and Git-commands on the command-line. The command-line is set up to complete
697-
filenames using "tab". Other elements are completed using the function
698-
GitS_CmdLineComplete(<mode>), which must be used in maps like this:
707+
filenames using "tab". Other elements are completed using special keys, which
708+
may be configured like this:
699709
>
700-
cnoremap <silent> <c-b> <C-\>eGitS_CmdLineComplete('branch')<CR>
701-
cnoremap <silent> <c-s> <C-\>eGitS_CmdLineComplete('command')<CR>
702-
cnoremap <silent> <c-r> <C-\>eGitS_CmdLineComplete('remote')<CR>
703-
cnoremap <silent> <c-t> <C-\>eGitS_CmdLineComplete('tag')<CR>
710+
let g:Git_MapCompleteBranch = '<c-b>' " complete branches, CTRL-B
711+
let g:Git_MapCompleteCommand = '<c-s>' " complete commands, CTRL-S
712+
let g:Git_MapCompleteRemote = '<c-r>' " complete remotes, CTRL-R
713+
let g:Git_MapCompleteTag = '<c-t>' " complete tags, CTRL-T
704714
<
715+
These maps are not set up by default. Only if one of these variables is set,
716+
then the corresponding map is created.
717+
705718
==============================================================================
706719
4. SYNTAX HIGHLIGHTING *gitsupport-syntax*
707720
==============================================================================

git-support/README.md

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
README for git-support.vim (Version 0.9.2pre) / June 28 2014
1+
README for git-support.vim (Version 0.9.2) / August 21 2014
22
================================================================================
33

44
* INSTALLATION
@@ -124,7 +124,7 @@ Any problems? See the TROUBLESHOOTING section at the end of the help file
124124
RELEASE NOTES
125125
================================================================================
126126

127-
RELEASE NOTES FOR VERSION 0.9.2pre
127+
RELEASE NOTES FOR VERSION 0.9.2
128128
--------------------------------------------------------------------------------
129129
- Added: Command :GitBash for running interactive Git commands.
130130
- Added: Command :GitSlist as a shorthand for ":GitStash list".

git-support/doc/ChangeLog

Lines changed: 23 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,26 @@
1+
--------------------------------------------------------------------------------
2+
RELEASE NOTES FOR VERSION 0.9.2
3+
--------------------------------------------------------------------------------
4+
- Added: Command :GitBash for running interactive Git commands.
5+
- Added: Command :GitSlist as a shorthand for ":GitStash list".
6+
- Added: New maps for the buffers: branch, remote, stash, tag
7+
- Added: New maps for the buffer: status
8+
- Added: New setting g:Git_BinPath, to set the path to the executables.
9+
- Added: Command-line completion for subcommands, branches, remotes, tags.
10+
- Changed: :GitShow shows different objects in an according way.
11+
- Changed: :GitCommitFile updates the file before committing.
12+
- Changed: :GitHelp shows man page text with appropriate width.
13+
- Changed: :GitStatus can be restricted to a path by passing it as an argument.
14+
- Changed: :GitStatus respects the option 'status.relativePaths'.
15+
- Changed: :GitStatus can work with changes introduced by Git version 1.8.5.
16+
- Changed: Calling :GitCheckout and :GitReset without arguments
17+
(see g:Git_CheckoutExpandEmpty and g:Git_ResetExpandEmpty).
18+
- Fixed: Jumping to files was still not working correctly.
19+
- Fixed: Better compatibility with custom mappings
20+
(use "normal!", "noremap" and "noremenu" consistently).
21+
- Improved syntax highlighting.
22+
- Minor changes.
23+
124
--------------------------------------------------------------------------------
225
RELEASE NOTES FOR VERSION 0.9.1
326
--------------------------------------------------------------------------------

git-support/rc/additions.vimrc

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -21,10 +21,10 @@
2121
"" cmd-line completion
2222
"" (use ctrl+s for commands, since we do not want to remap ctrl+c,
2323
"" "s" stands for Git 's'ubcommands)
24-
"cnoremap <silent> <c-b> <C-\>eGitS_CmdLineComplete('branch')<CR>
25-
"cnoremap <silent> <c-s> <C-\>eGitS_CmdLineComplete('command')<CR>
26-
"cnoremap <silent> <c-r> <C-\>eGitS_CmdLineComplete('remote')<CR>
27-
"cnoremap <silent> <c-t> <C-\>eGitS_CmdLineComplete('tag')<CR>
24+
"let g:Git_MapCompleteBranch = '<c-b>'
25+
"let g:Git_MapCompleteCommand = '<c-s>'
26+
"let g:Git_MapCompleteRemote = '<c-r>'
27+
"let g:Git_MapCompleteTag = '<c-t>'
2828
"
2929
" syntax highlighting (bright background)
3030
"

git-support/rc/customization.vimrc

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -195,10 +195,10 @@ xnoremap ` s``<Esc>P<Right>
195195
"" cmd-line completion
196196
"" (use ctrl+s for commands, since we do not want to remap ctrl+c,
197197
"" "s" stands for Git 's'ubcommands)
198-
"cnoremap <silent> <c-b> <C-\>eGitS_CmdLineComplete('branch')<CR>
199-
"cnoremap <silent> <c-s> <C-\>eGitS_CmdLineComplete('command')<CR>
200-
"cnoremap <silent> <c-r> <C-\>eGitS_CmdLineComplete('remote')<CR>
201-
"cnoremap <silent> <c-t> <C-\>eGitS_CmdLineComplete('tag')<CR>
198+
"let g:Git_MapCompleteBranch = '<c-b>'
199+
"let g:Git_MapCompleteCommand = '<c-s>'
200+
"let g:Git_MapCompleteRemote = '<c-r>'
201+
"let g:Git_MapCompleteTag = '<c-t>'
202202
"
203203
" syntax highlighting (bright background)
204204
"

plugin/git-support.vim

Lines changed: 54 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -41,7 +41,7 @@ endif
4141
if &cp || ( exists('g:GitSupport_Version') && ! exists('g:GitSupport_DevelopmentOverwrite') )
4242
finish
4343
endif
44-
let g:GitSupport_Version= '0.9.2pre' " version number of this script; do not change
44+
let g:GitSupport_Version= '0.9.2' " version number of this script; do not change
4545
"
4646
"-------------------------------------------------------------------------------
4747
" Auxiliary functions. {{{1
@@ -1853,6 +1853,8 @@ endfunction " ---------- end of function GitS_CommitDryRun ----------
18531853
"-------------------------------------------------------------------------------
18541854
"
18551855
function! s:Diff_GetFile( ... )
1856+
"
1857+
" :TODO:17.08.2014 15:01:WM: recognized renamed files
18561858
"
18571859
let f_name = ''
18581860
let f_line = -1
@@ -1914,24 +1916,36 @@ function! s:Diff_GetFile( ... )
19141916
"
19151917
endfunction " ---------- end of function s:Diff_GetFile ----------
19161918
"
1917-
" :TODO:11.08.2014 19:09:WM: docu {{{2
1919+
"-------------------------------------------------------------------------------
1920+
" s:Diff_ChunkHandler : Add/checkout/reset a chunk. {{{2
1921+
"
1922+
" Parameters:
1923+
" action - "add-chunk", "checkout-chunk", "reset-chunk" (string)
1924+
" Returns:
1925+
" success - true, if the command was run successfully (integer)
1926+
"-------------------------------------------------------------------------------
19181927
"
1919-
function! s:Diff_ChunkHandler ( action )
1928+
function! s:Diff_ChunkHandler ( action, ... )
19201929
"
1921-
let l_pos = line('.')
1930+
let l_pos = line('.') " the current position
19221931
"
1923-
let d_pos = search ( '\m\_^diff ', 'bcnW' )
1924-
let c_pos = search ( '\m\_^@@ ', 'bcnW' )
1925-
let c_end = search ( '\m\_^@@ \|\_^diff ', 'nW' )
1932+
" the positions in the buffer
1933+
let d_pos = search ( '\m\_^diff ', 'bcnW' ) " the position of the diff header
1934+
let c_pos = search ( '\m\_^@@ ', 'bcnW' ) " the start of the chunk
1935+
let c_end = search ( '\m\_^@@ \|\_^diff ', 'nW' ) " ... the end
19261936
"
19271937
if d_pos == 0 || c_pos == 0
19281938
return 0
19291939
elseif c_end == 0
1940+
" found the other two positions
1941+
" -> the end of the chunk must be the end of the file
19301942
let c_end = line('$')+1
19311943
endif
19321944
"
1945+
" get the chunk
19331946
let chunk = join ( getline ( c_pos, c_end-1 ), "\n" )."\n"
19341947
"
1948+
" get the diff header
19351949
let head = getline(d_pos)
19361950
"
19371951
while 1
@@ -1945,6 +1959,14 @@ function! s:Diff_ChunkHandler ( action )
19451959
let head .= "\n".line
19461960
endwhile
19471961
"
1962+
" apply the patch, depending on the action
1963+
let base = s:GitRepoDir()
1964+
"
1965+
" could not get top-level?
1966+
if base == '' | return | endif
1967+
"
1968+
silent exe 'lchdir '.fnameescape( base )
1969+
"
19481970
if a:action == 'add-chunk'
19491971
let text = system ( s:Git_Executable.' apply --cached -- -', head."\n".chunk )
19501972
elseif a:action == 'checkout-chunk'
@@ -1953,6 +1975,8 @@ function! s:Diff_ChunkHandler ( action )
19531975
let text = system ( s:Git_Executable.' apply --cached -R -- -', head."\n".chunk )
19541976
endif
19551977
"
1978+
silent exe 'lchdir -'
1979+
"
19561980
if v:shell_error != 0
19571981
echo "applying the chunk failed:\n\n".text | " failure
19581982
elseif text =~ '^\_s*$'
@@ -1961,7 +1985,7 @@ function! s:Diff_ChunkHandler ( action )
19611985
echo "chunk applied successfully:\n".text | " success
19621986
endif
19631987
"
1964-
return 1
1988+
return v:shell_error == 0
19651989
endfunction " ---------- end of function s:Diff_ChunkHandler ----------
19661990
" }}}2
19671991
"-------------------------------------------------------------------------------
@@ -4125,6 +4149,28 @@ function! Git_RemoveMenus()
41254149
endfunction " ---------- end of function Git_RemoveMenus ----------
41264150
"
41274151
"-------------------------------------------------------------------------------
4152+
" Setup maps. {{{1
4153+
"-------------------------------------------------------------------------------
4154+
"
4155+
let s:maps = [
4156+
\ [ 'complete branch', 'g:Git_MapCompleteBranch', '<C-\>eGitS_CmdLineComplete("branch")<CR>' ],
4157+
\ [ 'complete command', 'g:Git_MapCompleteCommand', '<C-\>eGitS_CmdLineComplete("command")<CR>' ],
4158+
\ [ 'complete remote', 'g:Git_MapCompleteRemote', '<C-\>eGitS_CmdLineComplete("remote")<CR>' ],
4159+
\ [ 'complete tag', 'g:Git_MapCompleteTag', '<C-\>eGitS_CmdLineComplete("tag")<CR>' ],
4160+
\ ]
4161+
"
4162+
for [ name, map_var, cmd ] in s:maps
4163+
if exists ( map_var )
4164+
try
4165+
silent exe 'cnoremap <silent> '.{map_var}.' '.cmd
4166+
catch /.*/
4167+
call s:ErrorMsg ( 'Error while creating the map "'.name.'", with lhs "'.{map_var}.'":', v:exception )
4168+
finally
4169+
endtry
4170+
endif
4171+
endfor
4172+
"
4173+
"-------------------------------------------------------------------------------
41284174
" Setup menus. {{{1
41294175
"-------------------------------------------------------------------------------
41304176
"

project/TODO.txt

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -68,8 +68,8 @@ Git:
6868
Update syntax highlighting, folding function, file actions
6969
- (WM) Do not use "sync fromstart" in syntax highlighting,
7070
is extremely slow for diff and log.
71-
- (WM) Document map "ow" in status buffer.
72-
- (WM) Document map "ac", "cc", and "rc" in diff buffer.
71+
- (WM) Document map "ow" in status buffer, mention in the README.
72+
- (WM) Document map "ac", "cc", and "rc" in diff buffer, mention in the README.
7373
- (WM) Update buffer after executing a command: :GitBranch, :GitRemote, :GitStash, ...
7474
- (WM) Buffer "git stash list", maps for: create
7575
- (WM) Feed output of "git apply" into quickfix.

0 commit comments

Comments
 (0)