Git Product home page Git Product logo

vim-lastplace's Introduction

vim-lastplace v4.4.1

A vim / nvim plugin that intelligently reopens files at your last edit position.

Features

  • Immediately jump to the last edit position when editing a file.
  • Commit Messages
    • Many version control systems re-use the same file for commit message editing.
    • It does not make sense in this case to jump to the last edit position.
    • vim-lastplace automatically detects this and starts with your cursor at the beginning of the file.
  • Maximize Context
    • Center the cursor vertically after restoring last edit position.
    • Keep as much of the file on screen as possible when last edit position is at the end of the file.
  • Opens folds if the last edit position is inside a fold.
  • Works properly with new file templates and scripts that jump to a specific line.

Install

vim:

You can install vim-lastplace as a vim plugin without any additional tools when using vim 8 or newer.

mkdir -p ~/.vim/pack/plugins/start
rm -rf ~/.vim/pack/plugins/start/vim-lastplace
git clone --depth=1 https://github.com/farmergreg/vim-lastplace.git ~/.vim/pack/plugins/start/vim-lastplace

neovim:

You can also install vim-lastplace and use it with neovim:

mkdir -p ~/.local/share/nvim/site/pack/plugins/start
rm -rf ~/.local/share/nvim/site/pack/plugins/start/vim-lastplace
git clone --depth=1 https://github.com/farmergreg/vim-lastplace.git ~/.local/share/nvim/site/pack/plugins/start/vim-lastplace

Configure

You can configure what file types to ignore by setting g:lastplace_ignore in your vimrc. This is a comma separated list. By default it is set to:

    let g:lastplace_ignore = "gitcommit,gitrebase,svn,hgcommit"

You can configure buffer types to ignore by setting g:lastplace_ignore_buftype in your vimrc. This is a comma separated list. By default it is set to:

    let g:lastplace_ignore_buftype = "quickfix,nofile,help"

Closed folds are automatically opened when jumping to the last edit position. If you do not like this behavior you can disable it by placing this in your vimrc:

    let g:lastplace_open_folds = 0

Conflicting Scripts:

Depending on which vim package you're using, vim may be preconfigured with last-edit-position logic that doesn't work as well as vim-lastplace. If so, you may want to disable that in favor of vim-lastplace. For example, for Vim as packaged with Git for Windows, you can edit C:\Program Files\Git\etc\vimrc and comment out the "Remember positions in files" autocmd BufReadPost * block.

Miscellaneous

This plugin is complete and stable. Please do not be afraid to try it even if there is very little recent activity in this repository. If you do find a bug, please submit a pull request that fixes whatever problem you're having.

Version History

vim-lastplace uses semver to manage version numbers.

4.4.1

- Unreleased
- Improve README.md

