Does clojure allow line continuations? If so, how? - clojure

Many languages allow for line continuations, e.g. in VB with the underscore at the end of a line,
or in Tcl with a backslash at the end of a line.
Does Clojure have a way to allow for line continuations?
Thanks,
chasse

Clojure does not need "line continuations." It is delimited by parentheses. Just don't close your parentheses, and your current statement will continue.

Related

Join Lines in Notepad ++ conditionally based on line start

I have a lot of newlines in multiple Notepad++ files, and I'm hoping to find a RegEx/find/replace function to do the following across many files at the same time:
Join lines (separated by CR|LF) together, unless the line starts with the characters ISA. If the line starts with ISA, it should be its own first line and the rest of the lines after it should join to its line, until the next ISA.
Any help would be greatly appreciated!
Thanks,
Sydney
Replace \r\n(?!ISA) with an empty string (or perhaps a single space).
(?!...) is a negative lookahead and means not followed by ...

Remove Word smart quotes from a text file using vim

I have a large text file, originally generated in Microsoft Word, that contains these four character sequences, alongside regular text:
?~#~\
?~#~]
?~#~X
?~#~Y
From the content of what is written in the file, it appears that the sequences respectively correspond to open double quotes, close double quotes, open single quote, and close single quote. When displayed in Vim, everything in the sequences other than the question mark appears in blue.
I cannot remove them with a command such as
:.,$s/?~#~Y//
This command results in the following error from vim:
E33: No previous substitute regular expression
E476: Invalid command
Press ENTER or type command to continue
These commands also produce errors:
:.,$s/\?~#~Y//
:.,$s/\?\~\#\~Y//
Specifically,
E866: (NFA regexp) Misplaced ?
E476: Invalid command
Press ENTER or type command to continue
What would be the correct way to automatically remove or replace the sequences? Ideally, I'd like to remove the double quotes, and replace the open/close single quotes with a traditional single quote or apostrophe.
Since "everything in the sequences other than the question mark appears in blue", all characters except the question mark are probably binary characters. I'd suggest this approach:
go to the first sequence and yank it: press v to start marking, extend the mark to the end of the sequence, then press y
paste the sequence as the replace pattern from the unnamed register: :%s/Ctrl-r"//gEnter
repeat for the remaining sequences.
If you’re using a unicode-compatible encoding (such as utf-8) and your font supports it, the smart quotes will show properly.
Additionally, the digraphs for them are 6', 6", 9', and 9". This makes it pretty easy to chain a couple of substitutes to swap them for straight variants:
%s/<C-k>6'\|<C-k>9'/'/g
Etc. Wrap it in a function or command to make it easier for later.
Sorry to bump an old thread but I stumbled upon this late at night while trying to figure out how to remove the exact same characters from a bind9 configuration file that I had pasted in from a website. The aberrant characters were "~#~X", "~#~Y", " | ", and I believe another but I can't remember it at the moment. Anyway, regular expressions couldn't seem to find and replace using the above methods, but I was able to find a solution.
If you can set VIM to show the special characters in their binary representation, then you can use regex to find that. Here's how I did it:
Steps to fix
Open the file with the problem characters in VIM
(a) original method - :set encoding=latin1|set isprint=|set display+=uhex
(b) easier method - :set encoding=utf-8
NOTE: either of these should display the digraph characters in their binary form <<<>>>
(e.g. <80>, <99>, ... )
Then search and replace with VIM regex like so
:%s:\%xNN:':g #replace NN with byte code (i.e. 80, 99, etc.)
Let's break that command down, shall we:
%s: - search command looking for all occurrences due to the % at the start and the 's' for search. The ':' (colon) has been used as the delimiter in this case, but you can use other symbols to delimit the search command.
\%x - the backslash escapes the %x which represents a byte code that we're looking for (i.e. <2 x numbers between brackets>)
NN - replace with the two chars inside of the <> that you're looking to replace in your file. In my case, the byte codes were <e2>, <80>, <99>, which I had to search for separately.
:' - then, the colon delimiting the replacement group where I'm specifying a single quote to replace the byte code, you could put whatever text you want here.
:g - finally, the last colon delineation and the letter 'g' which means to search the entire file top to bottom.
You can do more research in VIM's help with:
:help isprint
Anyway, I hope this helps someone else in the future.
References:
https://blog-en.openalfa.com/how-to-edit-non-printing-and-unicode-characters-in-vim-editor
https://unix.stackexchange.com/questions/108020/can-vim-display-ascii-characters-only-and-treat-other-bytes-as-binary-data
VIM How do I search for a <XX> single byte representation

why :%s/^$//g is not equal to :g/^$/d in vim?

