How to delete everything between angle brackets in VIM globally? - vim

Say I have a text such as
file.wav;0.000;12.015;Spreker-C;;;<lang:English> Yes </lang:English> Niko. <lang:English> Yes </lang:English> Niko, gaan ons verder praat oor die #um leerbesigheid? [no-speech]
and I want to delete everything between the angle brackets so i would have
file.wav;0.000;12.015;Spreker-C;;;Yes Niko. Yes Niko, gaan ons verder praat oor die #um leerbesigheid? [no-speech]
How do I do it globally?
If it was just one line, it would be an easy solution such as da<. However how do I delete everything for all lines in the file?

Search and replace with :s/<.\{-}>//g should work, assuming you don't have nested <>. <.\{-}> is a pattern that matches brackets and content inside in a non-greedy manner;

Related

How to force vim spellchecker to ignore lowercase/uppercase errors

I found here and here how to force Vim spell checker to ignore words with capital letters from being check. But my case is quite opposite. I want to ignore words that in corrected form include capital letters.
So in sentence:
europe was chozen best
only word chozen is the wrong one.
How to achieve that?
Thanks for any hint.
This answer was posted first by Rich on vi&vim stackexchange:
I don't think that Vim has a setting for this. One workaround is to
create a new spellfile that contains everything in your current spell
file(s) but with lowercase letters only:
Create a new buffer containing everything from the spell file(s) currently in use:
:spelldump
Delete lines that don't contain any upper-case characters. This isn't strictly necessary, but there's no point keeping duplicate
entries for lower-case words:
:v/\u/d
Convert the entire file to lower-case, ignoring lines that contain the locations of the spell files:
:v/^#/norm gu$
Save the file:
:w ~/.vim/spell/lowercase.utf-8.add
Start using this file in addition to the standard files in Vim's $VIMRUNTIME directory. Note that Vim uses a default 'spellfile'
value internally if the setting is empty, so if you already have any
existing spell files, you will need to ensure that they are included
in this setting (which accepts a comma-delimited list):
:set spellfile=~/.vim/spell/lowercase.utf-8.add
Note that if you set this option in a running instance of Vim, it
doesn't seem to take effect for spell-checking until you interact with
it (by, e.g. using the zg command.)
The above doesn't affect the way that Vim detects lower-case words at
the start of a sentence as spelled incorrectly. You can disable this
with the 'spellcapcheck' option:
:set spellcapcheck=

Where is '$' under the "normal mode" (after esc-pressing mode) in "Vim" text editor?

I have hard time realizing, as a beginner, why in "Vim" (Windows 10), when I want to delete a word with a d$ and when I simultaneously press shift+4 on non-numeric key above qwerty... why "Vim" does not recognize that as a $?
I strongly believe that you confusion stems from the fact that d$ is not actually meant to delete a word. Moreover, dw (which sound pretty much like "delete word") is not meant to delete a word either.
d is a command that will perform its action (deletion) on the next movement right after the command. Note that $ moves to the end of the line, and w moves to the beginning of the next word. Therefore:
d$ deletes from the cursor position until the end of the line.
dw deletes from the cursor position until the beginning of the next word.
For a better example you should try d3j. 3j moves three lines below, therefore d3j deletes the current lines and the next three lines as well.
To delete the word under the cursor (no matter where the cursor is in the word) there are several ways. Some ways to do it:
bdw first move to the beginning of the word then delete 'till the next word.
vawd visually select the word a word (including the space after the word) and delete it.
viwd visually select an inner word and delete it (this leaves the spaces around the word in peace).
daw delete a word (without going into visual).
diw delete inner word (without visual).
(Try the visual ones first to see how they work, then you can use the non-visual ones.)
Also, we have a vi.SE section of the website.
I've finnaly understand it... a cursor must be BEFORE a related "tail" to be eliminated.
PS: In fact problem was with "e212 error: can't write to file"... instead of changing proposed "sudo permissions", while I'm on Win 10 instead, I've just reinstalled a fresh Vim.
So, problem were not with "$" (as it was where always have been) but when one is unsure where problem lies, often makes a wrong diagnosis.

How to delete values between xml tags in Vi editor

