Prevent vim from loading sessions when reading from stdin - session

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

Related

VBScript Nothing returns garbage

We have to use VBScript as an embedded script engine in our Hospital Information System.
When we use nothing to set the value of a control (textbox/checkbox/...) it worked always fine. Since somepoint it sets now the textbox to "?>".
item("TEXTBOX").value = nothing ' Leads to -> "?>"
It is not completly clear what causes this, maybe a windows update is responsible, every rollup ~ since KB3212646 Win7 2017-01 seems to cause this error.
My Question is now, has someone else also seem this error, so that it is clear that MS causes this error or is our HIS publisher responsible for not handling nothing correct.
I know setting a textbox to Nothing is not best practice instead "" should be better, but since the item object could be more the just a textbox e.g. a combobox/checkbox this seems, from an objectoriented perpsective, better. Or am I completly wrong?
Following #Ansgar comment, you should apparently change everywhere you have = nothing to = "" in your example
item("TEXTBOX").value = ""
Beware to keep the nothing if you have the Set keyword in left
Set some_object = Nothing

VIM: Ruby methods with ? and ! in the end

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.

VIM prompting for a variable when running a macro?

I find I waste a lot of time closing and reopening sets of files so I'd like to improve my VIM macro for loading and saving the session to support multiple sessions.
I'd like for it to prompt for a string value, so that I could press my shortcut, then type in for example "foo", and have my macro save the session to .foo (so I also need to do basic string concat on it). Then I'd do the same for the load macro and manage sessions by theme (using MVC framework you tend to have a lot of files to work with).
" Control-S to save and Shift F5 to load
set sessionoptions=tabpages,winpos
map <S-F5> :source ~/.vim/.session<cr>
map <c-s> :mksession! ~/.vim/.session<cr>\| :echo "Session saved."<CR>
I have very little experience of VIM scripting. Is it possible to do this in a one liner, or perhaps a small function?
Thank you.
map <s-f5> :execute "source ".input("session name: ", "~/.vim/session.", "file")<cr>
Enter "foo" to load "session.foo".
Instead, you can also do:
map <s-f5> :source ~/.vim/session.
Note there isn't a <cr>, so you complete the command yourself and press enter — identical typing as above, even down to filename completion.
However, I'd look at calling a function or something else entirely at about this point.
Here's the snippet I have now, in case someone needs something similar (no need to vote). It saves sessions under .session.xyz which are also excluded from my Git project. I like to store them in the Git project folder so they are saved with backups.
I like confirmation echo as well because when you press enter after saving the session otherwise you can't see that anything happened. It's just for feedback.
map <S-F5> :execute "source ".input("Load session: ", "~/Some/Project/.session.", "file")<cr>
map <c-s> :execute "mksession! ".input("Save session: ", "~/Some/Project/.session.", "file")\| :echo "Session saved."<CR>
The file completion makes this very handy, thank you!

Codefolding IF|FOREACH for textmate

Hope someone can help.
I am a new user to textmate and want to add code folding to if|endif & foreach|endforeach on textmate.
These are the current supported folds
foldingStartMarker = '(/\*|\{\s*$|<<<HTML)';
foldingStopMarker = '(\*/|^\s*\}|^HTML)';
I have tried
foldingStartMarker = '(/\*|\{\s*$|<<<HTML|if)';
foldingStopMarker = '(\*/|^\s*\}|^HTML|endif)';
Which starts the fold for an if but the stop Marker is not being picked up.
Has anyone else done this ?
Hope you can advise
Change The HTML bundle instead of the PHP bundle!
I've changed |array\s?(\s*$ into |array(\s*$ to get array folding. This might work for you as well.
I've also tried this: |array\s*(\s*$ because I want to fold array( as well as array ( or array (. I don't know if this is exactly the right syntax, but it works perfectly!
Thanks to Chris Adams:
http://old.nabble.com/Any-chance-of-a-little-help-sorting-this-language-regexp-to-make-php-coding-less-painful-in-textmate--td30458020.html

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