I want to delete blank lines in the file in gvim for windows (not vim from cygwin).
:g/^$/d # delete all blank lines correctly
:%s/^$//g #can not delete all blank lines
It's a problem how to express the end of line ,
i have checked my file in detail with the command %!xxd ,
i found there is a 0d0a at the end of every line,
when the end of line is expressed by the special character $ ,
does it contain the 0d0a?
it is different to express concept of the end of line betwwen command g and s ?
:%s/^$\n//g #delete all blank lines correctly
It confused me that ^$ will contain the special character \r\n or not,maybe ^$ in s command do not contai the special character \r\n ,but ^$ in g command do contai the special character \r\n.
which position does special character $ point at ? behind the \r\n or before the \r\n.
No, the two commands are doing different things. :g/^$/d says "find empty lines and delete them", while :s/^$//g means "in this (current) line, replace all occurences of nothing-on-a-line with nothing (still on the same line)". The latter, as you notice, does not make sense.
EDIT for your edit:
The ^$ do not contain anything. It literally says "start of line, then immediately end of line", where "line" is detected by Vim. Vim knows that \r\n or \r or \n (depending on file and on which OS it was created, and on Vim's options) mark the end of line, and treats it accordingly. The separator lies between the ^$.
It's like when you say "the rooms in my house" - this (for me at least) does not include walls. When you say ^$\n, you're saying "the empty room, and also the wooden wall next to it". s/^$// is "empty the (already empty) room"; s/^$\n// is "empty the empty room and break down its wall".
In contrast, for g, again it does not say anything about \n. It finds the empty row (not caring about any separators), and then does a command on it; in your case, the command is d: delete a row. It deletes a full row (along with any newlines). For example, if you write :g/DELETEME/d, it would delete any rows that have DELETEME in it, anywhere: it does not care about any newlines in the match part, it just deletes the matched rows.
d means delete the lines that are matched. s is just a substitution. Essentially the second expression means "substitute lines that match ^$ with an empty string," but that does not delete them. You are substituting nothing with nothing. ^ and $ are zero-width assertions and cannot be replaced.
Both #Amadan and #Explosion Pills are right, but I think you really need an explanation of "how vim thinks" about what you are editing.
For one thing, vim is based on vi, which was a front end to the ex editor. Although vim has come a long way, it is still a line-based editor. Do not look for the magic character at the end of the line, because there is none! (When I say that vim has come a long way, I remember when the 'whichwrap' option was added.)
We usually do not bother to make the distinction, but the file on your hard disk is different from the buffer that you edit in vim (:help buffers). The file is a sequence of characters (or bytes). When vim reads the file, it splits them up into lines depending on the 'fileformat' option (short form 'ff'). Since you work on windows, the default is 'ff'=dos, which means that 0d0a (a.k.a. CRLF or \r\n) in the file is used to separate lines. I have 'ff'=unix, so I see only 0a when I filter through xxd. (Before OS X, Mac used 0d, so there were three standards!)
It is a good thing that the magical EOL character is simply not there, because that makes vim portable between systems. Being a line-based editor, vim lets you do all sorts of things like find the first pattern match on each line and do something to it. That is not always what you want, so some people get in the habit of adding /g at the end of every :s command, or even set 'gdefault'.
Coming back to your original question, removing a line from the buffer is very different from removing all the characters in the line. Ex commands (Remember the lineage) act on lines, and :d is the command to delete one. The :s command will change a line; do not be confused by the common usage :%s, which invokes :s on every line in the buffer (:help :range).

Delete one and two letter lines in VIM?

I have a data source that contains a bunch of city names, but mixed in are quite a few state abbreviations that shouldn't be there..
Is there a way in VIM to delete each line than contains two characters or less?
Here it is:
:g/^\a\{1,2}$/d
Explanation
delete each line that ... → that calls for a :global command (which defaults to % range, the entire buffer); the executed command is :delete.
two characters or less → in a regular expression, any character is matched by ., to restrict this to 1 or 2 the \{n,m} multi is used. This still needs to be anchored via ^ and $ to the beginning and end of the line, so that additional characters don't make this match. Oh, and if you also want to remove completely empty lines, change this to .\{,2}. See :help /\{ for details.
more robust "characters": . will match any character, i.e. also whitespace. To avoid unwanted matches, it's best to restrict this as much as possible. If your state abbreviations are only alphabetic, you can use the \a atom instead of . The available character classes start in the help at :help /\i.

How to read this command to remove all blanks at the end of a line

I happened across this page full of super useful and rather cryptic vim tips at http://rayninfo.co.uk/vimtips.html. I've tried a few of these and I understand what is happening enough to be able to parse it correctly in my head so that I can possibly recreate it later. One I'm having a hard time getting my head wrapped around though are the following two commands to remove all spaces from the end of every line
:%s= *$== : delete end of line blanks
:%s= \+$== : Same thing
I'm interpreting %s as string replacement on every line in the file, but after that I am getting lost in what looks like some gnarly variation of :s and regex. I'm used to seeing and using :s/regex/replacement. But the above is super confusing.
What do those above commands mean in english, step by step?
The regex delimiters don't have to be slashes, they can be other characters as well. This is handy if your search or replacement strings contain slashes. In this case I don't know why they use equal signs instead of slashes, but you can pretend that the equals are slashes:
:%s/ *$//
:%s/ \+$//
Does that make sense? The first one searches for a space followed by zero or more spaces, and the second one searches for one or more spaces. Each one is anchored at the end of the line with $. And then the replacement string is empty, so the spaces are deleted.
I understand your confusion, actually. If you look at :help :s you have to scroll down a few pages before you find this note:
*E146*
Instead of the '/' which surrounds the pattern and replacement string, you
can use any other character, but not an alphanumeric character, '\', '"' or
'|'. This is useful if you want to include a '/' in the search pattern or
replacement string. Example:
:s+/+//+
I do not know vim syntax, but it looks to me like these are sed-style substitution operators. In sed, the / (in s/REGEX/REPLACEMENT/) can be uniformly replaced with any other single character. Here it appears to be =. So if you mentally replace = with /, you'll get
:%s/ *$//
:%s/ \+$//
which should make more sense to you.