3

I am trying to write vim function which should make window to go to previous open buffer. How can I do it from command line? My first suggest was to find out some CTRL-O command line alternative.

  • 1
    "which should go backwards at some point": What exactly should go backwards to where? Do you mean the cursor in the text buffer (e.g. as if you typed b in normal mode)? – Martin Tournoij Dec 4 '17 at 9:14
  • @Carpetsmoker, I have editet the qwestion to make subject more clear – ephemerr Dec 4 '17 at 9:23
  • Your question title does not really make sense together with the text. Please update the question and/or title to make this more useful for future visitors. – Karl Yngve Lervåg Dec 4 '17 at 13:42
  • Related post: How do I use the jumplist to jump once per file? – Peter Rincker Dec 4 '17 at 15:13
7

The jumplist is not the best way to do buffer navigation. Vim has a great number of buffer navigation tools which are probably better used for this task.

  • <c-^>/<c-6> - jump to the alternative file or if providing a count to a certain buffer number. See :h CTRL-6
  • :b - jump to a specific buffer. Takes buffer number or partial filename. See :h :b
  • :sb - split variant of :b
  • :ls/:buffers - list opened buffers. See :h :ls
  • # used to represent the alternative file which is often the previous buffer. e.g. :b#. See :h c_#
  • Common mapping nnoremap <leader>b :ls<cr>:b<space>

If you really do want to use the jump list you may want to look at Ingo Karkat's EnhancedJumps plugin or see vim-buffer-history plugin which is sort of similar.

  • Thank you for expanded answer. So b# command is the best solution of my problem. – ephemerr Dec 5 '17 at 7:21
0

I found the solution in use of normal command. There would be such a line in my function:

exe "normal \<C-O>"
  • 2
    That doesn't go to previous open buffer. It goes to the last position in your jump list which could be in the same buffer. What about Ctrl-^? – B Layer Dec 4 '17 at 10:06
  • 1
    Also you shouldn't need exe. Try normal! ^O where ^O is inserted by hitting Ctrl-V followed by Ctrl-O. – B Layer Dec 4 '17 at 10:10
  • good point. If i_Ctrl-v occupied, see :h i^v for alternative (usually Ctrl-q). Another approach is use digraph, in this case, in insert mode, first type Ctrl-k, then type Ctrl-o twice will insert Ctrl-o. – qeatzy Dec 5 '17 at 2:52

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.