InfoHeap
Tech
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. Mac – how to take screenshots
  2. node – how to fix cannot find module error
  3. Mac – how to take timed screenshot
  4. PhantomJS – find all fonts-families on a web page
  5. Disable directory listing in apache
  6. Bash – how to use functions – quick tutorial
  7. Use universal selector to get all DOM nodes in vanilla Javascript
  8. How to monitor 404 pages on your site
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 | Company results | 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 | InfoHeap Money

Copyright © 2025 InfoHeap.

Powered by WordPress