4.4.0

  • Release Date: 2023-08-24
  • Use keepjumps to prevent the addition of unwanted marks.
  • Fix a bug with folds not opening. (Issue #30)
  • Fix a bug when using multiple windows (Issue #28)
  • Documentation Updates
    • vim8 installation documentation
    • nvim installation documentation
    • various other improvements
    • pre-generated helptags

3.2.1

  • Release Date: 2020-01-20
  • Re-center screen when opening folds
  • Documentation fixes and updates

3.1.1

  • Release Date: 2017-06-19
  • Add 'nofile' and 'help' to lastplace_ignore_buftype. (Issue #14)
  • Do not jump when a new file is created (Issue #15, #16)

3.1.0

  • Release Date: 2017-02-21
  • Add g:lastplace_ignore_buftype setting.
  • Update github links from username dietsche to farmergreg.

3.0.4

  • Release Date: 2016-09-06
  • Add g:lastplace_open_folds option.

3.0.3

  • Release Date: 2016-08-08
  • Point release for Debian packaging. Changes all http links to https. No code changes.

3.0.2

  • Release Date: 2016-05-12
  • A fix for files that are smaller than the current screen size (issue #8)

3.0.1

  • Release Date: 2016-01-16
  • A fix for files with modelines.

3.0.0

  • Release Date: 2015-06-14
  • Open folds if the last edited area is inside a closed fold.

2.0.1

  • Release Date: 2015-01-23
  • Add gitrebase filetype to the ignore list.

2.0.0

  • Release Date: 2015-01-22
  • Center the screen when restoring the cursor position.
  • When at the end of a file, keep as much of it on screen as possible.

1.0.0

  • Release Date: 2015-01-14
  • Initial version.

About

Get the latest version, submit pull requests, and file bug reports on GitHub:

If you like this plugin, please star and rate it on these sites:

vim-lastplace's People

Contributors

adelarsq avatar farmergreg avatar jebaum avatar joshkel avatar natweiss avatar nzbart avatar odedlaz avatar samoshkin avatar somini avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar

vim-lastplace's Issues

Maintain Scroll Position

It may be nice to try and restore the scroll position in addition to the last place that was edited. Various challenges would have to be dealt with including:

  • windows of different heights
  • scrolloff settings that are non zero
  • other??

A naive implementation could be realized by following this outline:

  • Ask the user set set viminfo+=! in their .vimrc
  • BufWinLeave: save line("w0") in a global variable that is persisted due to viminfo ! flag being set
  • BufWinEnter : jump to saved w0, then to '"

vim-lastplace does not work with templates

I'm attempting to use a default template for new Perl files with this command:

autocmd BufNewFile *.pl 0r ~/.vim/perl/base_template.pl

I would like Vim to start the cursor on Line 11 of the template which is done like this:

autocmd BufNewFile *.pl 0r ~/.vim/perl/base_template.pl | 11

With vim-lastplace enabled when I create a new .pl file it loads the template but always puts the cursor on line 0. If I disable vim-lastplace then it starts on line 11.

global disable or add check for vimdiff

I would like to use vim-lastplace, but want to disable this for vimdiff.
I could disable it with code like:

if &diff
    let g:lastplace_disable = "on"
endif

in my .vimrc, if we had such a global disable var. Do you think there is another way ?
Thank you for vim-lastplace.

vim-lastplace scrolls the file by one line from top

Hi, thanks for this nice plugin.

There's one small issue with it which is a bit annoying, it does preserve cursor location when I open a file, but it scrolls the file one line, hiding the top line, when used, even if I closed the file without scrolling it at all.

Plugin automatically expands folded text

Hello! Thank you for your plugin.
I have an issue with your and Fold-License plugin. When If I open the file for the first time, the license of the file is opened automatically. Is it possible to keep license folded?
Tested on this project.

Add note about `:h last-position-jump`, available out-of-the-box in recent versions of Vim

Consider adding a note that this plugin isn't needed in Vim 8+ onwards.

:h last-position-jump

One can have this behavior out-of-the-box with the following in ~/.vimrc (see :h skip_defaults_vim):

unlet! skip_defaults_vim
source $VIMRUNTIME/defaults.vim

The magic setting is this part:

  " Put these in an autocmd group, so that you can revert them with:
  " ":augroup vimStartup | au! | augroup END"
  augroup vimStartup
    au!

    " When editing a file, always jump to the last known cursor position.
    " Don't do it when the position is invalid, when inside an event handler
    " (happens when dropping a file on gvim) and for a commit message (it's
    " likely a different one than last time).
    autocmd BufReadPost *
      \ if line("'\"") >= 1 && line("'\"") <= line("$") && &ft !~# 'commit'
      \ |   exe "normal! g`\""
      \ | endif

  augroup END

endif

I mean, I am sure your plugin does more than that, and I am not advocating for you to delete it. However, it would be nice to warn users that the basic functionality for it ships out-of-the-box with recent versions of vim. It would be even better if the diff parts of this plug-in compared to the status quo were merged upstream - but hey, one step at a time.

Nonetheless, great job in your repository management - This is one of the fewest I found with all issues and pull requests closed.

Option for opening folds if the last edited area is inside a closed fold

I'd like to feature request an option for this feature of automatically opening folds, personally I don't like it because sometimes when opening a file one wants to check another position in the file and not care about the last one or the last fold, which sometimes one even wishes to keep closed because of that.

Keep horizontal position

Hi,

Would be nice to be able to keep the cursor position as well.

Example (_ is the cursor):

line
line _line
line

When we reopen the file, the cursor goes to the first position:

line
_line line
line

What you think?

One problem I see is that we would have to deal with lines where no longer large as the last position, in that case I think going to the last position would be okay.

vim-lastplace can not work well with latest vim

I use vim-lastplace under some environment such as ubuntu14, lubuntu14, lubuntu18.

In the ubuntu14, lubuntu14, vim-lastplace work very well.
However, in the lubuntu18, vim-lastplace can not work well with latest vim.
The cursor is always on the first line, no matter which line was last opened

vim --version
VIM - Vi IMproved 8.0 (2016 Sep 12, compiled Apr 10 2018 21:31:58)
Included patches: 1-1453

lsb_release -d
Description: Ubuntu 18.04 LTS

vim-lastplace conflicts with vim-buffergator

The recent commit conflicts with vim-buffergator.

Error detected while processing function <SNR>38_lastplace:
line    2:
E16: Invalid range
E16: Invalid range

The conflict was introduced at the commit f1c8989ea6af5ed297d7d622d190a86cc86f7681, the commit 36c4ae38130232134ece7bdd0e844d8034b585ab works.

Maybe I could change the default setting to ignore vim-buffergator list window, but I do not know vim-buffergator list window type or name.

    let g:lastplace_ignore = "gitcommit,gitrebase,svn,hgcommit"
    let g:lastplace_ignore_buftype = "quickfix,nofile,help"

Error Message:"Need to specify how to reconcile divergent branch"

I am running vim on popos 22 (linux).

I have been using lastplace plugin for years without issue.

BUT today ... I received the following ERROR message while doing a PluginUpdate

image

Sorry I don't know how to follow the hint "git config --global"

Any help much appreciated.

DL


My VIM version:

VIM - Vi IMproved 9.0 (2022 Jun 28, compiled May 10 2022 08:40:37)
Included patches: 1-749
Modified by [email protected]
Compiled by [email protected]
Huge version with GTK3 GUI. Features included (+) or not (-):
+acl +file_in_path +mouse_urxvt -tag_any_white
+arabic +find_in_path +mouse_xterm +tcl
+autocmd +float +multi_byte +termguicolors
+autochdir +folding +multi_lang +terminal
-autoservername -footer -mzscheme +terminfo
+balloon_eval +fork() +netbeans_intg +termresponse
+balloon_eval_term +gettext +num64 +textobjects
+browse -hangul_input +packages +textprop
++builtin_terms +iconv +path_extra +timers
+byte_offset +insert_expand +perl +title
+channel +ipv6 +persistent_undo +toolbar
+cindent +job +popupwin +user_commands
+clientserver +jumplist +postscript +vartabs
+clipboard +keymap +printer +vertsplit
+cmdline_compl +lambda +profile +vim9script
+cmdline_hist +langmap -python +viminfo
+cmdline_info +libcall +python3 +virtualedit
+comments +linebreak +quickfix +visual
+conceal +lispindent +reltime +visualextra
+cryptv +listcmds +rightleft +vreplace
+cscope +localmap +ruby +wildignore
+cursorbind +lua +scrollbind +wildmenu
+cursorshape +menu +signs +windows
+dialog_con_gui +mksession +smartindent +writebackup
+diff +modify_fname +sodium +X11
+digraphs +mouse +sound -xfontset
+dnd +mouseshape +spell +xim
-ebcdic +mouse_dec +startuptime +xpm
+emacs_tags +mouse_gpm +statusline +xsmp_interact
+eval -mouse_jsbterm -sun_workshop +xterm_clipboard
+ex_extra +mouse_netterm +syntax -xterm_save
+extra_search +mouse_sgr +tag_binary
-farsi -mouse_sysmouse -tag_old_static
system vimrc file: "$VIM/vimrc"
user vimrc file: "$HOME/.vimrc"
2nd user vimrc file: "/.vim/vimrc"
user exrc file: "$HOME/.exrc"
system gvimrc file: "$VIM/gvimrc"
user gvimrc file: "$HOME/.gvimrc"
2nd user gvimrc file: "
/.vim/gvimrc"
defaults file: "$VIMRUNTIME/defaults.vim"
system menu file: "$VIMRUNTIME/menu.vim"
fall-back for $VIM: "/usr/share/vim"
Compilation: gcc -c -I. -Iproto -DHAVE_CONFIG_H -DFEAT_GUI_GTK -pthread -I/usr/include/gtk-3.0 -I/usr/include/at-spi2-atk/2.0 -I/usr/include/at-spi-2.0 -I/usr/include/dbus-1.0 -I/usr/lib/x86_64-linux-gnu/dbus-1.0/include -I/usr/include/gtk-3.0 -I/usr/include/gio-unix-2.0 -I/usr/include/cairo -I/usr/include/pango-1.0 -I/usr/include/harfbuzz -I/usr/include/pango-1.0 -I/usr/include/fribidi -I/usr/include/harfbuzz -I/usr/include/atk-1.0 -I/usr/include/cairo -I/usr/include/pixman-1 -I/usr/include/uuid -I/usr/include/freetype2 -I/usr/include/gdk-pixbuf-2.0 -I/usr/include/libpng16 -I/usr/include/x86_64-linux-gnu -I/usr/include/libmount -I/usr/include/blkid -I/usr/include/glib-2.0 -I/usr/lib/x86_64-linux-gnu/glib-2.0/include -Wdate-time -g -O2 -ffile-prefix-map=/build/vim-cdpF6P/vim-9.0.0749=. -flto=auto -ffat-lto-objects -flto=auto -ffat-lto-objects -fstack-protector-strong -Wformat -Werror=format-security -D_REENTRANT -U_FORTIFY_SOURCE -D_FORTIFY_SOURCE=1
Linking: gcc -L. -Wl,-Bsymbolic-functions -Wl,-z,relro -Wl,-z,now -fstack-protector-strong -rdynamic -Wl,-export-dynamic -Wl,-E -Wl,-Bsymbolic-functions -flto=auto -ffat-lto-objects -flto=auto -Wl,-z,relro -Wl,-z,now -Wl,--as-needed -o vim -lgtk-3 -lgdk-3 -lpangocairo-1.0 -lpango-1.0 -lharfbuzz -latk-1.0 -lcairo-gobject -lcairo -lgdk_pixbuf-2.0 -lgio-2.0 -lgobject-2.0 -lglib-2.0 -lSM -lICE -lXpm -lXt -lX11 -lXdmcp -lSM -lICE -lm -ltinfo -lselinux -lcanberra -lsodium -lacl -lattr -lgpm -L/usr/lib -llua5.2 -Wl,-E -fstack-protector-strong -L/usr/local/lib -L/usr/lib/x86_64-linux-gnu/perl/5.34/CORE -lperl -ldl -lm -lpthread -lcrypt -L/usr/lib/python3.10/config-3.10-x86_64-linux-gnu -lpython3.10 -lcrypt -ldl -lm -lm -L/usr/lib/x86_64-linux-gnu -ltcl8.6 -ldl -lz -lpthread -lm -lruby-3.0 -lm -L/usr/lib

Alternate buffer not restoring cursor position with window splits

Sometimes I am editing a file a.txt and I want to reference two separate locations while editing. For this I usually split the window. I will also often switch between the alternate buffer b.txt for another reference. Under some circumstances (detailed below), this plugin prevents restoring the cursor to the last buffer position when switching alternate buffers. Here are two recordings:

In both cases I:

  • Open a.txt for editing. Note that the cursor starts on line 3 (the '" marks's location)
  • Use 'G' to view the bottom of a.txt
  • Split my window with <c-w>s
  • Refocus the top window to the top of a.txt and open b.txt for editing in the lower window
  • Use <c-6> to switch to alternate buffer repeatedly in the lower window

If I open a.txt for editing and the '" mark is positioned on line 1, this issue does not occur.

The first with this plugin installed:
When switching from b.txt to a.txt as the alternate buffer with this plugin installed, the cursor is returned to line 3, where my file was opened (the '" mark). This loss of context removes the benefit of having an alternate buffer for reference.

lastplace.mp4

Without the plugin installed:

no-lastplace.mp4

Without the plugin installed everything works as expected. I also tested without loading my .vimrc which also functioned properly. I am using Neovim 0.6 if that makes a difference.

Last place centering

It would be nice if it was possible to center the line on the screen instead of being at the bottom. Maybe a zz would handle it?

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.