I want to replace the value between below xml tags in VI for all the columns ending with AM
<property name="EQ_BNKCRD_30PL_DPD_BAL_AM" desc="EQ_BNKCRD_30PL_DPD_BAL_AM">+000026928134473.000</property>
simply +000026928134473.000 should be removed in the above tags
I have tried :%s/_AM">*.*</_AM"></g
but the output is this
<property name="EQ_RVLV_TRD_OPN_HI_LC_AM"><property>
from the above the desc part is removed and in property tag / is removed
dit
in normal mode, which means delete inside tag. If you do 'dat' delete around tag it would delete the tag too.
You want to match everything from _AM"> up to the next <. So this should work:
:%s/_AM">[^<]*</_AM"></g
The important change is from >*.* (which doesn't actually make much sense as it matches any number of > symbols and then anything after) to >[^<]* which means match one > and then anything that isn't a <.
how about :
%s/_AM">\zs[^<]*//
It might be easier to use a macro in this case. To delete the contents in between tags you can use dit. The following sets the search register to _AM> and just looks for the next match types dit every time it finds a match.
let #/='_AM">' | let #a='ndit#a' | set nowrapscan
Then go to the top of the file gg and run the macro that was stored in register a with #a. set nowrapscan is necessary to make sure the macro never goes on forever.
Why not record a macro that searches for the next occurrence of AM">, move the cursor a few characters to the right into the tag, and then dit for "Delete In Tag" -- then just play it back a ton of times
I often find it faster in cases like this to record a simple macro rather than taking the time to find a regex that works.
Edit: full sequence, separated logically
/AM">
qa
llll
dit
n
q
500#a

Spellchecking in Vim - tell Vim that this is okey

Yes, that title is the best I could come up with :-)
I have a text, and when activating spellchecking naturally a lot of words come out highlighted. Like emails, adresses, names and so on. How to tell Vim that some word is okey, without adding it to the wordlist.
Meaning, just, while editing this document I don't want to see my name highlighted.
Try: zG
:help internal-wordlist
From http://vimdoc.sourceforge.net/htmldoc/spell.html
zg Add word under the cursor as a good word to the first
name in 'spellfile'. A count may precede the command
to indicate the entry in 'spellfile' to be used. A
count of two uses the second entry.
In Visual mode the selected characters are added as a
word (including white space!).
When the cursor is on text that is marked as badly
spelled then the marked text is used.
Otherwise the word under the cursor, separated by
non-word characters, is used.
If the word is explicitly marked as bad word in
another spell file the result is unpredictable.
I have my Vim config in a git repository, which is useful for several things; For example, you could alias your vim to a small script that invokes Vim normally, but after Vim finishes checks if the ~/.vim/spell directory has any modifications and if so, asks you if you want to keep or discard them. If you want to keep them, it could automatically commit everything in spell and otherwise reset everything in there. So you usually wont be bothered by that script unless you actually do use the spellchecker.
The only drawback would be that you couldn't both make persistent and volatile additions to the dictionary in one session.

Is there a good Vi(m) command for transposing arguments in a function call? Bonus points for Emacs

For example if I have some code like:
foo = bar("abc", "def", true, callback);
Is there a nice command to move true to the 1st or 2nd position leaving the commas intact?
P.S as a bonus my friend want to know if this works in Emacs too.
In Vim if you place the cursor at the start of the first word and do dWWP then it will have the desired effect. Here is a breakdown:
dW delete the current word, including the comma and the following whitespace
W move to the start of the next word
P insert the deleted text before the cursor
This will work if there are further parameters after the pair to be swapped - it will need to be modified if there are only two parameters or you want to swap the last two parameters, since it will paste the text after the closing bracket.
Alternatively you could use a regex substitution:
:%s/(\([^,]\+\),\s*\([^,)]\+\)/(\2, \1/
This will find the first two arguments after the open bracket and swap them.
update:
A search of vim.org found the swap parameters plugin, which should do exactly what you want and can handle situations that either of the above methods cannot.
I don't know the answer for vi, but in Emacs, transpose-sexps (C-M-t) will swap two arguments either side of the cursor. Actually transpose-words (M-t) was my first guess, but that leaves the quotes behind.
You need a transpose emacs command. But its limited to not guessing that its transposing in lists, it only considers text (it can't guess the 1st, 2nd word of list). Try this.
Keep your cursor at after comma of true. Use M-x transpose-words. By default it will transpose with next word from the point. Shortcut is M-t.
You can use C-u 2 M-t for transpose with next second word.
Now coming to your question. If you want to move true, to backward 1 word, use C-u -1 M-t, and for backward 2 words C-u -2 M-t.
Am not a VIM guy. So sorry bout that.
If you want to do this as a refactoring, not just as text manipulation, I'd suggest looking into Xrefactory, a refactoring tool for Emacsen (free for C/Java, commercial for C++).
Transposing previous (Ctrl-t p) and next (Ctrl-t n) argument ... add the
following into your .vimrc file:
map <C-t>p ?,\\|(<CR>wd/,\\|)<CR>?,\\|(<CR>"_dw?,\\|(<CR>a, <C-c>?,<CR>P/,<CR>w
map <C-t>n ?,\\|(<CR>wv/,<CR>d"_dw/\\,\\|)<CR>i, <C-r>"<C-c>?,<CR>?,\\|(<CR>w

Resources