I've been messing with vim configuration recently, and now when I open the first file in gVim, I see some warnings that disappear quickly. Where else can I see them and see what's wrong?
Try one of the following:
After starting vim, use :messages command. It will show you all messages (except that were echoed with echo or echon).
Redirect vim output to some file: vim -c 'qa!' > messages.log.
Start vim using vim --cmd 'redir! > messages.log' -c 'redir END' -c 'qa!', then observe messages.log.
Related
I run vim scripts on a regular base. Is it possible to run a script e.g.
vim -s script.vim file.txt without opening vim and returning possible error messages to the terminal?
I've been working with a lot of C++ files that have no extensions and it's too annoying to have to type :set ft=cpp every time I open them, so I'm mostly just working without syntax highlighting. Is there a way to tell vim the file type in the command line? Something like:
$ vim --ft=cpp file_name
You can use the -c option when launching vim to execute commands after the first file has been read.
For your situation, you can simply use the standard set filetype command -
vim -c 'set filetype=javascript'
You could also use --cmd to execute the command after the first file is loaded.
Lifted from the vim man pages:
-c {command}
{command} will be executed after the first file has been read. {command} is interpreted as an Ex command. If the {command} contains spaces it must be enclosed in double quotes (this depends on the shell that is used).
Example: Vim "+set si" main.c
Note: You can use up to 10 "+" or "-c" commands.
--cmd {command}
Like using "-c", but the command is executed just before processing any vimrc file. You can use up to 10 of these commands, independently from "-c" commands.
The following command successfully launches vim that reads the edit buffer from standard input.
echo hi | vim -
But this one does not work.
echo hi | vim --remote-tab-silent -
When the above command is run, the following warning occurs and vim quits.
Vim: Warning: Input is not from a terminal
Vim: Error reading input, exiting...
Vim: preserving files...
Vim: Finished.
Why does it not read from standard input in the second case?
The help message of vim seems to indicate that it should have worked?
$ vim -h | head
VIM - Vi IMproved 7.4 (2013 Aug 10, compiled Mar 31 2015 23:36:07)
usage: vim [arguments] [file ..] edit specified file(s)
or: vim [arguments] - read text from stdin
or: vim [arguments] -t tag edit file where tag is defined
or: vim [arguments] -q [errorfile] edit file with first error
Arguments:
-- Only file names after this
-g Run using GUI (like "gvim")
$ vim -h | grep remote
--remote <files> Edit <files> in a Vim server if possible
--remote-silent <files> Same, don't complain if there is no server
--remote-wait <files> As --remote but wait for files to have been edited
--remote-wait-silent <files> Same, don't complain if there is no server
--remote-tab[-wait][-silent] <files> As --remote but use tab page per file
--remote-send <keys> Send <keys> to a Vim server and exit
--remote-expr <expr> Evaluate <expr> in a Vim server and print result
You cannot edit from stdin when using --remote.
:h --remote
--remote [+{cmd}] {file} ...
Open the file list in a remote Vim. When
there is no Vim server, execute locally.
There is one optional init command: +{cmd}.
This must be an Ex command that can be
followed by "|".
The rest of the command line is taken as the
file list. Thus any non-file arguments must
come before this.
You cannot edit stdin this way |--|.
The remote Vim is raised. If you don't want
this use >
vim --remote-send "<C-\><C-N>:n filename<CR>"
--remote-silent [+{cmd}] {file} ...
As above, but don't complain if there is no
server and the file is edited locally.
--remote-tab-silent Like --remote-silent but open each file in a
new tabpage.
I've got a weird problem where if i do something like this in a gnu screen window, that window starts responding in weird ways
ls *.cpp | xargs vim
After I exit from vim, the screen window doesn't echo any command. It even does not echo CR.
Any suggestions?
Piping changes vim's stdin and causes problems. Try this instead (for bash, zsh, etc.):
vim $(find . -name "*.cpp")
How about vim *.cpp?
Maybe for file in *.cpp; do vim "$file"; done could work too. Edit each file and exit.
Or start vim and add all cpp files with following command: :argadd *.cpp
When using Vim in a pipe like this, you'll probably notice the following warning:
Vim: Warning: Input is not from a terminal
That's Vim telling you that it cannot function as it's supposed to be (i.e. in interactive mode; you can still use it in "batch mode" by feeding it Ex commands to process). That explains the weirdness you experience after Vim quits.
I have a bash script that runs (something like) the following command:
vim -E <<EOT
call Myfunc()
EOT
where Myfunc() is defined in my .vimrc. I've discovered that using the heredoc (but not simply calling it with -E and entering commands manually) causes vim to skip loading my .vimrc, consequently setting compatible mode (causing other problems down the road).
I can load my .vimrc manually if I have to, but I'm assuming I don't know a priori where it is, so I'd like to let vim do the work.
Does using the heredoc make vim set some other option (-u NORC, say), which I can just unset to get normal behaviour?
I'm in Vim 7.3, if it matters.
Giving arguments to vim through a heredoc is equivalent to taking input from stdin:
vim -E -
call Myfunc()
qa!
This starts vim in silent mode (see :help -s-ex) and only loads plugins specified by the -u argument. To load all plugins, write the ex command to a file and use that file for input:
cat <<EOT > input.vim
call Myfunc()
qa!
EOT
vim -E input.vim
(I added qa: to force vim to exit after running Myfunc().)