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.
Related
I am writing a swirl lesson using swirlify package functions in RStudio.
Below is how lesson.yaml file looks like now
- Class: text
Output: Welcome to Part 1 Playing with Numbers!!!
Output for which looks like
How to insert a new line or line break after Welcome to Part 1 in lesson.yaml file above, so that it displays the output as below when I run the demo_lesson() command again after saving the lesson.yaml file
| Welcome to Part 1
| Playing with Numbers!!!
Using YAML, you can use any of these equivalent approaches:
Quoted string with escape
- Class: text
Output: "Welcome to Part 1\nPlaying with Numbers!!!"
Literal scalar
- Class: text
Output: |-
Welcome to Part 1
Playing with Numbers!!!
(| starts a literal scalar and - tells YAML to drop the final line break.)
Multiline scalar
- Class: text
Output:
Welcome to Part 1
Playing with Numbers!!!
(since one line break gets folded into a space, you need two line breaks.)
Since I do not know whether swirlify nicely handles line breaks in the string, I guess you could also do
- Class: text
Output: Welcome to Part 1
- Class: text
Output: Playing with Numbers!!!
Thanks to flyx for answering the question, here is how it works!!
I. Quotes string with escape (Works with two \n\n)
lesson.yaml file
II. Literals
First line in Output: |- Hit ENter once
Indent once by pressing one Tab for first line, Hit Enter twice to have break between header line and paragraph like below, then it works..
lesson.yaml file
III. Mulitline Scalar (Works with three times Enter between two lines)
Press Enter once After Output: in lesson.yaml
Indent once by pressingTab` key once, Write your first line, hit Enter thrice and write the second line. Then it works.
lesson.yaml file
OUTPUT FOR ALL THE ABOVE ANSWERS
Is there a quick way to insert a line with the same number of hyphens or = characters as there are in the current line in vi(m)? That is, to go from:
My Heading
to:
My Heading
==========
without going to the end of the line, reading the number of characters in it from CTRL-G, opening a new line underneath, and typing <n>i= ?
I use the following mappings in my own markdown.vim:
" Level 1 Heading
nnoremap <leader>1 :co.<CR>Vr=A<CR><Esc>
inoremap <leader>1 <Esc>:co.<CR>Vr=A<CR>
The first mapping is for when already in Normal mode while the second Insert mode mapping returns to Insert mode with the cursor at the start of the line underneath the heading.
Use the Ex copy command, :co to copy the line without affecting the contents of any of the Vim registers.
Then select all of the copied line with V.
Finally, r= replaces each of those characters with an equal sign.
For the mapping keys, I use the leader key (defaults to \) followed by the numeral 1 to represent a Level 1 heading in Markdown.
I have a file where I have multiple lines. Is there an option in Sublime Text 3 to reverse whole line ? Like
ABCDEFG
to
GFEDCBA
if someone need to do the following operation.
12345
67890
abcde
|
to
|
v
abcde
67890
12345
click Edit---->Permute lines--->Reverse and it will reverse all lines you selected in a file.
You best bet would definitely to take Leonid's advice and use a different tool, but if you are curious as to how one might do that in Sublime you have two options.
First go to Tools->New Plugin and paste the following code into the file:
import sublime, sublime_plugin
class ReverseCharactersCommand(sublime_plugin.TextCommand):
def run(self, edit):
for region in self.view.sel():
stringContents = self.view.substr(region)
self.view.replace(edit, region, stringContents[::-1])
Following that select the different sections of the document that you want reversed and run the follow command from the console
view.run_command("reverse_characters")
Here is an image of that workflow.
The import section of that code is the:
stringContents[::-1]
Which is an idiomatic way of reversing a string in Python.
Alternatively you could go checkout this follow git repository and which has the same code and a convenient command palette options specified for you :)
https://github.com/MattSeen/ST_ReverseCharacters
In vanilla sublime:
Select the text to reverse
Open the Find menu (Ctrl+F)
Ensure "In selection" and "Regular expression" options are enabled
Search for . and click "Find all" (⌥+Enter)
Now each character of the selection is highlighted with its own cursor.
Click Edit > Permute selections > Reverse
It's not elegant but it is straightforward and repeatable. If you already have the cursors, all you need is step 4.
Not inside Sublime Text, but in Linux/OSX the rev command-line utility does just that - rev file.txt reverses every line of the file.
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'll show you what I want to do using a textmate command or bundle:
Lets say we have the following document:
foo
diddy
bah
foo
foobah
diddy
I want to find and delete all the lines matching bah, the desired ouput in this case would be:
foo
diddy
foo
diddy
Thanks!
With the document you want to filter open,
Cmd-F to bring up the Finder
window
Next, below the two text-entry boxes,
click Regular Expression
In the Find text box, type in
this regexp (without the spaces):
^ . * ? bah . * ? $
In the Replace text box, do not type
in anything--make sure it blank,
i.e., no whitespace characters
With the cursor at the beginning of
the document you want to filter,
click one of the buttons at the
bottom of the Find Window--e.g.,
Replace All to remove all of the matching lines in one step, or
Replace and Find to step through the lines one at a time
That's it.
Here's a more automated way to do the same thing:
from the Menu Bar, select Filter
Through Command from the Text
pull-down menu
enter this into the text box at the
top of the small window that appears:
sed ' / ^ . * bah . * $ / d '
select Document as Input and select
Replace Document as Output
Click Execute
[Note: i inserted spaces between the regexp tokens in both examples because for some reason the asterisks '' were not rendering in HTML page]
Building on top of #doug's answer
Since the user wants to delete the line after the match, the solution using Regex is
^ . * ? bah . * ? $\n
Matching the \n at the end will remove the line