InfoHeap
Tech tutorials, tips, tools and more
Navigation
  • Home
  • Tutorials
    • CSS tutorials & examples
    • CSS properties
    • Javascript cookbook
    • Linux/Unix Command Line
    • Mac
    • PHP
      • PHP functions online
      • PHP regex
    • WordPress
  • Online Tools
    • Text utilities
    • Online Lint Tools
search

Vim tutorials

  • Character toggle case
  • Go back to last edited line
  • Move to matching bracket
  • Multiline search replace with confirmation
  • Open vim at previous location
  • Vim mini cheat sheet
  • Vim redo (undo of last undo)
  • show line numbers
 
  • Home
  • > Tutorials
  • > Vim

How to open vim at previous location

By admin on Dec 1, 2015

Vi (or Vim) editor can remember location at the time of exiting a file. This can be fairly convenient while editing files during development.

.vimrc autocmd code for opening vi at previous location

Add the following code to ~/.vimrc file.

au BufWinLeave ?* mkview
au BufWinEnter ?* silent loadview

or

autocmd BufWinLeave ?* mkview
auautocmd BufWinEnter ?* silent loadview

Note that ?* tells vi to run autocmd only if it was opend with a filename.

Testing above code

Open vi and create a file (say foo.txt) and enter few lines to it. Save the file and exit vi. Now when you reopen foo.txt in vi, it should open with cursor at the previous location as shown below:
vi-file-open-at-previous-location

Suggested posts:

  1. How to find python package’s file location
  2. Mac – how to change default location for screenshots
  3. Mac command line utility open – some handy tips for better productivity
  4. Apache – add basic auth to a location or directory
  5. Linux/Unix – How to go to previous directory
  6. Mac – open Finder from terminal – quick tip
  7. node – how to find source file location of a module
  8. Bash – how to get main program and current file dir location
Share this article: share on facebook share on linkedin tweet this submit to reddit
Posted in Tutorials | Tagged Linux, Mac, Tutorials, Ubuntu Linux, Vim
  • Browse content
  • Article Topics
  • Article archives
  • Contact Us
Popular Topics: Android Development | AngularJS | Apache | AWS and EC2 | Bash shell scripting | Chrome developer tools | CSS | CSS cookbook | CSS properties | CSS Pseudo Classes | CSS selectors | CSS3 | CSS3 flexbox | Devops | Git | HTML | HTML5 | Java | Javascript | Javascript cookbook | Javascript DOM | jQuery | Kubernetes | Linux | Linux/Unix Command Line | Mac | Mac Command Line | Mysql | Networking | Node.js | Online Tools | PHP | PHP cookbook | PHP Regex | Python | Python array | Python cookbook | SEO | Site Performance | SSH | Ubuntu Linux | Web Development | Webmaster | Wordpress | Wordpress customization | Wordpress How To | Wordpress Mysql Queries

Copyright © 2023 InfoHeap.

Powered by WordPress