vim takes a very long time to start up - vim

I'm experiencing a very sluggish startup time with vim as well as other unrelated programs ever since I logged out and logged back in the last time. Following is the startuptime log for vim:
> times in msec clock self+sourced self: sourced script clock
> elapsed: other lines
>
> 000.005 000.005: --- VIM STARTING ---
> 000.073 000.068: Allocated generic buffers
> 000.168 000.095: locale set
> 000.180 000.012: GUI prepared
> 000.181 000.001: clipboard setup
> 000.188 000.007: window checked
> 000.621 000.433: inits 1
> 000.626 000.005: parsing arguments
> 000.627 000.001: expanding arguments
> 000.637 000.010: shell init
> 000.909 000.272: Termcap init
> 000.942 000.033: inits 2
> 001.031 000.089: init highlight
> 023.418 000.234 000.234: sourcing /grid/common/pkgs/vim/v7.3/share/vim/vim73/syntax/syncolor.vim
> 023.543 001.811 001.577: sourcing /grid/common/pkgs/vim/v7.3/share/vim/vim73/syntax/synload.vim
> 044.397 015.231 015.231: sourcing /grid/common/pkgs/vim/v7.3/share/vim/vim73/filetype.vim
> 044.449 025.111 008.069: sourcing /grid/common/pkgs/vim/latest/share/vim/vim73/syntax/syntax.vim
> 052.532 000.199 000.199: sourcing /grid/common/pkgsData/vim-v7.3/Linux/RHEL4.0-2007-x86_64/share/vim/vim73/syntax/nosyntax.vim
> 059.858 000.175 000.175: sourcing /grid/common/pkgs/vim/v7.3/share/vim/vim73/syntax/syncolor.vim
> 059.966 003.842 003.667: sourcing /grid/common/pkgs/vim/v7.3/share/vim/vim73/syntax/synload.vim
> 060.002 010.259 006.218: sourcing /grid/common/pkgs/vim/v7.3/share/vim/vim73/syntax/syntax.vim
> 069.085 000.178 000.178: sourcing /grid/common/pkgs/vim/v7.3/share/vim/vim73/syntax/syncolor.vim
> 072.326 000.173 000.173: sourcing /grid/common/pkgs/vim/v7.3/share/vim/vim73/syntax/syncolor.vim
> 076.317 000.175 000.175: sourcing /grid/common/pkgs/vim/v7.3/share/vim/vim73/syntax/syncolor.vim
> 076.477 013.311 012.785: sourcing /grid/common/pkgs/vim/v7.3/share/vim/vim73/colors/desert.vim
> 079.768 000.019 000.019: sourcing /grid/common/pkgs/vim/v7.3/share/vim/vim73/filetype.vim
> 080.322 065.921 017.221: sourcing $HOME/.vimrc
> 080.330 013.378: sourcing vimrc file(s)
> 106.526 000.376 000.376: sourcing /home/haitham/.vim/plugin/genutils.vim
> 111.139 001.435 001.435: sourcing /home/haitham/.vim/plugin/multiselect.vim
> 113.534 000.147 000.147: sourcing /home/haitham/.vim/plugin/omap-param.vim
> 119.245 000.073 000.073: sourcing /home/haitham/.vim/plugin/qfixtoggle.vim
> 122.821 000.696 000.696: sourcing /home/haitham/.vim/plugin/surround.vim
> 172.247 000.098 000.098: sourcing /grid/common/pkgs/vim/v7.3/share/vim/vim73/plugin/getscriptPlugin.vim
> 176.387 000.252 000.252: sourcing /grid/common/pkgs/vim/v7.3/share/vim/vim73/plugin/gzip.vim
> 179.876 000.183 000.183: sourcing /grid/common/pkgs/vim/v7.3/share/vim/vim73/plugin/matchparen.vim
> 182.748 000.620 000.620: sourcing /grid/common/pkgs/vim/v7.3/share/vim/vim73/plugin/netrwPlugin.vim
> 186.171 000.051 000.051: sourcing /grid/common/pkgs/vim/v7.3/share/vim/vim73/plugin/rrhelper.vim
> 189.739 000.046 000.046: sourcing /grid/common/pkgs/vim/v7.3/share/vim/vim73/plugin/spellfile.vim
> 193.406 000.195 000.195: sourcing /grid/common/pkgs/vim/v7.3/share/vim/vim73/plugin/tarPlugin.vim
> 199.206 000.060 000.060: sourcing /grid/common/pkgs/vim/v7.3/share/vim/vim73/plugin/tohtml.vim
> 202.299 000.152 000.152: sourcing /grid/common/pkgs/vim/v7.3/share/vim/vim73/plugin/vimballPlugin.vim
> 205.345 000.147 000.147: sourcing /grid/common/pkgs/vim/v7.3/share/vim/vim73/plugin/zipPlugin.vim
> 205.394 120.533: loading plugins
> 12343.581 12138.187: inits 3
> 12349.592 006.011: reading viminfo
> 18421.239 6071.647: setup clipboard
> 18421.264 000.025: setting raw mode
> 18421.270 000.006: start termcap
> 18421.293 000.023: clearing screen
> 18421.504 000.211: opening buffers
> 18421.564 000.060: BufEnter autocommands
> 18421.566 000.002: editing files in windows
> 18425.833 004.267: VimEnter autocommands
> 18425.835 000.002: before starting main loop
> 18426.587 000.752: first screen update
> 18428.334 001.747: --- VIM STARTED ---
Apparently the biggest components are "inits 3" and "setup clipboard".
Any clues what to do about it?

