insert hyphens between each space on sublime text - sublimetext3

I have a text like this:
this is any text
Could sublime text convert it to?
this-is-any-text
insert hyphens between each space

In addition to the suggestions given in the comments, there is another option - the Case Conversion plugin. Edit → Convert Case contains Title Case, Upper Case, Lower Case, and Swap Case. Case Conversion provides:
snake_case
SCREAMING_SNAKE_CASE
camelCase
PascalCase
dot.case
dash-case
separate words
separate with forward slashes
separate with backslashes
To use it, simply highlight the section of text you want to convert and select the desired operation from the menu, or use the assigned keyboard shortcut, which will show up on the menu. You can combine this with Find by using a regex pattern to only select certain areas.
Note: While I have contributed to the Case Conversion repo (I added the backslash feature), I am not its author, just a very satisfied user.

I have done as indicated by #odatnurd in sublime text I have selected the first space, then the following with CTRL + D and finally when they have all been selected I put a hyphen - and they have all been converted to a hyphen

Related

Replace a word (or many words) with spaces of same length?

In a general sense, my question is how do I do something like "dw" or "dd", but instead of deleting characters, I want to over-write with spaces?
E.g. lets say I have text:
first second third
if the cursor is on the "s" in second, I can hit "dw" to get:
first third
but what if I want:
first third
Is there a simple way to do that? An ideal solution would be to use the "d" style syntax (e.g. dw, daw, d$, etc.) but with whitespace replacement instead of deletion.
From the start of the word,
Ctrl-v to enter visual block mode,
e to move to the end of the word (highlighting the word in the process),
r[SPACE] to replace the highlighted characters with spaces.
Because of their very nature (the next character must be consumed), r and R can't work like operators. If you want to replace a motion, visually select it first, and then do r<Space> or r_ or whatever.
In this very specific case:
ver<Space>
or:
viwr<Space>
NOTE: I used ve and viw because the semantics of w are inconsistent so I prefer to avoid it when possible.

In Sublime Text 3: is there a shortcut to remove blank lines in a selected text? (same for blanks in a line)

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.

How to highlight multiple words in vim

I am checking a log file using vim. There's only one word can be highlighted, when I search another word,the second word is highlighted but the previous one is not highlighted anymore.
Can anyone show me a way that easily highlight/cancel highlight multiple words in vim? For example, I want to highlight words "stack", "over" and "flow", then I want to cancel the highlight of "stack" and highlight another word "error". So that I can analyze the log more efficiently.
Thanks.
There are two simple ways to highlight multiple words in vim editor.
Go to search mode i.e. type '/' and then type \v followed by the words you want to search separated by '|' (pipe).
Ex: /\vword1|word2|word3
Go to search mode and type the words you want to search separated by '\|'.
Ex: /word1\|word2\|word3
Basically the first way puts you in the regular expression mode so that you do not need to put any extra back slashes before every pipe or other delimiters used for searching.
/\v\/folder|\/copy - search for \folder and \copy
and add to .vimrc set hlsearch
To have all words highlighted in the same color and be able to search and replace all of then, add them as alternatives to the search pattern, e.g. /foo\|bar. My SearchAlternatives plugin provides handy mappings to add and remove patterns.
If you want different colors for different matches, you need a highlight mechanism different from the built-in search. My Mark plugin is used by many people for that. (The plugin page has links to alternative plugins.)

Searching for general number in a word editor

In a Notepad++ or an editor with similar features, is there an easy to search for a word which contains a number? For instance, suppose numbers were denoted by "~", then if I searched for "abc~" in the following text:
abc4
abc not a number
I would simply get the first word.
Use the "regular expression" search mode. If you just want to find groups of numbers, use \d+. If you want it to select the whole word containing one or more digits, use \w*\d+\w*.
Type this regular expression in the Find dialog box (select the regex option):
\w*\d\w*

Replace colon with tab to make columns

I have word lists where the word or expression in Spanish is separated by its translation with a colon (":"). I want to make two columns, one for Spanish, the other for English. In vim I tried with
:%s/:/^I^I^I/g
But it does not give the desired output. The different columns are not aligned.
When deleting the colon by hand and inserting the number of tabs with the same amount of tab strokes, it always ends up aligned.
Any idea how to solve this, preferably in vim?
On a Linux/*nix system I use column(1)
:%!column -s':' -t
followed by
:%retab!
I'd probable do a
:s/:/^I/g
followed by a
:set ts=25
Where 25 is the length of the longest word expected + 2. So, if you expect the longest word of your input (on the left side of the colon) to be 12 characters, I'd choose something around 14 instead.
With Tabular.vim it's quite easy, just type :Tab /:\zs and it does the rest.
When in insert mode a setting of yours makes tab to reach a nth column. This is set with the 'softtabstop' settings if I am right.
For those tasks you could use a plugin like Align.vim or Tabularize.
Another option is to insert a huge number of spaces, and then use Visual Block with < operator as many times as necessary, if you have to do it once. Otherwise prefer reusable methods.

Resources