Vim is not remembering last position

1
W

riting shell scripts in vim I usually go search for functions or something. Copy lines and then go back to where I was and modify the code. However, I need to manually navigate way back to the previous / last position. How can I automatically go back to where I was when I started my search operation under vim?


Vim is a text editor that is upwards compatible to Vi. It supports the following markers and moving about keys:

[a] '. : Jump to last modification line.

[b] `. : Jump to exact spot in last modification line

[c] CTRL-O : Retrace your movements in file in backwards.

[d] CTRL-I : Retrace your movements in file in forwards.
From the vim help files:

Jumps are remembered in a jump list. With the CTRL-O and CTRL-I command you can go to cursor positions before older jumps, and back again. Thus you can move up and down the list. There is a separate jump list for each window. The maximum number of entries is fixed at 100.

...
0 0
2
I like the '. command in vim. From :help '.: '. `. [Jump to] the position where the last change was made. The position is at or near where the change started. Ok. But here's my problem: I use an autocmd function to add a "last modified" line in my file header. So, after every write, '. brings me not to my "real" last change, but to my file header. My current solution is I try to remember to mark my current editing point with ma, so I can 'a to return to it. I sometimes forget, though, and even when I remember, it's another couple keystrokes. My ideal solution would be some sort of command that tells vim not to remember movements. I could send this command before the autocmd function jumps around, writing the last modified line, and then cancel it after the autocmd function has finished. That way, the location associated with '. would not be changed. However, I'm open to any other options that are more efficient. In case you want to see it, here's what the autocmd does on :w. function!...
0 0
3

To add to dnetserr's answer and Peter Rincker's comment, Vim maintains a list of changes, and has some commands associated with this.

:changes

will list the changes, showing you where they were and what they were. For example:

change line col text 2 8 17 #include 1 3 0 #include "stm32f407.auto.h" >

The line with the > shows where in the change stack you are, kind of like the jump list (:jumps) or tag stack (:tags). Also like the jump list and tag stack, you can traverse this list.

In normal mode, the motions are g; to go to a previous change location, and g, to go to the next one. You can also type the number of the change prior to g; or g, to go to that change from the list. Above, 2g; would take me to where the change involving stdio.h occurred.

When in the middle of the stack, the numbers from :changes updates to show the relative distances. For example:

change line col text 1 8 17 #include > 0 3 0 #include "stm32f407.auto.h" ...
0 0
4
main help file *usr_07.txt* Nvim VIM USER MANUAL - by Bram Moolenaar Editing more than one file No matter how many files you have, you can edit them without leaving Vim. Define a list of files to work on and jump from one to the other. Copy text from one file and put it in another one. |07.1| Edit another file |07.2| A list of files |07.3| Jumping from file to file |07.4| Backup files |07.5| Copy text between files |07.6| Viewing a file |07.7| Changing the file name Next chapter: |usr_08.txt| Splitting windows Previous chapter: |usr_06.txt| Using syntax highlighting Table of contents: |usr_toc.txt| ============================================================================== *07.1* Edit another file So far you had to start Vim for every file you wanted to edit. There is a simpler way. To start editing another file, use this command: :edit foo.txt You can use any file name instead of "foo.txt". Vim will close the current file and open the new one. If the current file has...
0 0
5

Each time I re-open a file with vi (vim actually), the very beginning of the file is shown. If I just want to add something at the end of the file, I could quickly go to the end by pressing Shift-g. But most of the time, I need to go to where I was working on in the middle of the file. Then I have to remember some strings or phrases to search, or go down page by page. That would be a headache to a lazy people like me.

Fortunately, VIM can memorize the last position for me. In its configuration file ~/.vimrc, add these lines at the end:

" Only do this part when compiled with support for autocommands if has("autocmd") " When editing a file, always jump to the last cursor position autocmd BufReadPost * \ if line("'\"") > 0 && line...
0 0
6
#467057 - /etc/vim/vimrc: Sample "jump to last position" does not work if 'g' remapped - Debian Bug report logs

Report forwarded to debian-bugs-dist@lists.debian.org, Debian VIM Maintainers :
Bug#467057; Package vim-common. (full text, mbox, link).

Acknowledgement sent to Andrew McCarthy :
New Bug report received and forwarded. Copy sent to Debian VIM Maintainers . (full text, mbox, link).

Message #5 received at submit@bugs.debian.org (full text, mbox, reply):

Package: vim-common Version: 1:7.1-241+1 Severity: minor File: /etc/vim/vimrc In Debian's /etc/vim/vimrc the following example appears: " Uncomment the following to have Vim jump to the last position when " reopening a file "if has("autocmd") " au BufReadPost * if line("'\"") > 0 && line("'\"") 0 && line("'\"") use normal! instead of normal to avoid triggering maps when calling g'". In what file? - Bram -- It was recently discovered that research causes cancer in rats. /// Bram Moolenaar --...
0 0
7
The VI Gang Sign

