(Mac)Vim quite slow when syntax is set to Ruby - ruby

I'm on MacVim 7.4 (I use the command line version), installed via Homebrew.
Vim is slow when syntax highlighting Ruby code. htop shows a 80%-100% CPU usage when moving inside a Ruby file in vim.
I found these here on SO:
Vim slow with ruby syntax highlighting
Syntax highlighting causes terrible lag in Vim
and tried the proposed solutions. What I did:
set regexpengine=1: nothing changed. Still very high CPU usage and slow performances.
set lazyredraw: things are better, but the tradeoff is very noticeable (cursor disappearing while moving)
I examined the autocmd statements in my .vimrc and found nothing slow in particular. I tried removing all the plugins but the problem is still there.
I tried turning the syntax off and, well, it solves the problem. Also, starting vim with vim -u NONE and then turning syntax on solves the problem, so it must be something in my .vimrc I guess?
Here's a link to my vimrc.
Edit
I may have found the guilty settings. It seems there are two settings that are noticeably slowing down movement in vim:
set relativenumber
set cursorline
Note that both of these settings trigger this behavior even alone.
These settings force vim to redraw quite a lot of stuff on the screen when scrolling holding j or k.
I doubt there's a solution here, but I'm very open to anything to speed this up.
Edit #2
Note that relativenumber and cursorline trigger this behavior only when used in Ruby files. Every other filetype I tried (with relativenumber and cursorline on) scrolls smoothly, no matter how long.

