VIM: Ruby methods with ? and ! in the end - ruby

I'm trying to use VIM completion (dictionary and current buffer), but i'm running into issues with ? and ! in the end of method names. Can i somehow explain to vim that method names (words basically) can have it only in the end and only one i.e. method_name? not bull???!!shit!? or if !xyz ... (when ? and ! added iskeyword !xyz exists in completion list). Any ideas how to do that?

IIRC, you have to modify the iskeywordoption.
You can try set iskeyword+=?,!so that ? and ! are considered as part of words and not separator.
In your .vimrc, you can add :
autocmd BufRead,BufNewFile *.rb set iskeyword+=?,!
See :help iskeywordfor more information.
Edit : I had not seen you had already mentioned iskeyword as a possible workaround.
Alternate idea :
1. Generate ctags for your ruby code.
2. in the complete option remove everything except the t option meaning tags only.
You are only going to have suggestions coming from the tag file. The downside is that it adds a new step to use completion and you will miss some non-tag completion.

Related

Why do we need the question mark in Immediate Window of VS?

So, reading this documentation:
https://learn.microsoft.com/en-us/visualstudio/ide/reference/immediate-window?view=vs-2022
It looks like the question mark (?) is an alias for the command >Debug.Print, which basically, will evaluate the expression and show the result.
So, in debug mode, instead of running this:
>Debug.Print DoSomething()
I can run this:
? DoSomething()
This is even better because I'm getting the autocomplete suggestions.
Now, the issue is that I can run the same line without a command at all, and it does exactly the same:
DoSomething()
So far looks like there is no need for the command >Debug.Print or the alias ?.
At first, I suspected that using ? will only print the result without changing the values, but this is not the case (When I assign a value to a variable using ? it is assigned and the new value is printed)
So, am I missing something here? Are there any other differences between these 3 options?
According to the documentation, if you want to use Visual Studio command, you need to add greater than sign before the command. If you run 'Debug.Print' without adding greater than sign, you will get an error.
My point is that the question mark ('?') is unnecessary if you in the Immediate Window, it is used to distinguish the typed expression from the result.

In Vimperator how to configure the number of lines of proposal when using the command ":history" ?

I'm using Vimperator.
I'd like to configure the number of lines that are display by Vimperator ,as proposals, when I'm looking up in history with the command
:history
for the moment my page is completely covered with proposals.
in my vimperatorrc i configured
previewheight=20
in order to have 20 propositions when I'm using completion on the command line but this is working with open completion not with :history.
My Question:
how can i set the numbers of lines I'd like to have displayed as proposals when I type the command ?
:history
thank you for your help.
Use the -max flag, for example:
:history -max=20

Is there a way to fold all multi-line Ruby comments in Vim?

I'm working on a Ruby gem and I would love to be able to hide all the documentation comments in the file because they are more for people using the library than reading or writing the code. I see the value in having the comments, but when I'm working on the code they are visually distracting to me.
In MacVim I can manually fold lines of code by selecting them and clicking Tools > Folding > Create Fold, but is there a way to automatically hide all comments using some sort of shortcut?
For example, the following code:
# Returns a 2D array for Rails select helper options.
# Also used internally for Formtastic support
#
# ==== Example
# # Create an Enum with some elements
# class Priority < ClassyEnum::Base
# end
#
# class Priority::Low < Priority; end
# class Priority::ReallyHigh < Priority; end
#
# Priority.select_options # => [["Low", "low"], ["Really High", "really_high"]]
def select_options
map {|e| [e.text, e.to_s] }
end
would be displayed as:
def select_options
map {|e| [e.text, e.to_s] }
end
You could try this method:
:set fdm=expr
:set fde=getline(v:lnum)=~'^\\s#'?1:getline(prevnonblank(v:lnum))=~'^\\s#'?1:getline(nextnonblank(v:lnum))=~'^\\s*#'?1:0
The problem is that this method would become the only folding option so that's probably a little bit extreme.
I guess you would like to play with vim’s foldmethod setting. Sorry for slightly vague answer, but I have no MacVim here so you are supposed to adjust directories/filenames in my suggestion yourself.
First of all, try :setlocal foldmethod=syntax in command mode to enable folding within your current file only. If it works, you have all the prerequisites installed (namely, the ruby.vim syntax file.) Try to add let ruby_fold=1 to your .vimrc file. The latter should enable folding over all ruby files (or, alternatively you may explicetely set folding to true for all filetypes supporting folding with set foldmethod=syntax.)
Now you are to find ruby.vim over your file system to tune it up. To give a hint, on Linux distros it’s located at /usr/share/vim/vim73/syntax/ruby.vim. My syntax file enables folding for all the stuff which “may” be folded (e. g. functions, methods, etc.) Copy the original file to your $HOME/.vim/syntax directory and adjust it according to your needs. Navigate through it (by searching for fold, for instance) and remove fold keyword where you don’t want the folding is applied. The names in syntax file are self-explanatory, so you would not be in trouble here.
Restart vim and enjoy your folding. Hope that helps.

