vim open file in a new tab
When inside vim, I use
:tabnew filename
to open a file in a new tab.
From the terminal, you can do vim -p filename1 filename2
to open the two files in tabs.
I have added the following lines to my .vimrc
that allow me to switch between tabs easily.
nnoremap <C-Left> :tabprevious<CR>
nnoremap <C-Right> :tabnext<CR>
nnoremap <C-j> :tabprevious<CR>
nnoremap <C-k> :tabnext<CR>
C
stands for the Ctrl key. Thus, I can do Ctrl-Right
or Ctrl-k
to switch to the next tab, and likewise for the previous.
This works for me.
For those using tmux - I have mapped Ctrl-h
and Ctrl-l
for switching windows in tmux. Thus, using the Ctrl key, and h,j,k,l, I am able to switch between all of tmux windows and vim tabs.
EDIT : I did not know this when I asked this question, but you really should avoid tabs to simply manage switching between multiple open files. Use buffers instead. Today, I have
nnoremap <C-j> :bprev<CR>
nnoremap <C-k> :bnext<CR>