I'm trying to use vim to follow a file, similarly to how tail -f does it. I want to use vim, because I want the ability to move around the file, search for text, etc while still having the file be followed.
I've found the Tail Bundle plugin, but I can't seem to figure out how to make it work. None of the commands listed in the docs cause the file to continuously load at the bottom. They simply open the same file in a preview window.
Does anyone know how to use this plugin, or can you provide another way to use vim to follow a file like tail -f
I would not use Vim for that. less comes with many vi-like key-bindings for navigation and is inherently better for use as a pager than Vim.
$ less +F filename
$ command | less +F
Related
In particular, I'm editing files in Verilog and would like to see other instances of a word under the cursor in other files. Ideally, it'd bring up a list like the auto-complete list. I can then select the line entry and vim would open the file (either in the same window or a new tab).
I've seen this feature in Emacs. I have to think it exists in Vim somewhere.
This would be really fun to write in vimscript, but I don't exactly have time at the moment. Hopefully this will get you going in the right direction:
There is a vim plugin called Fugitive
It allows you to do things like git grep, or git blame right from you vim console. https://github.com/tpope/vim-fugitive
Their git grep command, Ggrep, should get you a list of local files with whatever word you want to grep for. Possibly check out this Q/A for getting it to work nicely: Getting 'git grep' to work effectively in vim
Last thing I would do is write a little vimscript function and a keystroke alias that would call Ggrep with the word under the cursor.
(hopefully I'll have time to write a better answer later)
If you have a tags file available, you might be able to use :tselect identifier for that purpose.
Vimgrep is your friend.
:vimgrep /pattern/ <path>/**
This will add lines to the quickfix window. Each line is the text from the line in a file that matches the pattern. The ** is shorthand for recurse into subdirectories.
I am using vimdiff as a diff tool for my git repo. Say I have five modified files and I am done with diff after the second file. How can I tell vim to stop opening the rest of the diff? Right now I just keep closing the buffer using :qa. I figured there's gotta be a better way to cut through instead of manually closing one buffer at a time.
I checked vim :help diff.txt but don't seem to find what I need.
Do you get prompts when running git difftool? You should get something like this:
Viewing (2/5): 'foo.bar'
Launch 'vimdiff' [Y/n]:
You can interrupt (^C) at the prompt to stop viewing any more changes.
If you don't get the prompt, set difftool.prompt option (see git-config(1)).
One thing that I like to do from time to time is do a quick search on the directory I am working on and find all the references to a specific string, specially when debugging code from some one else. Is it still not possible for VIM to do such search? Is there an alternative to do it directly with plain terminal?
ATM (since I'm still learning VIM) I do the search in TextMate and find the string that way.
You can use the vim command :vimgrep. This will search for a pattern in the specified files and puts the results in the quickfix window which you can then use to jump to a specific match. So for example to search for foo recursively in every .php file in your current directory you would do
:vimgrep "foo" **/*.php
Another option is the command :grep which actually calls the grep program (or whatever grepprg is set to). It also puts the results in the quickfix window for easy navigation. However this requires that you have grep on your system.
vim's an editor, not really a file searcher. It's trivially simple to call out to a shell and run 'grep', however. Assuming you're on a Unix-ish environment (TextMate - MacOs?) While in command mode, hit ctrl-z and you'll be at the shell prompt, then do
grep somestring *.c
and you'll get all matches for 'somestring' in any C source files.
Once done grepping, just do a fg (foreground) command and boom - back to VIM.
vimgrep will work, but if the source happens to be in Git then you can use tpope's excellent https://github.com/tpope/vim-fugitive plugin, which exposes :Ggrep which hangs off git grep for more flexibility.
If it's specific entities you're looking for (functions, variables, etc) the integration with ctags is probably of interest to you as well.
Sounds like you might like to have a look at vim tag search functionality combined with ctags. ctags is an utility that can be used to generate an index (a tags file) of various language objects for source code (full project tree, not just a directory). In vim a tag is sort of identifier that can be jumped to or searched for.
See vim documentation:
:help tagsrch
Or:
http://vimdoc.sourceforge.net/htmldoc/tagsrch.html#ctags
I am starting on VIM and trying to understand it a bit. I currently use TextMate for web development, so I can build nice commands which take my current document/selection and display as a web view very quickly or send some results through tooltips.
I believe it's more appropriate to refer this question to MacVim since it has access to GUI elements so sometimes it might be possible?
"HTML Output for Commands" is a good explanation.
So I would like to know if it's posibble to output commands to a HTML window just like TextMate?
Or would I have to create my own program that accepts STDIN and display it as an html output on a view?
The same for the tooltips?
I was hoping that as MacVim is has access to Cocoa library and GUI elements perhaps it could already have some feature like this?
Sorry if I am misunderstanding things here, I really feel that it would be a good idea to migrate but obviously I would like to keep the nice and quick tools that I use and not losing a good visual appeal.
so I would like to know if its posibble to output commands to an html window just like TextMate?
You could have vim issue a command at the command-line which would tell a browser to open a file you're editing.
On a Mac, using either vim at the command-line or MacVim, if you were editing a file called "test.html" in the buffer and it was in your Desktop folder:
:!open ~/Desktop/test.html
will open, or re-open the file in the browser. So, when you make a change you issue that and the browser will come to the foreground with the latest version of the file. You could use the other options to "open" to specify which browser to use. And, you could easily add a key press to open the current file, which is "%" on the command line.
If you want to capture the output of a command in vim, there are a couple ways to do that. If you execute a command vim will capture its output in a temporary buffer for viewing.
:!ls
displays:
:!ls
Desktop Downloads Library Music Photo Tools Public VirtualBox VMs bin
Documents Editors Movies Music Tools Pictures Sites Web Tools
You can also see what's in Command - R like functionality in MacVim and Vim - Displaying Code Output in a New Window รก la Textmate?.
I'm not sure what you mean by "tooltips". Usually that refers to pop-up text at the tip of your mouse offering context sensitive help. You can't send text through that, so your use of the word is confusing.
MacVim and vim do have snippet-like capability, plus are scriptable, can work on text that is the current selection, plus a whole lot more. It's important to understand that MacVim is a GUI layer on top of the regular vim editor, so there are somethings it won't do because vim's engine doesn't make it easy. That hasn't ever bothered me, because if I need a particular TextMate feature I'll fire it up, use that particular thing, then jump back if I feel like it. But, that's not too common a need for me.
You might want to look at some of the related threads here on SO, over on the right hand side of the page, plus look at some of vim's plugins like:
taglist.vim
vimspell
matchit.zip
align
surround
Tabular
I use the above ones all the time. The following ones I'd miss if I didn't have them.
Command-T
SnipMate
Rails.vim
EDIT:
Capturing the temporary buffer to a new buffer in Vim is pretty easy:
:redir #a
:sil !ls -al
:redir end
:vnew
"agp
The second line :sil !ls -al could be any execution of a command. :sil tells Vim to not echo the output to the temporary buffer, instead capture it silently, which gets rid of the "Press any key" pause.
:vnew creates a vertical split with a new buffer in it. You could use :tabnew instead if you want a new tab.
"agp tells it to use buffer #a and paste the output into the current buffer and leave the cursor below the pasted text.
Like most of you, I work in several source files of code every day. A lot of the time, my insane work flow has me doing stuff like:
# TODO
# clean up this code
# do something else with this code
Is there currently a vim plugin available that will search for TODO or a similar mnemonic and print a list of my current tasks that are on-going and in what source file it needs to be done? It would be a huge time saver instead of using grep constantly. Also with vim ctags, you can jump right in the code where you left the TODO off at.
I've not tried it (yet), but this plugin looks promising.
Edit: I've just tried this plugin out. I will be keeping it around. It's very handy and interactively moves you around the buffer while you navigate the task list.
Also, there is a mirror on github if you use pathogen or another means of git submodules for your vim directory.
When you say grep, are you talking about grep from the command line, or :grep in vim? The latter allows you to view a quickfix list of matches and jump to them. If typing out :grep TODO -r . becomes cumbersome you could easily map that operation to a hotkey.