silent keyword not working in vim for external commands - vim

I was working on a vimscript that executes lgrep silently. However, the silent keyword would not work for any external command that is run. lmake, lgrep, etc all still dump their output despite the silent keyword used before the command.
How do I suppress the output??
Example:
:silent lgrep -R a *
The above command would dump out all results, forcing the user to press enter. I can't reproduce his problem on my machine, in bash/zsh/tmux/screen/terminal/iterm/vim 7.3/vim 7.4/anything. Any tips would be appreciated.
UPDATE:
I still have no idea what the problem is, but I found a workaround that goes something like this:
silent !grep -Rn a * >/tmp/lgrep_output.txt
lf /tmp/lgrep_output.txt
Run the raw external grep command (not lgrep) silently (this successfully suppresses the output, but :lgrep doesn't), redirecting the output to a file. Then load the file into the location list (lf /tmp/lgrep_output.txt)

Related

What will this command do

I accidentally ran the following command in my console.It was a copy paste error.
vim -> /etc/apache2/sites-available/25-xyz-https.conf.
But after that my 25-xyz-https.conf got corrupted. Eventhough I recovered the file just curious to understand what has happened.
This happens:
vim -
means open stdin in vim.
> file
is an output redirection by the shell. Stdout of the (vim) process will get stored in file. file will get truncated by the shell before the (vim) process get's started.
I recommend to always put a # into the shell before pasting things into the shell. That gives you a chance to review the line before executing it, especially if you paste the line together with the line break at the end. (which would execute it right away)
The shell ran "vim -" and then redirected the output from that command to /etc/apache2/sites-available/25-xyz-htttps.conf
If you run "vim -" you'll see it do something like this:
Vim: reading from stdin...
You will have to hit ^C to break out of reading from stdin, then :q to exit vim.
This is because many utilities interpret the '-' character as stdin (or stdout, depending on the context).
If you did something like:
date | vim -
This would open 'vim' with the contents of the document showing the current date. There is no open file, you could not simply :w to save the file, but you could :w./thedate.txt to save the contents to ./thedate.txt. The important thing is that the output of the 'date' command became the input to the 'vim' command.
After that, the > character just redirects stdout from the whole "vim -" session to overwrite the file provided.

meaning of "command" prefix and suffix of "!"

I am learning vim from vimtutor and I am currently on lesson 5 where they introduce external command prefix !command and external command suffix command!. I tested the command ls and did the following:
After typing :!ls, I got:
Desktop Downloads Music Public TEST
Documents Pictures Templates Videos
Press ENTER or type command to continue
When I saw the lists of folders and files, I knew that it acted like typing ls in the terminal, but when I typed :ls!, it got:
:ls!
1 %a "/tmp/tutorhN8t15" line 600
Press ENTER or type command to continue
Which made me confused of what the external command ! really means. What does it really mean?
:!command executes external command command.
:command! executes internal command command with a "bang" that usually modifies its behavior.
So…
:!ls executes your shell's ls command, which lists the files and directories in the working directory.
See :help :!.
:ls! executes Vim's ls command in a way that forces it to show listed and unlisted buffers.
See :help :ls.

store all the data in terminal to text file by tee command or equivalent tool

I learnt that a tee command will store the STDOUT to a file as well as outputs to terminal.
But, here the problem is every time I have to give tee command, for every command I give.
Is there any way or tool in linux, so that what ever I run in terminal, it should store the command as well as output. (I used tee command in MySQL, where it will store all the commands and outputs to a file of that entire session. I am expecting a tool similar to this.)
Edit:
When I run script -a log.txt, I see ^M characters as well as ^[ and ^] characters in log.txt file. I used various dos2unix, :set ff=unix, :set ff=dos commands, but they didn't helped me in removing these ^[, ^] characters.
Is there any method, I can directly get the plain text file (with out these extra chars).
OS: RHEL 5
You can use script command which writes everything on file
script -f log.txt
you could use aliases like such alias ls="ls;echo ls >>log" so every time you run ls it runs echo ls >>log too.
But script would probably be better in this case, just dont go into vi while you are in script.

Vim Ex mode loads when opening terminal

I know little about Vim in terminal(Mac) and the other day I was working copy and pasting text and i think I accidently did it when in terminal. Now whenever I open terminal it instantly loads on Vim Ex mode. I know how to quit Ex mode once in terminal but is there any way i can get rid of Vim loading when I open Terminal?
Thanks
Edit: To explain further to what i mean when I open terminal.app from Utilities I get the following
and the only way I get back to the command prompt is by typing quit every time I open terminal and i cant understand why the Vim process is running in the first place.
I was just outside the terminal in a document copy and pasting text then accidentally did a command v to paste within terminal which resulted in this happening.
It appears that you've accidentally updated one of your shell startup scripts so it launches vim.
If your default shell is csh or tcsh, take a look at .cshrc, .tcshrc, and .login in your home directory, and look for a command like vi -e or vim -e.
If your default shell is bash, check .bashrc and .bash_profile.
It may be easier to figure out which file you messed up by checking which file in your home directory was modified most recently:
% ls -altr $HOME | tail
-a lists all files, including files whose names start with ..
-l gives you a long listing, showing timestamps.
-t sorts by modification time.
-r reverses the order, so newer files are shown last

Is there a way to configure Vim grepprg option to avoid waiting until the external tool has finished searching?

I am a long time Vimmer. However, I keep switching to shell to make searches. This avoids me to use the quickfix functionality.
The main reason for switching to shell is that when I use grep from inside Vim (with :grep), I cannot follow progress.
Because the code base I search is usually wide, I really appreciate immediate feedback.
It gives me a chance to find out that my search expression is wrong before the full results have been displayed.
This allow me to cancel the search, refine the expression then relaunch the search.
Any hint how to reproduce this pattern inside Vim would be appreciated.
I don't see the same vim behaviour as you. When I run :grep, I still see the results in vim (not in the quickfix) before the search completes (but I cannot do anything until the search is done).
I even tried using no vim settings or plugins:
gvim -u NONE -U NONE
If that's not your behaviour, check your grepprg. Mine is the default:
:verbose set grepprg
grepprg=grep -n $* /dev/null
When I use run grep -e "score" -R /etc I see this output in vim:
:!grep -n -e "score" -R /etc /dev/null 2>&1| tee /tmp/voLcaNS/232
It's possible that your system is missing tee or your vim doesn't use it (I'm using Vim 7.2 on Ubuntu 10.10). tee takes the text passed to it and writes it to a file and to stdout.
If you're looking for a way to have the quickfix get updated with your search results and have vim not block while you're searching, then you could write a script that:
searches with grep as a background process and redirects to a file
every second until grep completes, have vim load the file in quickfix (cgetfile) (you can tell vim to do something from another process with --remote-expr)
You can try my AsyncCommand plugin to get your code started. It does the above, except that it only loads the file when the search is complete.
Are you familiar with ack.vim at all? It doesn't use the quickfix window, but uses a separate buffer in a split. However, it's rather faster results come right back to the vim frame.
This may be due to buffering between grep and tee, not vim itself. To test this theory, run grep from the command-line and pipe the output through tee (i.e. grep <pattern> <files> | tee temp.out). If it behaves the same as you observe within vim, then buffering is occurring.
To work around, install expect (sudo apt-get install expect-dev on Ubuntu 10.10) and grepprg to unbuffer grep -n $* /dev/null. (See Turn off buffering in pipe).
Take a look at :vimgrep in the online documentation. It displays the file name being searched and updates as it goes.
There are three ways to do a search in entire projects.
System command grep(fast, but not working well with Ouickfix list)
=>$ grep -n Example *
Vim internal grep(slow, but have a strong pattern support)
:vim[grep] /{pattern}/[g][j] {file} ...
System plugin ack(perfect)
1 install ack
brew install ack
2 add below configs to your .vimrc
:set grepprg=ack\ --nongroup\ --column\ $*
:set grepformat=%f:%l:%c:%m
3 then you can use grep to call ack in vim like
:grep "object\." app/**/*.rb

Resources