setup clipboard
First, try running Vim with the following command:
$ vim -X
You can try using the -X --startuptime <file> options together to see if the "setup clipboard" component is still slow.
If -X helps, you can get the same effect by adding the following line to your vimrc file:
set clipboard=exclude:.*
Explanation
If this helps what is happening is that on startup Vim is trying to connect to an X server to allow it to use the clipboard. The -X option tells Vim to not try connecting to the X server. From :help -X
-X Do not try connecting to the X server to get the current
window title and copy/paste using the X clipboard. This
avoids a long startup time when running Vim in a terminal
emulator and the connection to the X server is slow.
See --startuptime to find out if affects you.
Only makes a difference on Unix or VMS, when compiled with the
+X11 feature. Otherwise it's ignored.
To disable the connection only for specific terminals, see the
'clipboard' option.
When the X11 Session Management Protocol (XSMP) handler has
been built in, the -X option also disables that connection as
it, too, may have undesirable delays.
The clipboard option can be used to achieve the same thing more permanently via your vimrc file. From :help 'clipboard'
To never connect to the X server use:
exclude:.*
This has the same effect as using the -X argument.
Note that when there is no connection to the X server
the window title won't be restored and the clipboard
cannot be accessed.
The clipboard=exclude:.* option can be refined to only work with particular terminals, if you want Vim to connect to the X server in some instances. Check out :help 'clipboard' for more on this.
For me, this problem was happening because I had "X11 Forwarding" enabled on my ssh client but did not always have an X Server running on the ssh client machine.
When I have an X server running on the target machine, Vim is much faster starting up (though still a bit slow).
In this setup, I want to maintain the X11 Forwarding, but do not need Vim to use the X clipboard, so I added the set clipboard=exclude:.* line to my vimrc. Now Vim startup is quick for me once more.
inits 3
You seem to have already eliminated your plugins/customisations as a possible cause by trying vim -u NONE (and you said your vimrc was empty).
I am not familiar with this issue, but as suggested above, it might be to do with your viminfo file.
You can determine whether this is the case by starting Vim with the following command:
$ vim -i NONE
According to :help slow-start:
If you have "viminfo" enabled, the loading of the viminfo file may take a
while. You can find out if this is the problem by disabling viminfo for a
moment (use the Vim argument "-i NONE"). Try reducing the number of
lines stored in a register with ":set viminfo='20,<50,s10".

I'm using v7.4. The -X option increase the startup time successfuly when vim compiled with +clipboard. But, since the connection to the X now disabled, we can't copy and paste from x clipboard anymore.
Meanwhile, vim is my only way to write before send it to email, twitter, telegram, etc. So copy+paste from vim is a must. Just found the simple solution :
alias v='nvim'
Nvim use my old .vimrc automatically. clipboard feature work seamlessly without any configuration hassle.
Not provoking to using nvim. I just found it the shortest solution to my problem now.

Related

vim color schemes not working after installing with `brew`

