I need to execute vim commands on thousands of files without suffering from interactive mode slowness. I tried :
find ... | xargs vim '+set fileencoding=utf-8 | x'
and
for file in ... ; do
vim '+set fileencoding=utf-8 | x' $file
done
but it's too slow and I have warnings
Vim : Warning : Output is not to a terminal
Is it impossible to avoid interactive mode in vim ?
ps: I can otherwise use iconv, but it causes errors with files > 32 ko
iconv --from-code=ISO-8859-1 --to-code=UTF-8 $file -o $file
I would do:
find .... -print0 | xargs -0 vim -c 'argdo set fenc=utf8' -c 'wqa'
Filetype, syntax and indent plugins are probably what's slowing you down.
These are specified in your ~/.vimrc with a line that looks typically like:
filetype plugin indent on
You could try commenting that out, or
You can start Vim without your plugins and ~/.vimrc but staying in nocompatible mode by doing:
vim -Nu NONE
Related
How do I configure vim to open a default file (in my case, ~/Desktop/now.md) if the vim command is invoked without arguments on the command-line?
Add the following to your .vimrc:
au VimEnter * if eval("#%") == "" | e ~/Desktop/now.md | endif
This tells vim that whenever you launch vim (VimEnter) with any filetype (*) to run the following ex command:
if eval("#%") == "" | e ~/Desktop/now.md | endif
This is pretty straight-forward. The register '%' holds the name of the file you are editing, so we evaluate it and see if it's empty. If it is, tell vim to open the specified file.
Recommended reading: autocommands
Might be simpler handle this in your shell instead of vim.
You can add something like this to your .bash_profile / .zshrc:
alias vim='if [ $# -eq 0 ]; then command vim ~/Desktop/now.md; else command vim "$#"; fi;'
$# is the number of parameters passed to the command
"$#" lists all parameters passed to the command
To avoid recursively calling the vim alias, we prepend the vim command with the command keyword, which avoids aliases.
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 can easily vsplit vim window into two(left and right).
How to config vim to:
edit CoffeeScript in the left-window
view compiled JavaScript result in the right-window
view error message at the status-line
When I type in the left-window, the right-window and status-line should update JIT.
For example:
========================================================================
alert "hello" | alert("hello");
alert "world | alert;
|
========================================================================
missing ", starting on line 2
Just like http://coffeescript.org/ -> Try CoffeeScript.
I don't just use vim for this, I use a combination of GNU screen, GNU source-highlight and GNU watch. However, you need to have the version of screen that has the vertical split patch.
After starting screen, I'll hit Ctrl+ACtrl+C to create a second shell, then use Ctrl+AShift+\ to create a vertical split, then Ctrl+ATab to swap over to the new split and Ctrl+ACtrl+A to swap the split over to the new shell. In that shell, I run:
$ mkdir compiled
$ coffee -w -c -o compiled/ *.coffee &
That will run coffee in watch mode, which watches the source file (*.coffee) or folder for changes, and automatically recompiles changed *.coffee files and places the resulting .js files in the compiled folder.
Now, I will run $ watch --color -n 1 colorize compiled/main.js to display the contents of the compiled file I'm interested in, enabling ANSI colorized output.
That script file that I have called colorize is just a wrapper around source-highlight that automatically detects the language of the source file and applies appropriate syntax highlighting.
Then I use Ctrl+ACtrl+Tab to move back over to the first split, and fire up vim main.coffee and start editing away.
As I edit the coffeescript file, the compiled changes show up on the right hand side.
Errors are a little trickier, as they get spit out from the background coffee -w job. They will show up, but sometimes the watch command will overwrite the errors, and sometimes the errors will mess up the screen. When that happens, a quick Ctrl+L to tell bash to redraw the screen fixes things up.
Hope that's of some help.
vimrc config
set autoread
aug coffee
au!
au BufNewFile,BufRead *.coffee setf coffee.python
au FileType coffee.python setl makeprg=coffee\ -c\ %
au FileType coffee.python setl errorformat=Error:\ In\ %f\\,\ %m\ on\ line\ %l,
\Error:\ In\ %f\\,\ Parse\ error\ on\ line\ %l:\ %m,
\SyntaxError:\ In\ %f\\,\ %m,
\%-G%.%#
au BufWritePost *.coffee silent! make! | copen | redraw!
aug END
Note: If you like JIT, try CursorHold instead of BufWritePost.
open file
$ vim -O code.{coffee,js}
run ex command
:w
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.
Huge files take forever to load and work with in vim, due to syntax-highlighting.
I'm looking for a way to limit size of highlighted files, such that files larger than (say) 10MB will be colorless.
Adding the following line to _vimrc does the trick, with a bonus: it handles gzipped files, too (which is a common case with huge files):
autocmd BufWinEnter * if line2byte(line("$") + 1) > 1000000 | syntax clear | endif
Add to your .vimrc:
autocmd BufReadPre * if getfsize(expand("%")) > 10000000 | syntax off | endif
Note that this disables syntax highlighting in ALL buffers; syntax is a global vim thing and cannot be restricted to a single buffer.
I haven't tried it myself, but the LargeFile plugin seems to be exactly to address the kind of stuff you're looking for.
vim -u NONE <filename>
This will skip all initializations from configuration files.
Use uppercase U when running gvim.
"-i NONE" does only exclude viminfo from being loaded. If you defined syntax hilighting in there, that would help too.
vim -c 'syntax off' filename.ext