Skip to content

Commit 96e10ed

Browse files
committed
Added vim-lastplace
1 parent 3aefdbd commit 96e10ed

File tree

5 files changed

+244
-0
lines changed

5 files changed

+244
-0
lines changed
Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
doc/tags
Lines changed: 22 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,22 @@
1+
The MIT License (MIT)
2+
3+
Copyright (c) 2015 - 2017 Greg Dietsche
4+
5+
Permission is hereby granted, free of charge, to any person obtaining a copy
6+
of this software and associated documentation files (the "Software"), to deal
7+
in the Software without restriction, including without limitation the rights
8+
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
9+
copies of the Software, and to permit persons to whom the Software is
10+
furnished to do so, subject to the following conditions:
11+
12+
The above copyright notice and this permission notice shall be included in all
13+
copies or substantial portions of the Software.
14+
15+
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
16+
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
17+
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
18+
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
19+
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
20+
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
21+
SOFTWARE.
22+
Lines changed: 105 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,105 @@
1+
# vim-lastplace v3.1.1
2+
3+
Intelligently reopen files at your last edit position. By default git,
4+
svn, and mercurial commit messages are ignored because you
5+
probably want to type a new message and not re-edit the previous
6+
one.
7+
8+
## Advantages
9+
Advantages over the snippets that can be found around the net include:
10+
* Commit messages automatically start at the beginning of a file. This is important because many version control systems re-use the same file for commit message editing.
11+
* Maximizes Available Context
12+
- Center the cursor vertically after restoring last edit position.
13+
- Keep as much of the file on screen as possible when last edit position is at the end of the file.
14+
* Opens folds if the last edit position is inside a fold.
15+
* Works properly with new file templates and scripts that jump to a specific line in them.
16+
17+
## Installation
18+
You can use [pathogen.vim](https://github.com/tpope/vim-pathogen) or other plugin managers to install and use vim-lastplace.
19+
20+
cd ~/.vim/bundle
21+
git clone git://github.com/farmergreg/vim-lastplace.git
22+
23+
Depending on which Vim package you're using, Vim may be preconfigured with
24+
last-edit-position logic that doesn't work quite as well as vim-lastplace.
25+
If so, you may want to disable that in favor of vim-lastplace. For example,
26+
for Vim as packaged with Git for Windows, you can edit
27+
`C:\Program Files\Git\etc\vimrc` and comment out the "Remember positions in files"
28+
`autocmd BufReadPost *` block.
29+
30+
## Configuration
31+
You can configure what file types to ignore by setting
32+
g:lastplace_ignore in your vimrc. This is a comma separated list.
33+
By default it is set to:
34+
35+
let g:lastplace_ignore = "gitcommit,gitrebase,svn,hgcommit"
36+
37+
You can configure buffer types to ignore by setting
38+
g:lastplace_ignore_buftype in your vimrc. This is a comma separated list.
39+
By default it is set to:
40+
41+
let g:lastplace_ignore_buftype = "quickfix,nofile,help"
42+
43+
Folds are automatically opened when jumping to the last edit position. If you
44+
do not like this behavior you can disable it by putting this in your vimrc:
45+
46+
let g:lastplace_open_folds = 0
47+
48+
## Miscellaneous
49+
This plugin is complete and stable. Please do not be afraid to try it even
50+
if there is very little recent activity in this repository. If you do find
51+
a bug, please submit a pull request that fixes whatever problem you're having.
52+
53+
## Version History
54+
vim-lastplace uses [semver](http://semver.org/) to manage version numbers.
55+
56+
### 3.1.1
57+
- Add 'nofile' and 'help' to lastplace_ignore_buftype. (Issue [#14](https://github.com/farmergreg/vim-lastplace/issues/14))
58+
- Do not jump when a new file is created (Issue [#15](https://github.com/farmergreg/vim-lastplace/issues/15), [#16](https://github.com/farmergreg/vim-lastplace/issues/16))
59+
60+
### 3.1.0
61+
- Add g:lastplace_ignore_buftype setting.
62+
- Update github links from username dietsche to farmergreg.
63+
64+
### 3.0.4
65+
- Add g:lastplace_open_folds option.
66+
67+
### 3.0.3
68+
- Point release for Debian packaging. Changes all http links to https. No code changes.
69+
70+
### 3.0.2
71+
- A fix for files that are smaller than the current screen size (issue #8)
72+
73+
### 3.0.1
74+
- A fix for files with modelines.
75+
76+
### 3.0.0
77+
78+
- Open folds if the last edited area is inside a closed fold.
79+
80+
### 2.0.1
81+
82+
- Add gitrebase filetype to the ignore list.
83+
84+
### 2.0.0
85+
86+
- Center the screen when restoring the cursor position.
87+
- When at the end of a file, keep as much of it on screen as possible.
88+
89+
### 1.0.0
90+
91+
- Initial version.
92+
93+
## About
94+
95+
- Author : Gregory L. Dietsche
96+
- Web Page: https://www.gregd.org/
97+
98+
Get the latest version, submit pull requests, and file bug reports
99+
on GitHub:
100+
- https://github.com/farmergreg/vim-lastplace
101+
102+
If you like this plugin, please star and rate it on these sites:
103+
104+
- [GitHub](https://github.com/farmergreg/vim-lastplace)
105+
- [Vim.org](http://www.vim.org/scripts/script.php?script_id=5090)
Lines changed: 36 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,36 @@
1+
*vim-lastplace* Intelligently reopen files where you left off.
2+
3+
Author: Gregory L. Dietsche <https://www.gregd.org/>
4+
License: MIT
5+
Version: 3.1.1
6+
7+
INTRODUCTION *vim-lastplace-introduction*
8+
9+
Intelligently reopen files where you left off. By default git,
10+
svn, and mercurial commit messages are ignored because you
11+
probably want to type a new message and not re-edit the previous
12+
one.
13+
14+
You can configure what file types to ignore by setting
15+
g:lastplace_ignore in your vimrc. This is a comma separated list.
16+
By default it is set to:
17+
18+
let g:lastplace_ignore = "gitcommit,gitrebase,svn,hgcommit"
19+
20+
You can configure buffer types to ignore by setting
21+
g:lastplace_ignore_buftype in your vimrc. This is a comma separated list.
22+
By default it is set to:
23+
24+
let g:lastplace_ignore_buftype = "quickfix,nofile,help"
25+
26+
Folds are automatically opened when jumping to the last edit position. If you
27+
do not like this behavior you can disable it by putting this in your vimrc:
28+
29+
let g:lastplace_open_folds = 0
30+
31+
ABOUT *vim-lastplace-about*
32+
33+
Get the latest version and/or report a bug on GitHub:
34+
https://github.com/farmergreg/vim-lastplace
35+
36+
vim:tw=78:et:ft=help:norl:
Lines changed: 80 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,80 @@
1+
" ============================================================================
2+
" File: vim-lastplace.vim
3+
" Description: Reopen files where you left off. Configurable.
4+
" Author: Gregory L. Dietsche <vim@gregd.org>
5+
" Licence: MIT
6+
" Website: https://www.gregd.org/
7+
" Version: 3.1.1
8+
" ============================================================================
9+
10+
if exists("b:loaded_lastplace_plugin") || &cp
11+
finish
12+
endif
13+
let b:loaded_lastplace_plugin = 1
14+
15+
scriptencoding utf-8
16+
17+
if !exists('g:lastplace_ignore')
18+
let g:lastplace_ignore = "gitcommit,gitrebase,svn,hgcommit"
19+
endif
20+
21+
if !exists('g:lastplace_open_folds')
22+
let g:lastplace_open_folds = 1
23+
endif
24+
25+
if !exists('g:lastplace_ignore_buftype')
26+
let g:lastplace_ignore_buftype = "quickfix,nofile,help"
27+
endif
28+
29+
fu! s:lastplace()
30+
if index(split(g:lastplace_ignore_buftype, ","), &buftype) != -1
31+
return
32+
endif
33+
34+
if index(split(g:lastplace_ignore, ","), &filetype) != -1
35+
return
36+
endif
37+
38+
try
39+
"if the file does not exist on disk (a new, unsaved file) then do nothing
40+
if empty(glob(@%))
41+
return
42+
endif
43+
catch
44+
return
45+
endtry
46+
47+
if line("'\"") > 0 && line("'\"") <= line("$")
48+
"if the last edit position is set and is less than the
49+
"number of lines in this buffer.
50+
51+
if line("w$") == line("$")
52+
"if the last line in the current buffer is
53+
"also the last line visible in this window
54+
execute "normal! g`\""
55+
56+
elseif line("$") - line("'\"") > ((line("w$") - line("w0")) / 2) - 1
57+
"if we're not at the bottom of the file, center the
58+
"cursor on the screen after we make the jump
59+
execute "normal! g`\"zz"
60+
61+
else
62+
"otherwise, show as much context as we can by jumping
63+
"to the end of the file and then to the mark. If we
64+
"pressed zz here, there would be blank lines at the
65+
"bottom of the screen. We intentionally leave the
66+
"last line blank by pressing <c-e> so the user has a
67+
"clue that they are near the end of the file.
68+
execute "normal! \G'\"\<c-e>"
69+
endif
70+
endif
71+
if foldclosed(".") != -1 && g:lastplace_open_folds
72+
"if we're in a fold, make the current line visible and recenter screen
73+
execute "normal! zvzz"
74+
endif
75+
endf
76+
77+
augroup lastplace_plugin
78+
autocmd!
79+
autocmd BufWinEnter * call s:lastplace()
80+
augroup END

0 commit comments

Comments
 (0)