What does ragtag plugin do - vim

I am reading the doc still not sure what the plugin does.
https://github.com/tpope/vim-ragtag/raw/master/doc/ragtag.txt
Any further clarification will help.
Thank you.

The ragtag plugin only works with certain filetypes, which can cause some confusion, especially when editing an unsaved document.
*html*,wml,jsp,php,asp*,cf,mason,eruby,liquid,xml,xslt,xsd,docbk

It adds tags based on shortcuts. Its actually really useful for certain things.
For instance, in rails, you write the word foo (as in all the examples), press <C-X>+ and you get (^ is where your cursor ends):
<%= foo^ %>

Related

Variables in snipMate definition, is it possible? (vim)

I use vim for programming purposes and I use the snipMate utility. I'm aware of the basic snippets definition, but I'm trying to do something like the following (this doesn't work):
snippet ${1}_.
<$1 class="${2}">${3}</$1>
I think it would be easier to explain with an example. What I'm trying to do is to insert a html tag when typing a word followed by _. :
So if I type div_. and press tab, it should change to:
<div class="(position of cursor)">(position of cursor)</div>
If I type span_. and press tab, it should change to:
<span class="(position of cursor)">(position of cursor)</span>
And so on. Hope you get the idea. I'm aware that I can write a snippet for every case, but I'm trying to avoid that.
Thanks!
Make the snippet do the hard work for you:
snippet tag
<${1:div} class="${2}">${3}</$1>
You may also want to take a look at emmet-vim and surround.vim.

Preprocessing a word before spell checking in Vim

I use Vim's spell checking to validate texts in Russian. We have letter ё in our alphabet which is often replaced with simple е. So, for example, word ёжик из written as ежик. It is a bad tone actually. Its like using - (hyphen) where — (em-dash) is required, like using "computer" quotes forgetting about existence of „typographic” «quotes», etc.
The bad thing is that spell dictionary for Vim composed out of simplified words with all ёs, replaced with еs. So I always get an error in a word with ё.
So the question, is there any hook I can use that will allow me to normalize a word just before it will be spell checked? Or maybe someone has a better idea? Thanks.
UPDATE
With the hint from #sarnold, I found the solution. One should use ru_yo locale instead of ru_ru if he wants ёёёёё
My first thought when reading your post was to suggest using zg to add the word to the spellfile; after a few weeks you'll have a lot of them. Not ideal, but simple.
:help spell-russian lists several different spelling variations, would one of these help?
I also notice in :help spell.txt that there are options for downloading your own spellfiles from OpenOffice or http://www.a-a-p.org to automate building spellfiles.
I would recommend you to use your own spell checking for vim. Use a method #2 explained here

Which editors out of Emacs, Vim and JEdit support multiple simultaneous text insertion points?

Background: JEdit (and some other text editors as well) support a feature called Multiple simultaneous text insertion points. (at least that's what I'm calling it here).
To understand what this means, take a look at the link.
Out of all the features in use in modern text editors, initial research seems to indicate that this is one feature that both Emacs and Vim do not actually support. If correct, this would be pretty exceptional since it's quite difficult to find a text editor feature that has not made its way into at least one of these two old-school editors.
Question: Has anyone ever seen or implemented this feature in either Emacs, Vim, or both? If so, please point me to a link, script, reference or summary that explains the details.
If you know an alternate way to do the same (or similar) thing, please let me know.
The vim way to do this is the . command which repeats the last change. So, for instance, if I change a pointer to a reference and I have a bunch of
obj->func
that I want to change to
obj.func
then I search for obj->, do 2cw to change the obj-> to obj., then do n.n.n. until all the instances are changed.
Perhaps not a flexible as what you're talking about, but it works frequently and is very intuitive and fast when it does.
moccur-edit.el almost does what you want. All the locations matching the regexp are displayed, and the editing the matches makes changes in the corresponding source. However, the editing is done on a single instance of the occurrence.
I imagine it'd be straight forward to extend it to allow you to edit them all simultaneously (at least in the simple case).
There is a demo of it found here.
Turns out, the newest versions of moccur-edit don't apply changes in real-time - you must apply the changes. The changes are also now undoable (nice win).
In EMACS, you could/would do it with M-x find-grep and a macro. If you really insist that it be fully automatic, then you'd include the find-next in the macro.
But honestly, this strikes me as a sort of Microsoft-feature: yes, it adds to the feature list, but why bother? And would you remember it existed in six months, when you want to use it again?
For emacs, multiple-cursors does exactly that.
Have a look at emacsrocks episode 13, by the author of the module.
I don't think this feature has a direct analogue in either Emacs or Vim, which is not to say that everything achievable with this feature is not possible in some fashion with the two 'old-school' editors. And like most things Emacs and Vim, power-users would probably be able to achieve such a task exceedingly quickly, even if mere mortals like myself could spend five minutes figuring out the correct grep search and replace with appropriate back-references, for example.
YASnippet package for Emacs uses it. See 2:13 and 2:44 in the screencast.
Another slight similarity: In Emacs, the rectangle editing features provided by cua-selection-mode (or cua-mode) automatically gives you multiple insertion points down the left or right edge of the marked rectangle, so that you can type a common prefix or suffix to all of those lines.
e.g.:
M-x cua-selection-mode RET (enable the global minor mode, if you don't already use this or cua-mode)
C-RET down down down (marks a 1x3 character rectangle)
type prefix here
C-RET (unmark the rectangle to return to normal editing)
It should be something like this in vim:
%s/paint.\((.*),/\1.paint(/
Or something like that, I am really bad at "mock" regular expressions.
The idea is substitute the pattern:
/paint(object,/
with
/object.paint(/
So, yes, it is "supported"
It seemed simple to do a basic version of this in Emacs lisp. This is for when you just want two places to insert text in parallel:
(defun cjw-multi-insert (text)
"insert text at both point and mark"
(interactive "sText:")
(insert-before-markers text)
(save-excursion
(exchange-point-and-mark)
(insert-before-markers text)))
When you run it, it prompts for text and inserts it at both point (current position) and mark. You can set the mark with C-SPC. This could be easily extended for N different positions. A function like set-insert-point would record current position (stored as an Emacs marker) into a list and then when you run the multi-insert command, it just iterates through the list adding text at each.
I'm not sure about what would a simple way to handle a more general "multi-editing" feature.
Nope. This would be quite difficult to do with a primarily console-based UI.
That said, there is similar features in vim (and emacs, although I've not used it nearly as much) - search and replace, as people have said, and more similarly, column insert mode: http://pivotallabs.com/users/brian/blog/articles/350-column-edit-mode-in-vi

How do I get Vim to automatically put ending braces?

While editing .scm files it would be great if Vim would automatically put the ending brace ) as soon as I start (. How do I do this?
You can map the opening brace to your liking:
:imap ( ()<left>
Try to use AutoClose plugin.
The simplest answer is to include a map. Eg.:
:inoremap ( ()<left>
The problem is that you would need to add one entry for each symbol you want automatically closed ('{','[','"',etc). Besides, plugins are normally more smart, providing things like detecting the "closing" character and not repeating it.
The problem with the solution above and most plugins, is that they tend break the undo sequence (gundo anyone?), as explained in:help ins-special-special.
Here is list of plugins that do what you ask (from vimtips):
delimitMate by Israel Chauca Fuentes (configurable, and doesn't break undo/redo/repeat, but - break iabbr) also on GitHub
AutoClose by Karl Guertin (auto-closes specific hard-coded characters, but doesn't break undo/redo/repeat)
AutoClose by Thiago Alves (configurable, but breaks undo/redo/repeat)
auto-pairs Auto Pairs by Miao Jiang (configurable, but breaks undo/redo/repeat)
ClosePairs by Edoardo Vacchi (configurable, but breaks undo/redo/repeat)
smartinput by Kana Natsuno (configurable, but breaks undo/redo/repeat)
Besides vimtips, there is another nice explanation of the issue on the web.
I needed one too, and I already tried a few of the plug-ins:
AutoClose, http://www.vim.org/scripts/script.php?script_id=1849, is a bit aggressive.
simple pairs, http://www.vim.org/scripts/script.php?script_id=2339, depends on Python. If you are on Linux it is not a problem, but on Windows it can be a trouble to match the Vim version to the Python interpreter you have.
My advice would be ClosePairs, that you can find at http://www.vim.org/scripts/script.php?script_id=2373 which has been working perfectly for me. It is simple and useful.
There are many tips and plugins on the subject. Have a look at the relevant entry in the vimtips site.
I'm presently using auto-pairs and it works quite very well.
The issues of the the plugin breaking undo/redo/repeat seem to persist among some of the plugins listed above but i don't think its much of an issue (well, at least not to me at the moment).
Just one caveat though, i wasn't able to use :helptags to generate the help file with this plugin as at the time of writing this.
Check out this new plugin: vim-autoclose by Townk. The previously mentioned AutoClose was to aggressive, sometimes behaving in an undesirable way.
There is a problem with using this (via the imap or one of the scripts). You won't be able to repeat the complete edit by using the . command.
e.g. (foo) with . only gets you foo, without the brackets.
It works fine if you insert the brackets normally, as two characters.
You can try downloading the following plugin
AutoClose : Inserts matching bracket, paren, brace or quote
https://github.com/vim-scripts/Auto-Pairs
Tested this plugin for undu redo. 2013 It just works. Also with python-mode plugin.
There is a new plugin by cohama:
lexima.vim (github)
(not yet on vim.org)
This plugin supports the .command!
Afaik, this is the only plugin supporting this.
Also the undo/redo sequence works.

What is the most convincing command in Vim

I want to ditch my current editor. I feel I need something else. That do not expose my hands to the risk of RSI. I need to see why I should change editor. And it would be nice to believe, that I will be coding when I'm 80 years old.
All the big guys out there are using Vim. The only Emacs guy I know are RMS. Paul Graham is a Vi dude.
. (dot) - repeats the last editing action. Really handy when you need to perform a few similar edits.
:help usr_12.txt
That'll bring up a section in the help system that discusses "Clever Tricks". If those don't get you excited I don't know what will!
Recording macros
The asterisk.
*
Its effect: Immediately search for the next instance of the word under the cursor.
The best thing is the efficiency with which you can edit code (which is done a lot in programming). The commands such as
cw to change a word
dw to delete a word
ct, to change all text until the next comma
ci( to change the contents of the parentheses you're currently in
xp to correct spelling mistakes ("spleling" -> cursor on l -> xp -> "spelling")
o to insert a new line below and start editing
O to insert a new line above
Then there is the possibility to work with named registers very quickly. To move a block, just select it, press d, then move to it's new location and press p. Much faster than Ctrl-C and Ctrl-V. Use "ud to delete text and move it to register u (I use this one for the commenting template).
And also Vim has all the scripting support you need (either using it's native scripting language or using Python, Ruby, ...)
the numbers.
in command mode
type a number ( any number of digits )
type a command.
that command will be executed $number times
ie:
99dd
erases the next 99 lines.
The fast startup time.
The sharp distinction between editing and viewing. (you know when you edit)
The only way you ever find what you are looking for is with search "/" and that is good, since it much faster than your eyes.
But the best command(s) are:
/ - search string
ZZ - quit
. - repeat last insert (I think)
%! - insert unix command
Handling multi line regexps in search strings with "\_.". While checking over 4GB text files of various formats, it had saved my life several times.
Why are you looking to be convinced to start using a different editor? If you're happy with what you have now, stick. If not, perhaps ask about editors with features that you lack.
Even if you are using Visual Studio there is the wonderful vsvim.
I love the speed of Vim but I find it lacks the features of a modern IDE for C++ development. Eclipse CDT with the viPlugin is a good compromise.
You get the power and source overview provided by Eclipse CDT with the speed and flexibility of Vim for coding.
The lovely built in regular expression evaluator.
Maybe reading "Come home to vim" by Steve Losh article is a good start, or
a series of videos about interesting plugins. And be sure to see some articles on the site vimcasts.org
You should map Caps Lock to Esc. It will make getting out of insert mode feel natural as opposed to the awkward move you must make to press the ESC key. Besides, who uses Caps Lock anyway?
\v
Make your regular expressions mostly Perl compatible.
See very magic section here for more information.
To be truly inspired, you must see a vim guru in action. If you do not have a local guru, here is a video to inspire you.
http://www.youtube.com/watch?v=jDWBJOXs_iI&feature=related
If you don't already know vim, the speed at which code is navigated, sliced, and diced will be indistinguishable from magic. After a few months of studying vim, the same editing speed will seem commonplace.

Resources