I have a CSV file that contains about 100'000 records some of which have been broken into multiple lines at a "\" character in the source data during the export. Can any one help me with an expression to remove any line breaks that follow the "\" character in the data.
In the "Replace" dialog, select "Extended" from the "Search Mode" section (bottom left of the dialog).
In the "Find what" box type: \\\n
In the "Replace with" box type: \\
Hit "Replace All"
Enjoy
Good afternoon.
Did you try clicking on the "Edit" menu and "Convert line breaks" from the application "Notepad ++"?
Related
How do I change # to | as a comment sign in Notepad++?
In which language syntax comments are |?
I don't know what language have | as comments sign.
You have to define your own language rules. You can choose the comments sign in the file langs.model.xml (in the Notepad++ installation directory), see the attribut commentLine= for each language.
In SynWrite app you can change comment-char for "Text files" lexer: call "Options - Customize lexer" dialog, fill field "Line comment string" with "|".
Now command "Comment lines" adds "|".
I want to insert " to the end of each lines
I have the following text:
Some test\n
Also some text\n
The rest of text\n
And I want to get like this one:
Some test "\n
Also some text "\n
The rest of text "\n
Where \n - end of line
I just did a search for "sublime line padding" and found:
http://wbond.net/sublime_packages/alignment
Hope it helps.
From the website:
Features
Align multiple selections to the same column by inserting spaces (or tabs)
Align all lines in a multi-line selection to the same indent level
Align the first = on each line of a multi-line selection to the same column
See the screenshots below for examples of the plugin in action.
Installation
Download Package Control and use the Package Control: Install Package command from the command palette. Using Package Control ensures Alignment will stay up to date automatically.
I'm trying to figure out the syntax of the mapping commands, like onoremap, in vim.
Specially, I am confused over this line in the manual, regarding the use of <C-U>:
The CTRL-U (<C-U>) is used to remove the range that Vim may insert.
Can someone explain this?
That isn't part of the syntax for the onoremap command, that is explaining what a particular mapping does. That mapping is:
onoremap <silent> F :<C-U>normal! 0f(hviw<CR>
So, when the F key is used while an operator is pending vim will replace that with the bits in the next argument to the onoremap command. That starts with a : to begin an ex mode command. If there is a visual selection when the mapping is used, vim will automatically insert the range '<,'> so that the following ex command will apply to the visual selection, leaving the command line looking like:
:'<,'>
The <C-U> in the mapping tells vim that after the : is entered the Control+U combination should be used to clear the command line, eliminating the automatically inserted range leaving the command line looking like:
:
Then the remainder of the mapping is used.
You can see this for yourself by using V to begin a line-wise visual selection, then : to start entering a command. The range will show up, you can then use Control+U to clear it just as the example mapping does.
The portion of vim help that contains that mapping explains the remainder of it.
The Ctrl-U Vim-map operates as the same short-cut from the terminal command line. Check: https://www.howtogeek.com/howto/ubuntu/keyboard-shortcuts-for-bash-command-shell-for-ubuntu-debian-suse-redhat-linux-etc/
Avoid remapping few of them (like which breaks out a process on a terminal), but the majority (like Ctr-A or Ctrl-X) can be remapped.
If your VIM is no terminal one (like gVim), you can remap them all inconsiderately.
Btw: Ctrl-Shift-Letter is like Ctrl-Letter map for VIM-terminal.
Some terminal short-cuts:
" copy-paste
" <C-S-c> copy
" <C-S-v> paste (or replace visual selected)
" manage running processes
" <C-c> break out of a command or process on a terminal. This will stop a running program immediately.
" <C-z> send a running program in the background
" <C-d> If you are using an SSH connection, it will be closed. If you are using a terminal directly, it will be closed
" control what appears on the screen
" <C-l> clear terminal screen
" <C-s> Stop all output to the screen. This is particularly useful when running commands with a lot of long, verbose output, but you don’t want to stop the command itself with Ctrl+C.
" <C-q> Resume output to the screen after stopping it with Ctrl+S.
" Moving the Cursor
" <C-a> or Home: move cursor to beginning of line
" <C-e> or End: "" end ""
" <C-xx> Move between the beginning of the line and the current position of the cursor. This allows you to press Ctrl+XX to return to the start of the line, change something, and then press Ctrl+XX to go back to your original cursor position. To use this shortcut, hold the Ctrl key and tap the X key twice.
" <A-b> go left 1 word
" <C-b> "" char (like left-arrow)
" <A-f> go right 1 word
" <C-f> "" char (like right-arrow)
" Cutting and Pasting
" <C-u> erases everything from the current cursor position to the beginning of the line
" <C-k> erases everything from the current cursor position to the end of the line
" <C-w> erase the word preceding to the cursor position. If the cursor is on a word itself, it will erase all letters from the cursor position to the beginning of the word.
" <C-y> paste the erased text that you saw with Ctrl + W, Ctrl + U and Ctrl + K shortcuts
" Deleting Text
" <C-d> or Delete: Delete the character under the cursor
" <A-d> Delete all characters after the cursor on the current line.
" <C-h> Backspace: Delete the character before the cursor.
" Fixing Typos
" <A-t> Swap the current word with the previous word.
" <C-t> Swap the last two characters before the cursor with each other. You can use this to quickly fix typos when you type two characters in the wrong order.
" <C-_> Undo your last key press. You can repeat this to undo multiple times.
" Capitalizing Char
" <A-u> Capitalize every character from the cursor to the end of the current word
" <A-l> Uncapitalize every character from the cursor to the end of the current word
" <A-c> Capitalize the character under the cursor. Your cursor will move to the end of the current word.
" Command History
" <C-p> like up-arrow: press it repeatedly to keep on going back in the command history
" <C-n> like down-arrow: use this shortcut in conjugation with Ctrl+P. Ctrl+N displays the next command
" <A-r> revert any changes to a command you’ve pulled from your history if you’ve edited it.
" <C-r> search in your command history. Just press Ctrl+R and start typing. If you want to see more commands for the same string, just keep pressing Ctrl + R.
" <C-o> Run a command you found with Ctrl+R
" <C-g> Leave history searching mode without running a command
I know that Sublime Text 2 can delete the trailing white space on files upon saving.
When working in a team and commiting a change to a file this tends to produce huge diffs which make peer code review more cumbersome. For that reason I prefer to only do the white space cleaning when I'm commiting huge changes to a file anyway and leave whitespace as it is for the minor changes.
I would like to know if there's any command for executing the trimming of the white space on demand on a file, other than "Activate trimming on save > Save file > Deactivate trimming".
Searching in the Documentation and on stackoverflow didn't show anything relevant, all the links seem to talk about the auto trimming on save.
I use these steps for a quick on-demand solution within Sublime Text:
Find > Replace...
Find What: [ \t]+\n
Replace With: \n
Replace All
You could also do this for a large set of files via
Find > Find in Files...
Find: [ \t]+\n
Where:
Replace: \n
Replace
Beware: using this plugin makes Sublime Text significantly slower
I use TrailingSpaces plugin for this.
Highlight trailing spaces and delete them in a flash.
ST2 provides a way to automatically delete trailing spaces upon file
save. Depending on your settings, it may be more handy to just
highlight them and/or delete them by hand. This plugin provides just
that!
Usage: click "Edit / Trailing Spaces / Delete".
To add a key binding, open "Preferences / Key Bindings - User" and add:
{ "keys": ["ctrl+alt+t"], "command": "delete_trailing_spaces" }
You can simply use a regex to remove trailing whitespaces:
Find > Replace...
Find what: [^\S\r\n]+$
Replace with: leave empty.
Click 'Replace All'
[^\S\r\n]+$ is Regex for "at least one whitespace character (so spaces and tabs but not newlines, using a double negation) followed by the end of the line"
Regular Expression must be enabled:
This method isn't perfect, but uses no plugins or settings and works in most situations.
Multi-Select and move cursor to the end of every line
Hold CTRL-Shift, Press Left, Right
The spaces and tabs at the end of the lines should now be selected. Press Delete or Backspace
Note - Special characters such as ( and + may also be selected at the end of the line at this point, not just spaces.
How to Multi-Select all lines:
One way is to use the middle mouse key to select vertically then hit the End Key if it's a small selection.
With hot-keys:
CTRL-A (select all)
CTRL-SHIFT-L (place cursor on all lines selected)
END (Go to end of lines)
You can also use the find function to find something that will be in every line, like the space character:
\s (using regex)
Click Find All
Press the "End" key to get multiple cursors at the end of each line
Sample Text:
text and number 44 more text and a space
text and number 44 more text and 2 tabs
text and number 44 more text and no space or tab
text and number 44 more text after a line feed
I found a soulution here:
http://www.sublimetext.com/forum/viewtopic.php?f=4&t=4958
You can modify the package
trim_trailing_white_space.py
located in the default packages directory, this way:
import sublime, sublime_plugin
def trim_trailing_white_space(view):
trailing_white_space = view.find_all("[\t ]+$")
trailing_white_space.reverse()
edit = view.begin_edit()
for r in trailing_white_space:
view.erase(edit, r)
view.end_edit(edit)
class TrimTrailingWhiteSpaceCommand(sublime_plugin.TextCommand):
def run(self, edit):
trim_trailing_white_space(self.view)
class TrimTrailingWhiteSpace(sublime_plugin.EventListener):
def on_pre_save(self, view):
if view.settings().get("trim_trailing_white_space_on_save") == True:
trim_trailing_white_space(view)
class EnsureNewlineAtEof(sublime_plugin.EventListener):
def on_pre_save(self, view):
if view.settings().get("ensure_newline_at_eof_on_save") == True:
if view.size() > 0 and view.substr(view.size() - 1) != '\n':
edit = view.begin_edit()
view.insert(edit, view.size(), "\n")
view.end_edit(edit)
Now you can add the command to your keymap configuration:
{ "keys": ["your_shortcut"], "command": "trim_trailing_white_space" }
I have the following Warning popping up in a few of the Applescripts I'm running in a Cocoa application:
http://emberapp.com/splash6/images/unknown-escape-sequence-error/sizes/m.png
I have tried everything I can think of to remove the error such as totally rewriting it, copying and pasting from another similar script that doesn't have the warning etc. but I can't get rid of it. Can anyone tell me where I might be going wrong.
The raw code I'm using is:
NSString *theCellRefScript = [NSString stringWithFormat:#"tell application \"Numbers\"\n\
tell document 1 \n\
tell sheet \"%#\" \n\
tell table \"%#\" \n\
set value of cell \"%#\" to \%#\ \n\
end tell \n\
end tell \n\
end tell \n\
end tell ", theSheet, theTable, theCell, [theDistributionValues objectAtIndex:k]];
Don't open yourself up to this sort of problem in the first place.
Objective-C, like all modern C compilers, automatically concatenates string literals if they are seperated by whitespace. Rather than your multi-line horror with its trailing slashes, use:
NSString *theCellRefScript = [NSString stringWithFormat:#"tell application \"Numbers\"\n"
"tell document 1\n"
"tell sheet \"%#\ \n"
"tell table \"%#\ \n"
"set value of cell \"%#\" to \%# \n"
"end tell\n"
"end tell\n"
"end tell\n"
"end tell", theSheet, theTable, theCell, [theDistributionValues objectAtIndex:k]];
You have a trailing space on the end of a line, after the final backslash. It thinks you're trying to escape a space, not join lines.
edit: I'll even tell you how I knew, so you know for next time. From the error text, '040' is an octal number. Convert to decimal, 4 * 8 = 32, and ASCII 32 = space. A space is not a valid escape character. Some editors have a 'show whitespace' mode which'll show you tabs and spaces to help weed out issues like this.
Found the problem, there was a rogue space on the line starting set value of cell. The working version is:
set value of cell \"%#\" to \%#\\n\
This was driving me nuts because I really just couldn't see it. In my case it turned out to be rather simple: In my help text I had written that a certain option would escape all spaces - and I gave an example,
"\ "
Of course this became something like:
"\"\ \""
It's not visually obvious at all... but the backslash in the middle needs to be escaped, too:
"\"\\ \""
HTH