I had my vim set up with a number of colorschemes and plugins with the default vim install that comes with MacOS. However I needed a version of vim with python3 so I installed one via brew install vim.
Now the color schemes are not working, and everything is a dark grey color (I'm guessing the default palette for terminal).
Attempts at fixes:
I've tried running :PluginInstall to install the plugins again but nothing changes.
syntax on also does not change anything.
Updates
Output of --startuptime
times in msec
clock self+sourced self: sourced script
clock elapsed: other lines
000.007 000.007: --- VIM STARTING ---
000.088 000.081: Allocated generic buffers
000.592 000.504: locale set
000.596 000.004: clipboard setup
000.601 000.005: window checked
001.208 000.607: inits 1
001.220 000.012: parsing arguments
001.221 000.001: expanding arguments
004.441 003.220: shell init
004.873 000.432: Termcap init
004.891 000.018: inits 2
005.029 000.138: init highlight
005.853 000.087 000.087: sourcing /usr/local/share/vim/vim82/ftoff.vim
006.426 000.282 000.282: sourcing /Users/quinoah/.vim/bundle/Vundle.vim/autoload/vundle.vim
006.900 000.239 000.239: sourcing /Users/quinoah/.vim/bundle/Vundle.vim/autoload/vundle/config.vim
018.668 000.029 000.029: sourcing /Users/quinoah/.vim/bundle/csv.vim/ftdetect/csv.vim
018.942 000.022 000.022: sourcing /Users/quinoah/.vim/bundle/vim-markdown/ftdetect/markdown.vim
019.251 008.828 008.777: sourcing /usr/local/share/vim/vim82/filetype.vim
019.772 000.090 000.090: sourcing /usr/local/share/vim/vim82/ftplugin.vim
024.535 003.505 003.505: sourcing /usr/local/share/vim/vim82/colors/lists/default.vim
024.920 004.279 000.774: sourcing /usr/local/share/vim/vim82/syntax/syncolor.vim
025.203 004.850 000.571: sourcing /usr/local/share/vim/vim82/syntax/synload.vim
025.349 005.291 000.441: sourcing /usr/local/share/vim/vim82/syntax/syntax.vim
027.927 002.198 002.198: sourcing /usr/local/share/vim/vim82/colors/lists/default.vim
029.047 000.240 000.240: sourcing /usr/local/share/vim/vim82/syntax/syncolor.vim
038.527 010.210 009.970: sourcing /Users/quinoah/.vim/bundle/vim/colors/embark.vim
038.601 033.153 005.928: sourcing $HOME/.vimrc
038.611 000.429: sourcing vimrc file(s)
039.437 000.252 000.252: sourcing /Users/quinoah/.vim/bundle/csv.vim/plugin/csv.vim
040.265 000.174 000.174: sourcing /Users/quinoah/.vim/bundle/vim-airline/autoload/airline/init.vim
041.704 000.881 000.881: sourcing /Users/quinoah/.vim/bundle/vim-airline/autoload/airline/parts.vim
042.094 000.026 000.026: sourcing /Users/quinoah/.vim/bundle/vim-airline/autoload/airline/formatter/short_path.vim
044.113 000.254 000.254: sourcing /Users/quinoah/.vim/bundle/vim-airline/autoload/airline/util.vim
044.243 004.577 003.242: sourcing /Users/quinoah/.vim/bundle/vim-airline/plugin/airline.vim
044.545 000.054 000.054: sourcing /Users/quinoah/.vim/bundle/vim-airline-themes/plugin/airline-themes.vim
046.375 000.166 000.166: sourcing /Users/quinoah/.vim/bundle/ale/autoload/ale/events.vim
046.598 001.663 001.497: sourcing /Users/quinoah/.vim/bundle/ale/plugin/ale.vim
047.008 000.137 000.137: sourcing /Users/quinoah/.vim/bundle/black/plugin/black.vim
047.339 000.115 000.115: sourcing /Users/quinoah/.vim/bundle/fern.vim/plugin/fern.vim
047.622 000.059 000.059: sourcing /Users/quinoah/.vim/bundle/fern-git-status.vim/plugin/fern_git_status.vim
048.860 000.085 000.085: sourcing /usr/local/share/vim/vim82/plugin/getscriptPlugin.vim
049.231 000.260 000.260: sourcing /usr/local/share/vim/vim82/plugin/gzip.vim
049.640 000.297 000.297: sourcing /usr/local/share/vim/vim82/plugin/logiPat.vim
049.800 000.039 000.039: sourcing /usr/local/share/vim/vim82/plugin/manpager.vim
050.155 000.247 000.247: sourcing /usr/local/share/vim/vim82/plugin/matchparen.vim
050.830 000.556 000.556: sourcing /usr/local/share/vim/vim82/plugin/netrwPlugin.vim
050.984 000.021 000.021: sourcing /usr/local/share/vim/vim82/plugin/rrhelper.vim
051.148 000.042 000.042: sourcing /usr/local/share/vim/vim82/plugin/spellfile.vim
051.457 000.191 000.191: sourcing /usr/local/share/vim/vim82/plugin/tarPlugin.vim
051.734 000.157 000.157: sourcing /usr/local/share/vim/vim82/plugin/tohtml.vim
052.074 000.194 000.194: sourcing /usr/local/share/vim/vim82/plugin/vimballPlugin.vim
052.453 000.237 000.237: sourcing /usr/local/share/vim/vim82/plugin/zipPlugin.vim
052.498 004.704: loading plugins
052.775 000.277: loading packages
053.940 000.647 000.647: sourcing /Users/quinoah/.vim/bundle/indentLine/after/plugin/indentLine.vim
054.148 000.726: loading after plugins
054.156 000.008: inits 3
054.672 000.516: reading viminfo
054.703 000.031: setting raw mode
054.714 000.011: start termcap
054.745 000.031: clearing screen
055.676 000.603 000.603: sourcing /Users/quinoah/.vim/bundle/vim-airline/autoload/airline/extensions.vim
056.024 000.079 000.079: sourcing /Users/quinoah/.vim/bundle/vim-airline/autoload/airline/extensions/quickfix.vim
056.508 000.288 000.288: sourcing /Users/quinoah/.vim/bundle/vim-airline/autoload/airline.vim
056.907 000.065 000.065: sourcing /Users/quinoah/.vim/bundle/vim-airline/autoload/airline/extensions/netrw.vim
057.578 000.124 000.124: sourcing /Users/quinoah/.vim/bundle/vim-airline/autoload/airline/section.vim
058.287 000.375 000.375: sourcing /Users/quinoah/.vim/bundle/vim-airline/autoload/airline/highlighter.vim
058.817 001.641 001.142: sourcing /Users/quinoah/.vim/bundle/vim-airline/autoload/airline/extensions/term.vim
059.264 000.067 000.067: sourcing /Users/quinoah/.vim/bundle/vim-airline/autoload/airline/extensions/csv.vim
059.841 000.152 000.152: sourcing /Users/quinoah/.vim/bundle/vim-airline/autoload/airline/extensions/ale.vim
060.384 000.187 000.187: sourcing /Users/quinoah/.vim/bundle/vim-airline/autoload/airline/extensions/whitespace.vim
060.804 000.095 000.095: sourcing /Users/quinoah/.vim/bundle/vim-airline/autoload/airline/extensions/po.vim
061.311 000.163 000.163: sourcing /Users/quinoah/.vim/bundle/vim-airline/autoload/airline/extensions/wordcount.vim
061.738 000.047 000.047: sourcing /Users/quinoah/.vim/bundle/vim-airline/autoload/airline/extensions/keymap.vim
062.383 000.067 000.067: sourcing /Users/quinoah/.vim/bundle/vim-airline/autoload/airline/extensions/searchcount.vim
074.981 000.093 000.093: sourcing /Users/quinoah/.vim/bundle/vim-airline/autoload/airline/themes.vim
075.345 000.704 000.611: sourcing /Users/quinoah/.vim/bundle/vim-airline-themes/autoload/airline/themes/bubblegum.vim
085.582 000.452 000.452: sourcing /Users/quinoah/.vim/bundle/vim-airline-themes/autoload/airline/themes/bubblegum.vim
115.616 000.214 000.214: sourcing /Users/quinoah/.vim/bundle/vim-airline/autoload/airline/builder.vim
116.310 000.115 000.115: sourcing /Users/quinoah/.vim/bundle/vim-airline/autoload/airline/extensions/default.vim
154.893 000.354 000.354: sourcing /Users/quinoah/.vim/bundle/ale/autoload/ale.vim
155.927 095.889: opening buffers
156.006 000.079: BufEnter autocommands
156.009 000.003: editing files in windows
157.205 000.501 000.501: sourcing /Users/quinoah/.vim/bundle/fern.vim/autoload/vital/fern.vim
157.722 000.163 000.163: sourcing /Users/quinoah/.vim/bundle/fern.vim/autoload/vital/_fern/Async/CancellationToken.vim
158.015 000.042 000.042: sourcing /Users/quinoah/.vim/bundle/fern.vim/autoload/vital/_fern.vim
158.390 001.915 001.209: sourcing /Users/quinoah/.vim/bundle/fern-git-status.vim/autoload/fern_git_status.vim
159.427 000.442 000.442: sourcing /Users/quinoah/.vim/bundle/fern.vim/autoload/vital/_fern/Async/Promise.vim
160.116 000.153 000.153: sourcing /Users/quinoah/.vim/bundle/fern.vim/autoload/vital/_fern/Async/Later.vim
160.347 001.705 001.110: sourcing /Users/quinoah/.vim/bundle/fern.vim/autoload/fern/hook.vim
165.328 005.699: VimEnter autocommands
165.331 000.003: before starting main loop
168.580 000.543 000.543: sourcing /Users/quinoah/.vim/bundle/ale/autoload/ale/engine.vim
168.954 000.112 000.112: sourcing /Users/quinoah/.vim/bundle/ale/autoload/ale/statusline.vim
171.398 005.412: first screen update
171.400 000.002: --- VIM STARTED ---
~   ✔  base Py
There are a few things you'll need to investigate what is going on exactly. First, make sure that the vim you are executing in the terminal is coming from brew. You can do that with which:
$ which vim
/opt/homebrew/bin/vim
If the path doesn't point to homebrew, then your $PATH might need updating. In short: make sure you are using the vim executable you installed with brew.
Next, check again if the vim executable you are running does in fact have support for Python 3 (since you stated that is a need):
$ vim --version | grep python3
+cmdline_info +libcall +python3 +virtualedit
Continue to starting up with extra information as to what is being sourced. You do that by running vim --startuptime vim.log, then exiting the file and looking at the resulting vim.log file. Here is a snippet of what mine looks like:
times in msec
clock self+sourced self: sourced script
clock elapsed: other lines
000.004 000.004: --- VIM STARTING ---
000.069 000.065: Allocated generic buffers
001.546 001.477: locale set
001.550 000.004: clipboard setup
...
007.567 000.146: init highlight
008.327 000.248 000.248: sourcing /Users/alfredo/.vim/autoload/pathogen.vim
In that file, I can see that color schemes are getting sourced and loaded. Check for that in your output. For example, I have colorscheme tomorrow-night in my .vimrc and I see it in the log output:
076.290 025.426 025.186: sourcing /Users/alfredo/.vim/colors/tomorrow-night.vim
As you can see, I have my colors in ~/.vim/colors.
If all of that fails, try using a separate .vimrc to run with vim so that you check if anything in there is causing problems. You can use a separate one with the -u flag: vim -u empty-vimrc test.txt. In this case empty-vimrc must be a file that exists and has some configuration in it.

vim very slow to start

OS == FreeBSD-12.1p2
Vim == 8.1.2372
I am encountering a problem with vim having an excessively slow startup time on just one system. The content of vim --startuptime vim_startuptime.log follows:
times in msec
clock self+sourced self: sourced script
clock elapsed: other lines
000.030 000.030: --- VIM STARTING ---
000.166 000.136: Allocated generic buffers
000.293 000.127: locale set
000.307 000.014: GUI prepared
000.309 000.002: clipboard setup
000.334 000.025: window checked
001.000 000.666: inits 1
001.064 000.064: parsing arguments
001.066 000.002: expanding arguments
001.136 000.070: shell init
001.795 000.659: Termcap init
001.846 000.051: inits 2
002.060 000.214: init highlight
003.900 001.183 001.183: sourcing /usr/local/share/vim/vim81/syntax/syncolor.vim
. . .
018.890 001.561: loading plugins
018.997 000.107: loading packages
019.028 000.031: loading after plugins
019.077 000.049: inits 3
019.197 000.120: reading viminfo
75047.076 75027.879: setup clipboard
75047.146 000.070: setting raw mode
75047.161 000.015: start termcap
75047.191 000.030: clearing screen
75047.457 000.266: opening buffers
75047.551 000.094: BufEnter autocommands
75047.555 000.004: editing files in windows
75047.741 000.186: VimEnter autocommands
75047.744 000.003: before starting main loop
75048.149 000.405: first screen update
75048.151 000.002: --- VIM STARTED ---
However, if I disable X then this is the result (vim -X --startuptime vim_startuptime-X.log):
times in msec
clock self+sourced self: sourced script
clock elapsed: other lines
000.030 000.030: --- VIM STARTING ---
000.165 000.135: Allocated generic buffers
000.293 000.128: locale set
000.309 000.016: GUI prepared
000.310 000.001: clipboard setup
000.336 000.026: window checked
001.009 000.673: inits 1
001.074 000.065: parsing arguments
001.076 000.002: expanding arguments
001.146 000.070: shell init
001.801 000.655: Termcap init
001.853 000.052: inits 2
002.067 000.214: init highlight
003.936 001.214 001.214: sourcing /usr/local/share/vim/vim81/syntax/syncolor.vim
. . .
019.029 001.555: loading plugins
019.137 000.108: loading packages
019.168 000.031: loading after plugins
019.192 000.024: inits 3
019.307 000.115: reading viminfo
019.309 000.002: setup clipboard
019.363 000.054: setting raw mode
019.376 000.013: start termcap
019.402 000.026: clearing screen
019.811 000.409: opening buffers
019.856 000.045: BufEnter autocommands
019.859 000.003: editing files in windows
020.005 000.146: VimEnter autocommands
020.008 000.003: before starting main loop
020.390 000.382: first screen update
020.391 000.001: --- VIM STARTED ---
I connect to this system using ssh -X -t and generally use gvim to display the editing window on my desktop. When I do that on the problem host in addition to the long delay I get the message that the the child process could not open the GUI. I have previously run gvim on this host without issue.
Both hosts' /etc/ssh/sshd_config file are identical save for the Listen address. Yhe X11 entries in each are listed below:
grep -in x11 /etc/ssh/sshd_config
102:#X11Forwarding yes
103:#X11DisplayOffset 10
104:#X11UseLocalhost yes
147:# To allow ssh tunneling in jails set X11UseLocalhost to NO
148:X11UseLocalhost no
174:# X11Forwarding no
I have an identically configured host (hardware, OS, sshd_config) that I also connect to via ssh -X -t where this problem does not occur. I have tried removing and reinstalling vim on the problem host, which makes no difference.
Likewise I removed the .vim directory and .viminfo file from the user's home directory. This had no effect on startup time. This issue is not confined to a single userid in any case.
A debugging log (vim -V9vim_startup_debug.log) contains this:
. . .
Searching for "/usr/local/share/vim/vimfiles/after/plugin/**/*.vim"
Searching for "/root/.vim/after/plugin/**/*.vim"
not found in 'runtimepath': "plugin/**/*.vim"
Reading viminfo file "/root/.viminfo" info oldfiles
Opening the X display failed
Executing BufEnter Autocommands for "*"
autocommand sil call s:LocalBrowse(expand("<amatch>"))
. . .
I am open to suggestions as to how to resolve this problem. It is evident that X11 forwarding is somehow involved and that the clipboard setup is where the problem is happening, but I have no idea how to discover what the actual problem is.

Make Vim handle medium-sized text files on windows?

I am trying to open a 200MB text file in gvim on Windows, and it's choking. The vim window opens and just remains blank and unresponsive. My system has 8GB of RAM and the file opens fine in about 2-5 seconds using notepad.
I found this SO post on editing very large text files in vim, and I tried opening the file with plugins turned off:
vim -u "NONE" my200MBfile.text
But that didn't help. Is there anything else I can do to make it work? It seems strange that vim would choke on my machine on what is not really such a large file.
Thanks!
Most likely it's the syntax plugin that makes vim halt. I never have any issues with files of Mbs-Gbs. Unless I accidentally open them with some - not-so-well-behaved - filetypes.
Press ^C while loading/hanging (interrupting plugins)
:syntax off
Does the trick. There are other options with syntax that makes it easier to work with a file without fully 'synchronized' syntax highlighting
I played around with this some more, and I found indeed some of my plugins would make operating on (very) large files very slow. I did this, for fun:
On a large input file (~600Mb):
$ wc input.txt.full
2674568 2674568 608825278 input.txt.full
I launched vim with the following tweaks:
vim -u NONE -n +'se nonu nowrap ul=-1 | syn off' input.txt.full
Note this
-u NONE prevents execution of initialization (user) scripts and plugins
-n disables the writing of swapfiles (extremely important on slow/small disks)
se nonu nowrap ul=-1 disables
line numbering
line wrapping
undo history (setting undolevels to a negative value)
Basically, everything that could take a lot of CPU or memory
syn off to disables syntax highlighing (should only make a difference if syntax highlighting was in effect for the file type)
Now, I wanted to duplicate each line on the line itself (globally: copy line, join with previous):
:g/^/t.|-j
Unfortunately, the file would become too large for available memory (~3Gb)1 so I opted to act on the first 20% (~535,000 lines):
:exec "norm 20%"|1,.g/^/t.|-j
This works in a "jiffy" and without problems. Manual navigation (jumps, scrolling, mode switching, searching etc.) seems to be responsive.
Commandline Benchmark:
$ xxd -c 44 /dev/urandom | head -n 3800000 > input.txt.full
$ wc input.txt.full
3800000 91820644 627000000 input.txt.full
$ time vim -u NONE -n +'se nonu nowrap ul=-1 | syn off' input.txt.full +'exec "norm 10%"|1,.g/^/t.|-j' +wq
real 0m7.778s
user 0m6.680s
sys 0m0.952s
$ wc input.txt.full
3800000 101002757 689940307 input.txt.full
(Note that 689940307 ÷ 627000000 = 110.03 %, so that is exactly right).
This isn't slow in my book. For comparison, the wc invocation itself takes the same amount of time (7.7s).
1 All test performed on tmpfs to avoid cache differences.
The problem is more likely that vim doesn't like lines that long very much.
Try using a tool like json_reformat on the file first...
If you absolutely have to edit the file as-is, try :syntax off and possibly :set nowrap before you :edit the file in question.
Although Vim doesn't have a problem opening files of that size (or bigger), it is mentioned that it has a problem of opening a file with, as is your case, only one line (of that size).
You could try various workarounds, but I would suggest going with the "right tool for the right job" approach, and try EmEditor, a text editor made specifically for editing large files (amongst other things).
Note that this is not Vim bashing, but Vim is an editor for editing source code mostly. An excellent one at that, but like every other tool it has its limitations.

Unwanted control characters displaying in vimscript function output

[using MacVim 7.3 on OS X Lion]
I have a vimscript function which runs an external command. It's executing correctly, but the output displays (unwanted) control characters, such as [0m, [33m, [36m, and -1H. The relevant line in the vimscript function is:
exec ":!bundle exec rspec --color " . a:filename
Which produces:
:!bundle exec rspec --color spec/acceptance/user_logs_in.feature
[33m*[0m
Pending:
[33m User logs in [0m
[36m # the step 'the user "foo#test.host" exists' is not implemented[0m
[36m # [0m
Finished in 0.07121 seconds
[33m1 example, 0 failures, 1 pending[0m
Here's what the same command and output look like from the terminal, which is how I want it to display in vim:
$ bundle exec rspec --color spec/acceptance/user_logs_in.feature
*
Pending:
User logs in
# the step 'the user "foo#test.host" exists' is not implemented
#
Finished in 0.1161 seconds
1 example, 0 failures, 1 pending
Also, any time I execute and external command, vim displays -1H immediately after it. For example, if I type:
:ls<return>
I see:
:ls-1H
<rest of the output is as expected>
Any ideas on hiding those control characters and -1H.
(disclaimer: I'm very new to vim so please don't assume too much background knowledge on my part.)
Thanks.
Update 3/31/2012 # 17:32 PM
Sam Goldman's correct: MacVim doesn't know how to display colors, so it outputs the color codes.
I've switched to terminal vim (which supports colors, at least with iTerm), but using the version of vim that comes with MacVim, which is more up-to-date and is compiled with ruby support (among other things). The easiest way to do that is:
brew install macvim --override-system-vim
MacVim doesn't know how to display colors. Terminal vim will display the colors correctly, or you can add --no-color to your rspec command (or a .rspec file). I'm not sure about the -1H thing. Maybe some customization you have for your terminal?

VIM: dynamic runtimepath per module.vim and slow startup

I'm using VIM 7.1 on Debian. I have 9 plugins that I load via pathogen.vim. It takes around 8 sec's to load which is quite slow since this is in non-GUI/xterm mode. I ran vim -V and it shows that each module is being searched for in multiple directories.
Initially, ftoff.vim, debian.vim and other "system" related .vim files are searched for in ~/.vim/ and then in /usr/share/vim/vim71/ - I fixed this by moving my .vimrc to .vim/vimrc and: export VIM=/root/.vim, within .vimrc i did a set runtimepath=/usr/share/vim/vim71
But now, when the modules load, they alter this runtimepath and when pathogen loads it's even worse. Is there a way to specify a hash of module-name to dirPath so that this error prone lookup is avoided? Or a way to manually specify runtimepath on a per module basis within vimrc?
Here is an example of my runtimepath after pathogen loads my modules. Obviously, any further loading of a module invovles searching all those pathnames before locating the right path.
runtimepath=~/.vim,~/.vim/bundle/Align294,~/.vim/bundle/minibufexpl.vim_-_Elegant_buffer_explorer,~/.vim/bu
ndle/The_NERD_Commenter,~/.vim/bundle/The_NERD_tree,~/.vim/bundle/pathogen,~/.vim/bundle/vim-addon-mw-utils,
/.vim/bundle/tlib,~/.vim/bundle/snipMate,~/.vim/bundle/SuperTab,~/.vim/bundle/surround,~/.vim/bundle/taglist
~/.vim/bundle/Align294,~/.vim/bundle/minibufexpl.vim_-_Elegant_buffer_explorer,~/.vim/bundle/pathogen,~/.vim
bundle/snipMate,~/.vim/bundle/SuperTab,~/.vim/bundle/surround,~/.vim/bundle/taglist,~/.vim/bundle/The_NERD_C
mmenter,~/.vim/bundle/The_NERD_tree,~/.vim/bundle/tlib,~/.vim/bundle/vim-addon-manager,~/.vim/bundle/vim-add
n-manager-known-repositories,~/.vim/bundle/vim-addon-mw-utils,/var/lib/vim/addons,/usr/share/vim/vimfiles,/u
r/share/vim/vim71,/usr/share/vim/vimfiles/after,/var/lib/vim/addons/after,~/.vim/bundle/snipMate/after,~/.vi
/after,~/.vim/bundle/snipMate/after
I use vim-addon-manager and have 33 paths in rtp, but it takes around 0.7-0.8 seconds to start and immideately close vim (with vim -c 'qa!'), so the problem is either one of the plugins or your system. To check how long it takes to load each plugin, try the following script:
vim --cmd 'profile start profile.log' \
--cmd 'profile func *' \
--cmd 'profile file *' \
-c 'profdel func *' \
-c 'profdel file *' \
-c 'qa!'
You will get all timings in the profile.log. Table with function timings will be
present at the end of the file, to get per-script timings, use the following
script:
" Open profile.log file in vim first
let timings=[]
g/^SCRIPT/call add(timings, [getline('.')[len('SCRIPT '):], matchstr(getline(line('.')+1), '^Sourced \zs\d\+')]+map(getline(line('.')+2, line('.')+3), 'matchstr(v:val, ''\d\+\.\d\+$'')'))
enew
call setline('.', ['count total (s) self (s) script']+map(copy(timings), 'printf("%5u %9s %8s %s", v:val[1], v:val[2], v:val[3], v:val[0])'))
This will open a new file containing just the same table as at the end of
profile.log, but 1) for scripts, not for functions, 2) unsorted.
If problem is your system, you may try the following:
When computer starts create a ram disk and mount it to ~/.vim, then copy all plugins there.
Try merging plugins into a single file, see :h scriptmanager2#MergePluginFiles() (vim-addon-manager must be activated)
Upgrade your computer
Try creating a hardlinks to all plugins in ~/.vim:
cd ~/.vim/bundle;for d in *;do cd "$d";for f in **/*.vim;do t="$HOME/.vim/$(dirname "$f")";test -d "$t"||mkdir -p "$t";ln "$f" "$t";done;cd ..;done
it might not be related, but for me the variable DISPLAY makes a big difference in the time it takes to start vim (even when I have vim compiled without gui).
Try with
DISPLAY= vim
and
DISPLAY=:0 vim
and see if you notice a difference.
http://pastebin.com/R6E4czN7
I've pasted the output of vim -V to pastebin (should be valid for 1 month). It's self explanatory. There are a gazillion searches(414 search lines - most of them are useless). I need to reduce the number of incorrect searches.
1297651453.71068: Searching for "/root/.vim/bundle/pathogen/autoload/scriptmanager.vim"[J
1297651453.71456: Searching for "/root/.vim/bundle/snipMate/autoload/scriptmanager.vim"[J
1297651453.71846: Searching for "/root/.vim/bundle/SuperTab/autoload/scriptmanager.vim"[J
1297651453.78737: Searching for "/root/.vim/bundle/surround/autoload/scriptmanager.vim"[J
1297651453.79179: Searching for "/root/.vim/bundle/taglist/autoload/scriptmanager.vim"[J
1297651453.79684: Searching for "/root/.vim/bundle/The_NERD_Commenter/autoload/scriptmanager.vim"[J
1297651453.80756: Searching for "/root/.vim/bundle/The_NERD_tree/autoload/scriptmanager.vim"[J
1297651453.83: Searching for "/root/.vim/bundle/tlib/autoload/scriptmanager.vim"[J
1297651453.86193: Searching for "/root/.vim/bundle/vim-addon-manager/autoload/scriptmanager.vim"[J
1297651453.8662: line 3: sourcing "/root/.vim/bundle/vim-addon-manager/autoload/scriptmanager.vim"[J
1297651453.88259: finished sourcing /root/.vim/bundle/vim-addon-manager/autoload/scriptmanager.vim[J

Resources