From bd8a709119312e747084b8c93acea646e07ca5bd Mon Sep 17 00:00:00 2001 From: Marco Hinz Date: Sat, 9 Jan 2016 16:12:30 +0100 Subject: [PATCH] Usage: restore cursor position when opening file --- CHANGELOG.md | 1 + README.md | 19 +++++++++++++++++++ 2 files changed, 20 insertions(+) diff --git a/CHANGELOG.md b/CHANGELOG.md index b7613e6..a3b71a7 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -9,6 +9,7 @@ All notable changes to this project will be documented in this file. - Basics: [Marks?](README.md#marks) - Tips: [Saner command-line history](README.md#saner-command-line-history) - Usage: [Editing remote files](README.md#editing-remote-files) +- Usage: [Restore cursor position when opening file](#restore-cursor-position-when-opening-file) - Debugging: [Verbosity](README.md#verbosity) - Debugging: [Debugging Vim scripts](README.md#debugging-vim-scripts) - Debugging: [Debugging syntax files](README.md#debugging-syntax-files) diff --git a/README.md b/README.md index bdaf057..d67ccdf 100644 --- a/README.md +++ b/README.md @@ -30,6 +30,7 @@ added every day. Things about to be added can be found here: - [Clipboard theory (Windows, OSX)](#clipboard-theory-windows-osx) - [Clipboard theory (Linux, BSD, ...)](#clipboard-theory-linux-bsd-) - [Clipboard usage](#clipboard-usage) +- [Restore cursor position when opening file](#restore-cursor-position-when-opening-file) - [Editing remote files](#editing-remote-files) - [Managing plugins](#managing-plugins) - [Block insert](#block-insert) @@ -636,6 +637,24 @@ Vim comes with a pretty extensive documentation: :h gui-clipboard :h gui-selections ``` +#### Restore cursor position when opening file + +Without this, you will always be at line 1 when opening a file. With this, you +will be at the position where you left off. + +Put this in your vimrc: +```viml +autocmd BufReadPost * + \ if line("'\"") > 1 && line("'\"") <= line("$") | + \ exe "normal! g`\"" | + \ endif +``` + +This simpy does `` g`" `` (jump to position where you left off without changing +jumplist) if that position still exists (the file might have fewer lines since +it was altered by another program). + +This requires the use of a viminfo file: `:h viminfo-'`. #### Editing remote files