Option to copy lines with carets NOT separated with empty lines - sublimetext2

Sublime text 2 (Windows 7) has such feature: several lines with carets (no selections made,only carets) are copied to Clipboard separated with empty lines. Can i disable these empty line separators, to copy w/o them?
detail:
open few lines text file
place 3-4 carets using Ctrl+Click on few lines
press Ctrl+C to copy to clibboard
paste into new file-- u see empty line separators for copied text

Think you need a plugin to do it. I didn't test this, but it should work. It's pretty straight forward.
import sublime
import sublime_plugin
class EmptyLineCopyCommand(sublime_plugin.TextCommand):
def run(self, edit):
view = self.view
lines = []
for cursor in view.sel():
lines.append(view.substr(view.line(cursor)))
sublime.set_clipboard("\n".join(lines))
Put the following in your user key bindings.
{"keys": ["ctrl+c"], "command": "empty_line_copy", "context": [
{ "key": "selection_empty", "operator": "equal", "operand": true, "match_all": true }
]},

Related

Visual Studio Community 2017 spaces in launch.json args field

I'm currently trying to set the debugging startup arguments for a CMake based project in Visual Studio Community 2017. Normally this would be done via the launch.vs.json file. However, the arguments that I need to pass contain spaces in them. For example, the below launch.vs.json file should pass the arguemnts FIRST ARGUMENT and SECOND ARGUMENT as the first and second argument. However, the program ends up getting 4 arguments: FIRST, ARGUMENT, SECOND, and ARGUMENT. I've tried various different encodings for spaces, but cannot get a space to be encoded properly in the resulting arguments. This is especially problematic as one of the arguments to my program is a path inside C:\Program Files. As such, the path is broken into 2 separate arguments, rather than one as it should be. How do I make Visual Studio allow spaces within an argument?
For reference, launching via the command line with this command works as expected:
argtest.exe "FIRST ARGUMENT" "SECOND ARGUMENT"
launch.vs.json
{
"version": "0.2.1",
"defaults": {},
"configurations": [
{
"type": "default",
"project": "CMakeLists.txt",
"projectTarget": "argtest.exe",
"name": "argtest.exe",
"args": ["FIRST ARGUMENT", "SECOND ARGUMENT"]
}
]
}
test.c
#include <stdio.h>
int main(int argc, char ** argv) {
int i;
for (i = 0; i < argc; i++)
printf("%d = %s\n", i, argv[i]);
return 0;
}
CMakeLists.txt
cmake_minimum_required (VERSION 2.8.8)
project (argtest)
SET( CMAKE_RUNTIME_OUTPUT_DIRECTORY ${CMAKE_SOURCE_DIR}/ )
add_executable(argtest test.c)
You need to include the quotes in the args strings and escape them. For example:
{
"version": "0.2.1",
"defaults": {},
"configurations": [
{
"type": "default",
"project": "CMakeLists.txt",
"projectTarget": "argtest.exe",
"name": "argtest.exe",
"args": ["\"FIRST ARGUMENT\"", "\"SECOND ARGUMENT\""]
}
]
}
It is easier doing this through Visual Studio itself. To run a program with command-line arguments follow these steps:
Open the project in Visual Studio
Click on the 'Debug' tab in the menu bar.
Click on the '[NAME OF PROJECT] Properties' menu item.
A window will popup and should automatically go into the Debug menu within that window. Under the 'Start options' section enter your command-line arguments with a space between each argument.
Hope this helps.

Error trying to parse settings: Expected value in ~/Library/Application Support/Sublime Text 2/Packages/User/Preferences.sublime-settings:1:1

I know there are at least 2 other questions like this on SO but none of those answers are working for me.
I'm trying to customize my user settings on Sublime Text 2 (mac) but when I go to save it I get the error listed below.
Here are my settings.
{
"caret_style": "phase",
"color_scheme": "Packages/Color Scheme - Default/Solarized (Light).tmTheme",
"default_encoding": "UTF-8 with BOM",
"font_size": 15,
"highlight_line": true,
"highlight_modified_tabs": true,
"ignored_packages": [
"Vintage"
],
"line_padding_bottom": 4,
"line_padding_top": 0,
"wide_caret": true
}
Here's the error:
Error trying to parse settings: Expected value in ~/Library/Application Support/Sublime Text 2/Packages/User/Preferences.sublime-settings:1:1
The answers listed on Sublime Text 2: Error trying to parse settings and on Error trying to parse settings do not help at all.

How can I jump to line in Sublime Text?

