Scenario: I have opened Vim and pasted some text. I open a second tab with :tabe and paste some other text in there.
Goal: I would like a third tab with a output equivalent to writing both texts to files and opening them with vimdiff.
The closest I can find is "diff the current buffer against a file", but not diffing two open but unsaved buffers.
I suggest opening the second file in the same tab instead of a new one.
Here's what I usually do:
:edit file1
:diffthis
:vnew
:edit file2
:diffthis
The :vnew command splits the current view vertically so you can open the second file there. The :diffthis (or short: :difft) command is then applied to each view.
I would suggest trying :diffthis or :diffsplit
When you have two files opened in vertical splitt, run
:windo diffthis
The content of all tabs are inside the buffers.
Look at the buffers:
:buffers
Find the right number for the content which should be diffed with your current tab content.
Open the buffer inside your current tab (f.e. buffer number 4)
:sb 4
Or do for vertical view:
:vertical sb 4
Then you can simple diff the content with
:windo diffthis
If you finished diff analysis you can input:
:windo diffoff
Related
Is it possible in Vim to set a default window for opening all files and buffers there?
Consider the following scenario:
I'm using Netrw and I'm positioned into the window that has the file list. Then I use :buffer or the wildmenu to open a file and it opens right there. I want the file to be opened in a default window, no matter where I'm positioned.
Thanks in advance.
I'm not sure if that's what you are looking for but you can use the :Lexplore command. It opens netrw in a vertical split in the current directory (:pwd). You can then open a file in the other vertical split. I haven't used it much, so I don't know it's exact behavior when you have multiple splits. You can open an additional a vertical split by using v in the netrw buffer.
I have the following mapping which opens netrw in a small vertical split:
nnoremap <silent> <leader>le :Lexplore<bar>vertical resize 30<CR>
I open a bunch of files by vim *.html *.css *.js, and I want to know how to open those targeted files in background buffers without mess up current window?
I tried to use vsplit, then "buf <buffer-number-I-want-to-open>, then C-w T. But I found it's way to tedious.
So is there a clear way to do that? thanks!
When you launch vim by vim *.html *.css *.js, the argument would be loaded into your vim argument list.
you can get the list it by args:.
And you can use :next, :previous, first, last, to traverse them.
if you want to open them all as tab?
you can use argdo: argdo tab split. this will dispatch a tab split command to each element in the arglist.
see:
:help :args
:help :argdo
:help :tab
you can :tabnew then use :next or buffer + <num> to open background buffers. but it will introduce a NO NAME buffer.
a neater way is to use CtrlP's buffer view, then press <Ctrl-t> and you will have it.
--
plugin Ctrl-P can perfectly achieve this, if you want to save your time, you can stick with it.
For example, suppose you have 3 buffers, where you are in buffer 1 and 2 more buffers are in background.
:ls
1 %a index.html
2 style.css
3 h script.js
Assume that you want to open buffer 3 script.js
open CtrlP,
switch to buf view, and choose the buffer your want to open
then press <C-t>, you would be able to open the buffers in new tab
Cheers!
Instead of tab completed file or directory names, I see ^I
:open ./lib/^I^I^I
Is there another command that would offer tab completion, or perhaps another solution?
I'm considering replacing the following mapping with something that would use buffers, but want to keep tab completion.
map <C-O> :tabnew ./
That might be because :open is not the command you're looking for. Try :edit or :e for short. Also try :help :open and :help :e to see, what the commands do. :e has tab completion.
Use :enew if you want to create a new empty buffer.
Use :edit filename if you want to edit a specific file in place of the current one.
Use :new if you want to create a new empty buffer in a new horizontal split window.
Use :split filename if you want to edit a specific file in a new horizontal split window.
Use :vnew if you want to create a new empty buffer in a new vertical split window.
Use :vsplit filename if you want to edit a specific file in a new vertical split window.
Use :tabnew if you want to create a new empty tab.
Use :tabedit filename if you want to edit a specific file in a new tab.
Use :help :command if you are unsure about its usage.
:set wildcharm=<tab> for tab completion.
I have a section in file1 which should be moved to file2. Normally I'd do this by visually-selecting the block, deleting it, :wq from file1, open file2, then paste.
Is there an easy way to move a block of text from file to file2 without closing vim?
Alternatively:
write selection to new file:'<,'>w file2
then reselect and delete with gvd
The first step is covered in vimtutor Lesson 5.3: SELECTING TEXT TO WRITE.
You could open your new file in a split using :sp newfile and then delete the block as normal from your first file. Then, change to the other split with ctrl w and w. Then use p to put the deleted content into the other file.
You could open the file in a new buffer.
just open the file via :e file2 and paste the text. To move quickly between the buffers use either :e # or :b #
see :help buffers for more information
Since no one mentioned that: you can use tabs instead.
Select your block.
Delete it with d
Create a new buffer in new tab with :tabnew newfile.name
Paste it and save it with p and :w
You can go back with gT or close current tab with :q
I personally newer use buffers -- only tabs. Read more about them in :help tabpage
Is there any command in vim with which I can jump to an already open tab containing the file which is open in the tab.
And that too with possibility of completion among all the open buffers.
For example you have following files open in different tabs.
readme.txt
pom.xml
Then the command jt will autocoplete the buffer names and jump to the tab containing the buffer.
You can use the command :sb <buffer>
You'll have to :set swb=usetab, in order to use existing open window in another tab. Otherwise it will just split the current window.