I have list of strings which all have leading whitespace
How do I remove it
so I found a way to do this by using a sublime package Trimmer
trimmer screenshot
Related
I have a string:
result = " is programming that manages the execution of programs written in any of several supported languages."
I want to remove white space at the beginning of a sentence.
How I can do it?
You can do this by using Trim(String) in VBA (for trimming left and right spaces) or use LTrim(String) for only trimming leading spaces.
You can use Trim(result) it will remove all white spaces at the beginning and at the end of a string
My question is very simple:
Is there a shortcut in Sublime Text 3 which allows to remove blank lines in a selected text? (same for blanks in a line)
For instance, how to make this text:
a
b
c
To become:
a
b
c
And this line:
I need to remove these blanks.
to become this line:
Ineedtoremovetheseblanks.
You don't need a plugin to do this, a simple regex search and replace will do. First, select the text where you'd like to delete the blank lines. Then, select Find → Replace… (or, hit CtrlH on Windows/Linux, ⌘⌥F on OS X). Make sure the "Regular Expression" and "In selection" buttons are selected:
In Find What:, enter ^\n, and make sure the Replace With: field is empty. Then, simply hit "Replace All" and this:
becomes this:
As a bit of explanation, the regular expression ^\n searches for the beginning of a line (^) immediately followed by a newline character (\n). If you suspect that some of your "blank" lines contain whitespace, like space or tab characters, you can use ^\s*\n instead - \s* matches 0 or more whitespace characters, including newline characters.
For your second example, use the same Find/Replace settings as above, except your regular expression should simply be \s*.
There is a package called Trimmer. You can install it via Package control.
After you got the package you can use its functionalities. Just highlight the text you want to change (or don't select anything if you want to change the entire file) and then choose:
1) Edit > Line > Delete Empty Lines
2) Edit > Line > Remove Blank Spaces
Alternatively, as Chris's answer already pointed out you can use the classic search & replace functionality that is already present in the editor.
AS my original answer was incorrect, I have found this package which will be suitable for your needs.
The package is called DeleteBlankLines, for Sublime Text 3, has the ability to delete blank lines for the entire document and within the selected text only, all from a key stroke just like you were after.
The package can be found here:
https://packagecontrol.io/packages/DeleteBlankLines
I prefer using \s+, which will get one or more (i.e., the + character) whitespace characters (i.e., the \s escape sequence).
The * character will do zero or more, which on some versions can break up the individual words into letters.
There are 5 white blanks in line 3,6 white blanks in line 4,7 white blanks in line 5.
I want to replace them with 4 white blanks,how to write the command?
It is not %3,7s/^\s*/ /g ,how to fix it?
it is a test
it is a test
it is a test
I want change it into:
it is a test
it is a test
it is a test
Based on your example, it sounds like you want to replace all sequences of whitespace at the beginning of lines with 4 spaces.
Please comment if I have misinterpreted your question. You can do this by looking for an arbitrary amount of whitespace at the beginning of line and replacing with four spaces.
%s/^\s\+/ /g
You typed :%3,7s/^\s*/ /g, but % is a range and 3,7 is another range, so it's wrong : you have to choose between them:
:%s ...
will replace in the whole file, or
:3,7s ...
will only replace in lines from 3 to 7.
I have a file that is pipe-delimited and semi-fixed width. What I mean by that, is that the values can look like this:
one|two two|three three | four four| | six six |seven seven
eight eight| nine nine |
My goal is to remove all beginning whitespace, trailing whitespace, and and sections where there is whitespace in an empty delimiter (such as you see between four and six above). Once complete, I intend to work with the file in Excel.
I know that I could tackle the whitespace by importing the entire file into Excel and performing a TRIM() command, but that is very time-consuming with very 'wide' documents.
My current solution is to tackle this with Notepad++ with a series of find and replace commands:
Trim trailing whitespace:
Find what: (\S+)\s+[|]
Replace with: \1|
Trim beginning whitespace:
Find what: ([|])\s+([A-Za-z])
Replace with: \1\2
Trim whitespace from within empty columns:
Find what: [|]\s+[|]
Replace with: ||
...and then import to Excel.
Is there a simpler, single find and replace command I could be using, or should I just put these together in a macro?
How about:
Find what: \s*\|\s*
Replace with: |
Edit:
Change \s into \h to avoid matching linebreak. \h stands for horizontal white space :
Find what: \h*\|\h*
Replace with: |
This may sound like a stupid answer but this is how I'd go about doing this.
Open replace and put "| " and in the replace put "|", hit replace until you get 0 changes.
Then do the same with " |" and in replace "|"
Finally do it with " " (two spaces) and " " (one space).
My apologies if this isn't what you want. I can't do comments yet.
I have a field with hex a decimal values that look like FF FE, I need to remove the white space so the results are FFFE but trim is not working for me! Is there another function I can use?
Trim only removes whitespace at the beginning and end. Use substitute instead.
=SUBSTITUTE({cell ref}," ","")
should do the trick