by Jon Beltran de Heredia, May 16th, 2007

Yes, even if you can't believe it, there are a lot fans of the 30-years-old vi editor (or its more recent, just-15-years-old, best clone & great improvement, vim).

No, they are not dinosaurs who don't want to catch up with the times - the community of vi users just keeps growing: myself, I only got started 2 years ago (after over 10 years of being a professional programmer). Friends of mine are converting today. Heck, most vi users were not even born when vi was written!

Yes, there are definite reasons why the vi/vim editing model is just superior to any other out there. And you don't need to be a Unix whiz to use it, either: vim is available for free for almost any platform out there, and there are plug-ins to get the functionality inside all major IDEs. Let's try to break a few misconceptions, and see some real examples of why it's the...

0 0
8

John Lennon’s last interview, taken on December 8, 1980 just few hours before his murder. John and Yoke were interviewed by Dave Sholin and Laurie Kaye. Ron Hummel and Bert Keane were also part of that team. John had just finished a photo session with Annie Leibovitz for Rolling Stone magazine.

John talks about growing up Sean, the new album after five years, being separated from Yoko, how they meet in 1966 and their love and peace campaign and much more.

JOHN: “Ah… I’m sorry I’m late. I kept expecting her to buzz me but she kept sayin’ ‘One more, one more.’ Are we on?”
YOKO: “Yes dear, we’re on, we’re on.”
JOHN: “Well, what do I do? Are you doing one and then the other? Or… ”
YOKO: “No, it’s because we were just waiting… ”
JOHN: “Oh, I’m sorry. I’d just put on me jacket to leave and she said, ‘Ooh, can I have one with the jacket?’ So we took one with the jacket. “Dahling!” “Well, hello.”

JOHN: “What’s that! Oh, it’s a microphone....

0 0
9
LETTERS TO THE EDITOR 2017
Previous Letters to Editor Page

Letters To The Editor must include a name and contact (phone/email) and may be Emailed to
Editor or addressed to: Letters to the Editor, 1871 Whitehaven Road, Grand Island, NY 14072

We just would like to give the caring people of the Carter Drive area a big thank you for giving Jazz all the treats, love and hugs on our many walks. She was a special dog who was loved by all. She crossed the rainbow bridge on December 19, 2017. She will be missed by all.


Ann & Denny Dahl

I would like to give a very heartfelt THANK YOU to all the residents of Grand Island. The opportunity to serve as your Highway Superintendent for the past 8 years was both humbling and life changing. I really love what we have accomplished and the progress we made. But I am mostly proud to have carried on the systems and traditions of my predecessors, Norm Mrkall and the late Ray Dlugokinski. Ray was an extremely thoughtful...

0 0
10
...
0 0
11

We're tool makers and tool users. Embedded developers - both those doing hardware work and those crafting firmware - use a wide range of tools, but it can be awfully hard to distinguish the good from the ugly. Here's thoughts from a number of engineers. Feel free to submit your own reviews to jack@ganssle.com.

Jack has written some extensive reviews of test equipment:

Scopes, logic analyzers, spectrum analyzers and signal generators: Siglent's SDS1204X-E four channel, 200 MHz scope. Here's a video review. Agilent's MSO-X 3054A mixed signal scope. Tektronix's MSO2024 mixed signal scope. Tektronix's MDO4104 mixed domain scope (i.e., it has a spectrum analyzer as well). Gabotronics Xprotolab tiny little $49 mixed signal scope. Philco's 7019 65-year-old scope is pretty awful but a ton of fun. Siglent's SDS1102CML oscilloscope. And here's a video about it I made, plus another. GW Instek's GDS-1052-U is a $300 bench scope....
0 0
12

(ed note: In the Cluster novels, the quotation mark symbols denote which species-language is being used. " is for humans, * is for Asts (looks like a mass of coils), / is for Slashes (looks like a living disk harrow, shooting laser beams), and :: is for Quadpointers (looks like a slug with four chisles on its nose). The protagonist Herald the Healer is a Slash.)

Whorl twined to another section of his convolute residence, and Herald followed. Here in the living rock bordering a corkscrew chamber was emblazoned in relief a creature-sized Shield of Arms.

It was beautiful. The outer shield was in the shape of an ellipse set at an angle, representing Galaxy Andromeda, bordered inside by a wreath of intertwining serpents to designate Sphere Ast. Within that were the Family Arms of Precipice, resembling an ornate overhanging cliff. Herald moved his loops across it, savoring its aspects. It had superior form, texture, and color, and was, in its fashion, a genuine work of art....

0 0