Does anyone know of a shortcut for jumping to a specific line (given a #) in Sublime Text?
Ex: I run code and get an error at line 5765. I want to be able to jump quickly in Sublime Text to line 5765, without scrolling.
Windows: Ctrl + G
Mac: Control + G
Linux:Ctrl + G
or
Windows: Ctrl + P + :
Mac: Command + P + :
Linux: Ctrl + P + :
Then type the line number. It will automatically find it for you and if it requires scrolling to get to - it will snap your view to the line number level.
Rather than Control+G, if you're used to using CMD+P or CMD+T, you can just type :
Also useful:
CMD+R go to function in current file
CMD+Shift+R find function in any file (CMD+, "binary_file_patterns" ignore node_modules)
CMD+Option+Down jump to function definition in another file (from cursor word)
CMD+D / CMD+U jump & accumulate next word occurrence & populate search query / (undo). from cursor becomes an exact match (case and word boundary) vs from selection is a partial match (ignore case and word boundary). D and U also work in less bash / zshell pager to scroll down / up half pages
CMD+G / CMD+Shift+G jump or "go" to next / previous search query (CMD+D amazing with this)
CMD+{ / CMD+} focuses left / right tab (same in terminals, browser, kapeli dash, etc.)
CMD+[ / CMD+] shift line left / right (chrome forward / backward nav, devtools changes panel)
CMD+Control+Up / CMD+Control+Down shift line up / down
CMD+K->(some number) fold to indentation
CMD+K->J unfold all
CMD+Option+[ / CMD+Option+] fold / unfold current line's children
CMD+, is preferences in most all Mac applications
As pointed out by #maxTuzz, I use Ubuntu 16.06 and Sublime regularly,
this Ctrl+P then Pressing : and Starting typing the Line Number you want to Navigate.
Or
Directly we can type Ctrl+G Starting typing the Line Number you want to Navigate.
In My Mac, Performance>>Key Bindings add:
//line duplicate & delete
{ "keys": ["super+y"], "command": "run_macro_file", "args": {"file": "res://Packages/Default/Delete Line.sublime-macro"} },
{ "keys": ["super+d"], "command": "duplicate_line" },
//replace
{ "keys": ["super+r"], "command": "show_panel", "args": {"panel": "replace", "reverse": false} },
//goto
{ "keys": ["super+l"], "command": "show_overlay", "args": {"overlay": "goto", "text": ":"} },
{ "keys": ["super+g"], "command": "show_overlay", "args": {"overlay": "goto", "text": "#"} },
//upper or lower
{ "keys": ["super+shift+u"], "command": "swap_case" },
//sidebar toggle
{ "keys": ["super+shift+t"], "command": "toggle_side_bar" },
base is to press Ctrl + P and a then type : and then write the line that you want to go , BUT there is a shortcut for this :
Just hit Ctrl + G , and it does the same steps for you!
on your keyboard click the:
command + p
then type : on your keyboard follow by the line number, example 374
:374
then click the enter key on your keyboard to jump to the desired line number

Error trying to parse settings

Here is the exact error I get as I open the program:
Error trying to parse settings: Expected value in ~/Library/Application Support/Sublime Text 2/Packages/Default/Preferences.sublime-settings:1:13677
You can remove the comments and use a service like http://zaach.github.io/jsonlint/ to validate the JSON.
Packages/Default/Preferences.sublime-settings. Check that file instead (Sublime Text 2 -> Preferences -> Settings - Default
{
"bold_folder_labels": true,
"caret_style": "phase",
"fade_fold_buttons": false,
"font_face": "Consolas",
"font_size": 12,
"highlight_line": true,
"ignored_packages":
[
"Vintage"
],
"line_padding_bottom": 1,
"line_padding_top": 1
}

Scripting find & replace operations in Sublime Text

Often I find myself doing repetitive file & replace operations in a file. Most often that comes down to fixed find and replace operations; deleting some lines, changing some strings that are always the same and so on.
In Vim that is a no-brainer,
function! Modify_Strength_Files()
execute':%s/?/-/'
execute':%s/Ä/-/'
"--------------------------------------------------------
execute':%s/Ä/-/'
execute':%s///g'
"--------------------------------------------------------
execute':g/Version\ of\ Light\ Ship/d'
execute':g/Version\ of\ Data\ for\ Specific\ Regulations/d'
"--------------------------------------------------------
" execute':g/LOADING\ CONDITION/d'
" execute':g/REGULATION:\ A\.562\ IMO\ Resolution/d'
" This is to reduce multiple blank lines into one.
execute ':%s/\s\+$//e'
execute ':%s/\n\{3,}/\r\r/e'
" ---------------------
endfunction
copied verbatim.
How could a function like this be defined in Sublime Text editor, if it can be done at all, and then called to act upon the currently opened file?
Here are resources to write Sublime Text 2 plugins:
Sublime Text 2 API Reference
Sublime Text 2 Plugin Examples
How to run Sublime Text 2 commands
Setting up Sublime Text 2 Custom Keyboard Shortcuts
Example: you can write a similar plugin and bind a hot key to it, that is, batch_edit command. Then you can open a file and execute the command via that hot key. By the way, in this script, I didn't consider the file encoding. You can get the file encoding via self.view.encoding().
# -*- coding: utf-8 -*-
import sublime, sublime_plugin
import re
class BatchEditCommand(sublime_plugin.TextCommand):
def run(self, edit):
self._edit = edit
self._replace_all(r"\?", "-")
self._replace_all(u"Ä", "-")
self._delete_line_with(r"Version of Light Ship")
self._delete_line_with(r"Version of Data for Specific Regulations")
self._replace_all(r"(\n\s*\n)+", "\n\n")
def _get_file_content(self):
return self.view.substr(sublime.Region(0, self.view.size()))
def _update_file(self, doc):
self.view.replace(self._edit, sublime.Region(0, self.view.size()), doc)
def _replace_all(self, regex, replacement):
doc = self._get_file_content()
p = re.compile(regex, re.UNICODE)
doc = re.sub(p, replacement, doc)
self._update_file(doc)
def _delete_line_with(self, regex):
doc = self._get_file_content()
lines = doc.splitlines()
result = []
for line in lines:
if re.search(regex, line, re.UNICODE):
continue
result.append(line)
line_ending = {
"Windows" : "\r\n",
"Unix" : "\n",
"CR" : "\r"
}[self.view.line_endings()]
doc = line_ending.join(result)
self._update_file(doc)