Prevent vim from loading sessions when reading from stdin

I've been customizing my .vimrc a lot lately and love the power and convenience that :mksession gives me. I currently have the following in my .vimrc to autoload sessions:
function! LoadSession()
if argc() == 0 && ! &diff
let g:sessiondir = $HOME . "/.vim/sessions" . getcwd()
let g:sessionfile = g:sessiondir . "/session.vim"
if (filereadable(g:sessionfile))
exe 'source ' g:sessionfile
else
echo "No session loaded." + argc() + argv()
endif
else
let g:sessionfile = ""
let g:sessiondir = ""
call ResCur()
endif
endfunction
I then call this with au VimEnter * nested :call LoadSession(). This works great for most cases, except when vim is reading from stdin. In that case the session is still loaded, however I want to prevent that from happening. I would have thought the argc() == 0 conditions would be enough, but it appears that the - that vim is being called with to read from stdin causes argc() to not return 0. Poop! ;]
I've tried all sorts of things from looking at argv(0) (it's empty in this case - why?), trying to find ways of identifying that vim is reading from stdin (it shows a message that it's doing so, but I can't figure out how to tap into that), etc., but no luck so far.
I'm sure I'm missing something terribly obvious here, but the Googles and vim :help isn't getting me anywhere, so I'm hoping some kind soul here can shed some light on this for me.
What I found works is having
autocmd StdinReadPre * let g:my_is_stdin = 1
in your .vimrc and then test for exists("g:my_is_stdin") in your session saving/loading functions. Mind that these have to be run also via autocmd on events VimLeave/VimEnter for this scheme to work.
The session.vim plugin that I'm using offers extended session handling. Among others, it asks whether a previously saved session should be restored on Vim startup.
But unless you need the other functionality of the plugin, your workaround with mappings triggering the restore is probably fine, too.
I've been fiddling a lot with loading sessions on Vim startup, and ultimately decided that's it's not a very good idea, mainly because it doesn't work well with plugins.
I ultimately added some mappings for saving and restoring a session. This has the bonus that you don't have to mess arround with your session when you're doing quick edits.
map <leader>ss :call CustomSessionSave()<CR>
map <leader>sl :call CustomSessionRestore()<CR>
map <leader>sd :call CustomSessionDelete()<CR>
Maybe this helps

I get this window while editing Ruby Files in Vim. What is it?

I usually get this new window open up suddenly while I am editing a Ruby file in VIM. This is getting irritating because, i cant type in anything while its processing. And it usually happens arbitarily. Does any one here know which plugin could be doing this? Or is this somekind of VIM's process?
This is happening when you hit K in normal mode.
K Run a program to lookup the keyword under the
cursor. The name of the program is given with the
'keywordprg' (kp) option (default is "man"). The
keyword is formed of letters, numbers and the
characters in 'iskeyword'. The keyword under or
right of the cursor is used. The same can be done
with the command >
:!{program} {keyword}
There is an example of a program to use in the tools
directory of Vim. It is called 'ref' and does a
simple spelling check.
Special cases:
- If 'keywordprg' is empty, the ":help" command is
used. It's a good idea to include more characters
in 'iskeyword' then, to be able to find more help.
- When 'keywordprg' is equal to "man", a count before
"K" is inserted after the "man" command and before
the keyword. For example, using "2K" while the
cursor is on "mkdir", results in: >
!man 2 mkdir
- When 'keywordprg' is equal to "man -s", a count
before "K" is inserted after the "-s". If there is
no count, the "-s" is removed.
{not in Vi}
If you notice, it's running ri in the open window, which is the ruby documentation app.
In Unixy environments, the help program normally runs inline, just displacing the vim output for a minute.
Is this using gvim, or command-line vim?
In either case, you can try monkeying with 'keywordprg' to fix the popup
Or, if you can't train yourself not to type it, you can just use :nnoremap K k to change what K does (in this case, just treat it as normal k command and go up one line).
I have this same issue on my work desktop, but not my home machine. The setups are near identical.
While stalking down a possible cause, I noticed that when I leave my cursor over a Ruby symbol such as File, Vim would popup a short description of the File class. After comparing all the various vim scripts and ri-related files that I could find, I finally settled on the only solution that worked...
Open $HOME/_vimrc and add the following line:
autocmd FileType ruby,eruby set noballooneval
Previously, I commented out a block in $VIMRUNTIME/ftplugin/ruby.vim, but Brian Carper suggested a better solution of :set noballooneval. I added the autocmd line so it is only executed with Ruby files.
If anyone figures out a true solution, please contact me. :(

Resources