0

I have <C-J> and <C-K> mapped to previous/next tab in Vim.

Sometimes when too many tabs are open in Vim, it will display only the last few characters of the current tab's file name in the tab label. When switching tabs, I get lost as to which file I'm currently looking at. (I have statusline disabled.)

How do I bind <C-J> to "switch tabs and show current file name"?

I tried :map <C-J> :tabNext<CR>:f<CR> but to no avail.

Jonas H.
  • 2,331
  • 4
  • 17
  • 23

2 Answers2

3

You need to force a redraw so that you can use :file. e.g.

nnoremap gt gt:redraw<bar>file<cr>

For more help see:

:h gt
:h :redraw
:h :file

Aside about tabs

Vim's tabs are not like most text editors' tabs.

Let me repeat that: Vim's tabs are not like most text editors' tabs.

Vim's tabs are more like viewports into a group of windows/splits. Additionally, Vim is buffer centric, not tab centric like most editors. Therefore using features like the quickfix list is often easier without tabs (See :h 'switchbuf' if you must use tabs). Vim's tabs often get in the way of a good window & buffer workflows, as there are better window and buffer navigation commands available. I personally have many files open (often 50+ buffers). I rarely use tabs and use on average 1-2 splits without any issue. You may want to read the following posts:

Best practices with Vim mappings

Two general rule of thumbs for making mappings:

  • Supply a mode. So :map becomes :nmap
  • Unless using a <Plug> or <SID> mapping you should probably be using :noremap variant, e.g. nnoremap, xnoremap, etc. Using this will prevent recursive mapping.

This means:

map <c-j> ...

becomes:

nnoremap <c-j> ...
Peter Rincker
  • 43,539
  • 9
  • 74
  • 101
0

According to vim wikia you can add :echo @% command to print in your status line. You can even use echom instead of echo if you want to store it in your logs.

LLenain
  • 549
  • 1
  • 7
  • 12