Is there a command in vim that can bookmark a place (path to the file, line number in that file), so that I can go to that place easily later?
It would be similar as NERDTree :Bookmark command. You can open your file with NERDTreeFromBookmark. I’m looking for the same functionality with the difference that bookmark is not only a file but file + line number.
Thank you
The
viminfosetting can contain the option!, which makes it store any global variables with uppercase letters in the viminfo file. Using this, you can define a variable calledg:BOOKMARKSand store your bookmarks in there.Here’s some vimscript you could use to do that:
I’m not sure how readable the code is, but basically, the
Bookmarkcommand accepts a single parameter to use as a name. It will store the current filename and cursor position to theg:BOOKMARKSdictionary. You can use theGotoBookmarkcommand with a mark name to go to it.DelBookmarkworks in the same way, but deletes the given mark. Both functions are tab-completed.Another way to jump through them is by using this command:
CopenBookmarkswill load the bookmarks in the quickfix window, which seems like a nice interface to me.This solution is similar to Eric’s — it uses the
.viminfofile, so if something goes wrong with it, you’ll probably lose your marks. And if you save your marks in one vim instance, they won’t be immediately available in another.I don’t know how comfortable your are with vimscript, so just in case — to use this, you can put the code in a file under your
pluginvimfiles directory, for exampleplugin/bookmarks.vim. Should be completely enough. Here’s the entire code in a gist as well: https://gist.github.com/1371174EDIT: Changed the interface for the solution a bit. Original version can be found in the gist history.