As avivr said, Vim is sometimes slow to (especially for ins-completion) in large files due to foldmethod=syntax
From :help todo:
Slow combination of folding and PHP syntax highlighting. Script to
reproduce it. Caused by "syntax sync fromstart" in combination with patch
7.2.274. (Christian Brabandt, 2010 May 27) Generally, folding with
'foldmethod' set to "syntax" is slow. Do profiling to find out why.
The FastFold plugin makes it so folds are only recalculated on save (so you're always using foldmethod=manual -- but the folds are calculated with foldmethod=syntax or whatever you had set before).
This solved the problem for me. Now I can use compl-whole-line completion in my 5000 line C++ file and it's instant and snappy instead of taking minutes and unresponsive.

Ruby syntax file has been known to be slow, it's better to disable 'cursorline', 'cursorcolumn' since they will cause the most effect.
However you should also have a look at Vim slow with ruby syntax highlighting. Something that could potentially also help improve things.

I had this issue, also tried set regexpengine=1 and various other things.
To me it seemed like the slowness was more or less severe depending on the size/complexity of file being edited, but it took a while to pinpoint the exact reason.
In my case the culprit was the following setting:
autocmd Filetype ruby setlocal foldmethod=syntax
This setting tells Vim to create folds automatically based on syntax elements (classes, functions, conditionals).
I don't think it matters that it was set with an autocmd in this case.
I think the problem was that for fairly complex files, the folds were updated during the editing process, causing dramatic slowness for complex files.
Hope this helps someone.

Related

Prevent clear from clearing previous screens in bash ubuntu-16.04

I'm trying to determine a way to stop clear from erasing previous terminal command history on ubuntu-16.04
I want it to have similar behaviour Ctrl+L, but I have got into the habit of typing clear instead (since it had this behaviour on my Ubuntu-14.04 before I upgraded).
Is there any easy way to do this?
My initial thoughts were to alias clear to a different command, but I'm not sure what this command would be like.
Can anybody assist with this or will I just have to get used to using Ctrl+L?
man clear:
clears your screen if this is possible, including its scrollback
buffer (if the extended "E3" capability is defined).
To find out if this extended "E3" is defined and how to change this behavior, this might be useful to you: https://superuser.com/questions/1094599/how-do-i-change-the-behavior-of-clear-on-centos7-such-that-it-will-not-clear

losing text while pasting into vi

I'm running into some trouble using Vim in OSX which is: whenever I copy outside of Vim and COMMAND + P to paste text inside, a few characters of the copied text gets deleted.
COPY: Function(){...... + 20 lines
PASTE n(){..... + 20 lines)
I know Vim has a lot of ins and outs... I use it without trouble on my Ubuntu setup. But I am not really expert with it yet and I have a feeling this is a basic issue mac users will have encountered. However, I was looking through the forums and googling it, and I cannot seem to find an answer.
Appreciate so much any help.
EDIT: I know this is a very basic question that someone might ask if they didn't understand the basics of Vi insert mode and hadn't like run Vimtutor. For me that was not quite the issue; I actually have been working of Vim for a while, but this default behavior had been changed early on (so I never noticed it).
I definitely would have wasted a lot of time before considering the basics of how insert mode works, so really thank you so much for your awesome, timely responses! I hope that this thread is useful to some other folks who're perhaps inadvisably pulled some "boilerplate" .vimrc off the internet, or have gotten used to Vim as configured by others... because the point of Stack Overflow isn't to explain to people things they should have picked in like 10 seconds from a man page or whatever.
It looks like you're not in insert mode when you're pasting, so Vim interprets the text as commands, until one letter (e.g. i or o) accidentally switches to insert mode. [1]
You need to go into insert mode first (i, also consider :set paste, and the 'pastetoggle' option; :help 'paste' has some background information).
Or (when supported), access the clipboard from within Vim, e.g. via "+p (normal mode) or <C-R><C-R>+ (insert mode).
As only the terminal-based versions of Vim have this problem of differentiating between typed and pasted keys, switching to the GUI GVIM (I think called MacVim there) would avoid this problem, too.
[1] Vim understands the example as:
Fu: backward find character u
n: next search match
cti: change until before the next character i (which aborts insert mode when there's no such character)
o: new line below the cursor and insert text

How to avoid follow-mode large text spillovers to the next windows when the text size is decreased?

When setting my text-scale-mode-amount to -2 i.e C-xC--C-- and using follow-mode alongside I get this annoying large amounts(20 lines) of text spillover in the next buffer which almost defeats the main purpose of using follow-mode. The spillover increases when the text-scale-mode-amount is further decreased(further decreasing the size of the text).
Any solutions to this?
Update 1:
Just tested this on my Emacs running on Ubuntu(Linux) and nothing of that sort happens. No spillovers. Its the Windows Emacs that is causing the problem.
Update 2:
Its a bug that is occurring in GNU Emacs 24.2.1 (i386-mingw-nt6.1.7600) of 2012-08-29 on MARVIN and seems to have been fixed in Emacs 24.3 since I am not facing the problem after upgrading to it. Therefore this question is specific to the above mentioned version of Emacs and others facing the same.
Simple solution:
Like phils suggested, upgrade the Emacs.
Not so simple solution:
Replace Emacs_installation_dir/lisp/follow.el with this and delete follow.elc in the same directory. Or force Emacs to use the above package instead of the built-in one(overriding it).
I think it's a bug in follow-mode which doesn't really pay attention to the actual text displayed. I'd recommend a report-emacs-bug to get a bug-number for that issue.

does vim read the whole file into memory

When I open a file, does vim read it all into memory? I experienced significant slowdowns when I open large files. Or is it busy computing something (e.g., line number)?
Disabling features like syntax highlighting, cursorline, line numbers and so on will greatly reduce the load and make Vim snappier in these cases.
There's even a plugin to handle that for you and a Vim tip for some background info.
Yes, Vim loads the whole file into memory.
If you run htop in another pane you can watch it happen in real time.
If you don't have enough memory available, it will start hitting the swap which makes it take even longer.
You can disable plugins and heavy features (like syntax highlighting) to get improved performance (the -u effectively tells vim not to load your ~/.vimrc):
vim -u NONE mysqldump.sql
However, unless you really need to edit the file, I prefer to just use a different tool. I typically use less. I mostly search the files in vim with / and less supports that just fine.
less mysqldump.sql

Emacs: some programs only work in ansi-term, some programs only work in shell

Relative Emacs newbie here, just trying to adapt my programming workflow to fit with emacs. So far I've discovered shell-pop and I'm quite enjoying on-demand terminals that pop up when needed for banging out the odd commands.
What I understand so far about Emacs is that shell is a "dumb" terminal that doesn't support any ansi control codes, and that makes it incompatible with things like ncurses that attempt to draw complex UI's on a terminal emulator. This is why you can't use less or top or similar in shell-mode.
However, I seem to be having trouble with ansi-term, it's not the be-all, end-all that it's cracked up to be. Sure, it has no problems running less or git log or even nano, but there are a few things that can't quite seem to display properly when they're running in an ansi-term, such as apt-get and nosetests. I'm not sure quite what the name is for it, but apt-get's output is characterised by live-updating what is displayed on the very last line, and then having unchanging lines of text scroll out above that line. It seems to be halfway between something like less and something dumber, like cat. Somehow ansi-term doesn't like this at all, and I get very garbled output, where it seems to output everything on one line only or just generally lose it's place and output things all over, randomly. In the case of nosetests, it starts off ok, but if any libraries spew out any STDERR, the output all goes to hell in a similar way.
With some fiddling it seems possible to fix this by mashing C-l and RET, but it's not always reliable.
Does anybody know what's going on here? Is there some way to fix ansi-term so that it can display everything properly? Or is there perhaps some other mode that I don't know about that is way better? Ideally I'd like something that "just works" as effortlessly as, eg, Gnome Terminal, which can run all of the above mentioned programs without a single hiccup.
Thanks!
I resolved this issue by commenting out my entire .emacs.el and then uncommenting and restarting emacs for every single line in the file. I discovered that the following line alone was responsible for the issue:
'(fringe-mode 0 nil (fringe))
(this line disables the fringes from inside custom-set-variables).
I guess this is a bug in Emacs, that disabling the fringe causes term-mode to garble it's output really badly whenever any output line exceeds $COLUMN columns.
Anyway, I don't really like the fringes much at all, and it seems I was able to at least disable the left fringe without triggering this issue:
(set-fringe-mode (cons 0 8))
Maybe apt-get does different things based on the $TERM environment variable. What happens if you set TERM=dumb? If that makes things work, then you can experiment with different values until you find one that supports enough features but still works.
Note that git 2.0.1 (June 25th, 2014) now better detects dumb terminal when displaying verbose messages.
That might help Emacs better display some of the messages received from git, but the fringe-mode bug reported above is certainly the main cause.
See commit 38de156 by Michael Naumov (mnaoumov)
sideband.c: do not use ANSI control sequence on non-terminal
Diagnostic messages received on the sideband #2 from the server side are sent to the standard error with ANSI terminal control sequence "\033[K" that erases to the end of line appended at the end of each line.
However, some programs (e.g. GitExtensions for Windows) read and interpret and/or show the message without understanding the terminal control sequences, resulting them to be shown to their end users.
To help these programs, squelch the control sequence when the standard error stream is not being sent to a tty.

Resources