Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 6809695
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 26, 20262026-05-26T20:06:59+00:00 2026-05-26T20:06:59+00:00

Is there a command in vim that can bookmark a place (path to the

  • 0

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

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-05-26T20:07:00+00:00Added an answer on May 26, 2026 at 8:07 pm

    The viminfo setting 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 called g:BOOKMARKS and store your bookmarks in there.

    Here’s some vimscript you could use to do that:

    set viminfo+=!
    
    if !exists('g:BOOKMARKS')
      let g:BOOKMARKS = {}
    endif
    
    " Add the current [filename, cursor position] in g:BOOKMARKS under the given
    " name
    command! -nargs=1 Bookmark call s:Bookmark(<f-args>)
    function! s:Bookmark(name)
      let file   = expand('%:p')
      let cursor = getpos('.')
    
      if file != ''
        let g:BOOKMARKS[a:name] = [file, cursor]
      else
        echom "No file"
      endif
    
      wviminfo
    endfunction
    
    " Delete the user-chosen bookmark
    command! -nargs=1 -complete=custom,s:BookmarkNames DelBookmark call s:DelBookmark(<f-args>)
    function! s:DelBookmark(name)
      if !has_key(g:BOOKMARKS, a:name)
        return
      endif
    
      call remove(g:BOOKMARKS, a:name)
      wviminfo
    endfunction
    
    " Go to the user-chosen bookmark
    command! -nargs=1 -complete=custom,s:BookmarkNames GotoBookmark call s:GotoBookmark(<f-args>)
    function! s:GotoBookmark(name)
      if !has_key(g:BOOKMARKS, a:name)
        return
      endif
    
      let [filename, cursor] = g:BOOKMARKS[a:name]
    
      exe 'edit '.filename
      call setpos('.', cursor)
    endfunction
    
    " Completion function for choosing bookmarks
    function! s:BookmarkNames(A, L, P)
      return join(sort(keys(g:BOOKMARKS)), "\n")
    endfunction
    

    I’m not sure how readable the code is, but basically, the Bookmark command accepts a single parameter to use as a name. It will store the current filename and cursor position to the g:BOOKMARKS dictionary. You can use the GotoBookmark command with a mark name to go to it. DelBookmark works 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:

    " Open all bookmarks in the quickfix window
    command! CopenBookmarks call s:CopenBookmarks()
    function! s:CopenBookmarks()
      let choices = []
    
      for [name, place] in items(g:BOOKMARKS)
        let [filename, cursor] = place
    
        call add(choices, {
              \ 'text':     name,
              \ 'filename': filename,
              \ 'lnum':     cursor[1],
              \ 'col':      cursor[2]
              \ })
      endfor
    
      call setqflist(choices)
      copen
    endfunction
    

    CopenBookmarks will 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 .viminfo file, 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 plugin vimfiles directory, for example plugin/bookmarks.vim. Should be completely enough. Here’s the entire code in a gist as well: https://gist.github.com/1371174

    EDIT: Changed the interface for the solution a bit. Original version can be found in the gist history.

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

Is there a command-line argument that would force firefox.exe to launch a new process
I recently found that there is a command in Vim called compiler. You can
Im wondering if there is a command in V/Vim that will save a backup
There's a command in VIM where you can say how many chars to replace,
Is there a command that would allow me to check if the string xyz
I'm wondering if there's a command in Vim I'm missing that does columnar motion.
Is there any command in vim with which I can jump to an already
Is there a command in classic ASP I can use to tell the browser
Is there a command within the bash shell of fedora that will give me
Is there a command like cat in linux which can return a specified quantity

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.