Sublime Text: How to hide the last line number which contains the preserved blank line? - sublimetext

Currently in my configuration, Sublime will always preserve a blank line on the bottom of every file when saving. Since the last line is blank, is there any option to hide the appropriate line number?
NOTE: If there was no option in Sublime, is it possible to write a custom extension or plugin to handle it?
Really appreciate for any help,

The only way to do this is to eliminate the last line by using the following setting:
"ensure_newline_at_eof_on_save": false
Sublime is programmed such that when a line is terminated by a newline character (hex 0A, ASCII character 10), the next line is shown, which intuitively is the correct thing to do. All text editors that I know of have this behavior. Therefore, the only way to "hide" the last line number in the gutter is to not have a newline character terminating the previous line.

Related

Notepad++ convert leading spaces to tabs upon entry

Very close to reverse of this question. I prefer coding with 2-whitespace indentation, but need to have files indented with tabs to align with project convention. What I would like to do is preferably automatically convert 2 spaces upon entry to tab symbol in Notepad++ and have the editor configured to tab length of 2.
A possible manual way for doing this could be Edit->Blank Operations->Space to TAB but this converts all of my spaces to tabs, even those of length 1 - which are, for example, spaces between function arguments, not just leading spaces.
In a perfect case scenario I'm trying to achieve formatting style as described in this question, but with typing just spaces and the editor taking care of the rest.
I'm on Notepad++ 6.0, but willing to upgrade if this helps
Let me complete the answer of Ari Okkonen to add a workaround to the problem commented by Sergii Zaskaleta of mixed tabs and spaces at the beginning of the line.
Settings->Preferences->Tab Settings->Tab size: 2 (if not already)
Edit->Blank Operations->Space to TAB (Leading)
Select a block of lines of text with the problem of mixed spaces and tabs. Press [Tab] and [Shift]+[Tab] to add and remove a tab from each line. In the process, the leading spaces had been converted to tabs.
A manual way that seems to work: After having edited the file before saving you may try (Works in Notepad++ v6.8.3):
Settings->Preferences->Tab Settings->Tab size: 2 (if not already)
Edit->Blank Operations->Space to TAB (Leading)

Blank lines on text box widget

I have an issue with getting the contents of a tkinter text box. If I paste information into it from Excel (for example), it always adds an empty line at the bottom. I would like to remove that line automatically. This is what I use to get the contents:
contents = inputText.get(1.0, "end-1c")
for line in contents.split("\n"):
line = line.strip()
I initially added a '[:-1]' on the end of that, which works, but only on text that is pasted into the text box. If you type text in manually, then obviously there's no trailing '\n' on the end, so it ends up removing the last character that was typed. Not good!
How can I get it to remove (or ignore) the trailing empty lines? The 'line = line.strip()' in the code further down seems to have no effect.
Thanks, Chris.
Your problem isn't with getting the text, your problem is that pasting seems to add more than you expect. To get text, regardless of how it ended up in the widget, you should use .get("1.0", "end-1c"). There is simply no way to know at the time you are getting the contents of the widget if any extra newlines came from the user directly or from a paste operation. To tkinter, text is text no matter how it was entered.
The only solution is to adjust the paste binding, and even that is problematic because I don't think tkinter has any way of knowing if the clipboard contents are from excel, or from some other source.
If all you really want is to ignore all trailing blank lines, call strip() on the data before calling split("\n")
Textbox was always inserts a blank line at the end. The problem was compounded when editing textbox and yet another blank line was inserted. However during edit you could remove blank lines so you can't use "end-1c" all the time.
The trick was to remove 1 or more extra blank lines after editing:
# Rebuild lyrics from textbox
self.work_lyrics_score = \
self.lyrics_score_box.get('1.0', tk.END)
while self.work_lyrics_score.endswith('\n\n'):
# Drop last blank line which textbox automatically inserts.
# User may have manually deleted during edit so don't always assume
self.work_lyrics_score = self.work_lyrics_score[:-1]
Note however this is with Linux. For Windows you might need something like:
while self.work_lyrics_score.endswith('\n\r\n\r'):
# Drop last blank line which textbox automatically inserts.
# User may have manually deleted during edit so don't always assume
self.work_lyrics_score = self.work_lyrics_score[:-2]
Or whatever the the control code is for DOS/Windows LF/CR (Line Feed / Carriage Return) typewriter days style is.

ACE editor displaying a line

While using ACE editor I've observed that a mysterious line is being displayed at the center of the editor. How do i fix this?
That line is called as Print Margin, include
editor.setShowPrintMargin(false);
in your code.
It is not a mysterious line but a print margin - simple line at the specified column, to help seeing when lines become too long.
To disable it we can also use,
editor.setOption("showPrintMargin", false)

Customizing Xcode [fonts, code sense, and more]

How can I make code completion case-sensitive?
How can I make Ctrl-k kill the content of the line and the new line character?
How can I make backspace always delete only one character, no matter what it is? Right now, it deletes spaces in chunks equal to my indent level.
How to change the indentation style in file templates? I like to have the opening brace on its own line.
How can I make the font aliased?
I'm using Xcode 3.2.2.
EDIT: Issues 2, 4, and 5 are solved. 1 and 3 are still open.
EDIT2: ad.3. Yes, I set Xcode to use spaces, not tabs.
3.
Look in Preferences : Key Bindings : Text Key Bindings : Indent Friendly Delete Backwards
If the delete key is mapped to this entry change it to plain Delete Backwards.
2.
In that same preference area, you can see that there is no delete line option to map ^k to.
How can I make code completion case-sensitive?
I don't think that's possible.
How can I make Ctrl-k kill the content of the line and the new line character?
I can't answer that one, you might need to write a script to do it.
How can I make backspace always delete only one character, no matter what it is? Right now, it deletes spaces in chunks equal to my indent level.
Backspace always deletes one character. It sounds like your file has tab characters in it, each one of which takes up the space of 4 spaces by default. You can tell Xcode to use spaces instead by de-selecting Tab key inserts tab, not spaces in the Indentation preference panel.
How to change the indentation style in file templates? I like to have the opening brace on its own line.
You need to create custom file templates. You can find the Xcode templates here:
/Developer/Library/Xcode/Templates/File Templates
You need to copy the appropriate templates to this location:
~/Library/Application Support/Developer/Shared/Xcode/File Templates
You can then edit the template files to use whatever indents you like.
How can I make the font aliased?
You need to use a font that has aliased characters. Try Monaco at 9 or 10 points.

Deleting lines of code in a text editor

Edit: This question had been tagged "Tolstoy" in appreciation of the quality and length of my writing:) Just reading the first and the last paragraph should be enough:) If you tend to select and move code with the mouse, the stuff in middle could be interesting to you.
This question is about how you use text editors in general. I’m looking for the best way to delete a plurality of lines of code (no intent to patent it:) This extends to transposing lines, i.e. deleting and adding them somewhere else. Most importantly, I don’t want to be creating any blank lines that I have to delete separately. Sort of like Visual Studio's SHIFT+DELETE feature, but working for multiple lines at once.
Say you want to delete line 3 from following code (tabs and newlines visualized as well). The naïve way would be to select the text between angle brackets:
if (true) {\n
\t int i = 1;\n
\t <i *= 2;>\n
\t i += 3;\n
}\n
Then hit backspace. This creates a blank line. Hit backspace twice more to delete \t and \n.
You end up with:
if (true) {\n
\t int i = 1;\n
\t i += 3;\n
}\n
When you try to select a whole line, Visual Studio doesn't let you select the trailing newline character. For example, placing the cursor on a line and hitting SHIFT+END will not select the newline at the end. Neither will you select the newline if you use your mouse, i.e. clicking in the middle of a line and dragging the cursor all the way to the right. You only select the trailing newline characters if you make a selection that spans at least two lines. Most editors I use do it this way; Microsoft WordPad and Word are counter-examples (and I frequently get newlines wrong when deleting text there; at least Word has a way to display end-of-line and end-of-paragraph characters explicitly).
When using Visual Studio and other editors in general, here’s the solution that currently works best for me:
Using the mouse, I select the characters that I put between angle brackets:
if (true) {\n
\t int i = 1;<\n
\t i *= 2;>\n
\t i += 3;\n
}\n
Hitting backspace now, you delete the line in one go without having to delete any other characters. This works for several contiguous lines at once. Additionally, it can be used for transposing lines. You could drag the selection between the angle brackets to the point marked with a caret:
if (true) {\n
\t int i = 1;<\n
\t i *= 2;>\n
\t i += 3;^\n
}\n
This leaves you with:
if (true) {\n
\t int i = 1;\n
\t i += 3;<\n
\t i *= 2;>\n
}\n
where lines 3 and 4 have switched place.
There are variations on this theme. When you want to delete line 3, you could also select the following characters:
if (true) {\n
\t int i = 1;\n
<\t i *= 2;\n
>\t i += 3;\n
}\n
In fact, this is what Visual Studio does if you tell it to select a complete line. You do this by clicking in the margin between your code and the column where the red circles go which indicate breakpoints. The mouse pointer is mirrored in that area to distinguish it a little better, but I think it's too narrow and physically too far removed from the code I want to select.
Maybe this method is useful to other people as well, even if it only serves to make them aware of how newlines are handled when selecting/deleting text:) It works nicely for most non-specialized text editors. However, given the vast amount of features and plugins for Visual Studio (which I use most), I'm sure there is better way to use it to delete and move lines of code. Getting the indentation right automatically when moving code between different blocks would be nice (i.e. without hitting "Format Document/Selection"). I'm looking forward to suggestions; no rants on micro-optimization, please:)
Summary of Answers
With respect to Visual Studio: Navigating well with the cursor keys.
The solution that would best suit my style of going over and editing code is the Eclipse way:
You can select several consecutive lines of code, where the first and the last selected line may be selected only partially. Pressing ALT+{up,down} moves the complete lines (not just the selection) up and down, fixing indentation as you go. Hitting CTRL+D deletes the lines completely (not just the selection) without leaving any unwanted blank lines. I would love to see this in Visual Studio!
In Emacs:
kill-line C-k
transpose-lines C-x C-t
C-a C-k C-k -- kill whole line including newline (or kill-whole-line by C-S-backspace).
C-u <number> C-k -- kill <number> of lines (including newlines).
C-y -- yank back the most recently killed text (aka paste)
In VIM:
Delete the whole line including the newline: dd
Transpose lines: dd p
You can always prefix any command with a number to repeat it, so to delete 10 lines do:
10 dd
You can also specify a range of lines to delete. For instance, to delete lines 10-15:
:10,15d
Or you can move the lines, for instance move lines 10-15 below line 20:
:10,15m20
Or you can copy the lines:
:10,15t20
What I do is, starting with the cursor at the start of the line (in some editors you have to press home twice to do this), hold shift and press down until all lines that I want to delete are selected. Then I press delete.
In Eclipse you can ALT-↓ or ALT-↑ to move a line. I find this incredibly useful, as well as ALT-SHIFT-{↓, ↑} to copy a line. In addition, it doesn't wreck your clipboard. It even corrects indentation as the line is moving!
Adding to the existing vim answer, you can use d along with any cursor movement command to delete from the cursor's current position to the new position. For example, to delete...
...to end-of-paragraph (usually meaning "to the next blank line"): d}
...the line containing the cursor and the next 5 lines: d5j
...a set of parentheses, braces, etc. and its contents: d% (with the cursor on the opening or closing paren/brace/etc.)
...to the third appearance of the word "foo": d3/foo
It's quite flexible.
Learn to use your cursor keys.
For moving lines I do the following:
Use ↑/↓to move to the line you want to copy.
Hit Home if not there already, and again if it places the cursor after whitespace.
Then press Shift+↓ to select the line (or lines) you want to move
Ctrl+X to cut the line.
Move Up/Down to the line you want to insert
Ctrl+V
This should work in pretty much any text editor on Windows.
When deleting lines I still tend to use Ctrl+X (although I guess I also use backspace) as the above is so ingrained in how I edit, and it's also more forgiving.
(Although I find them disorienting on the occasions I use Macs, I think Apple might have been on to something with the way they've set up the Home/End, skip word shortcuts on Macs)
Ctrl+Shift+L removes line without copying it to the buffer.
in Eclipse i use CTRL+ D to delete a single line (or a couple)
for many lines i'll select them with the mouse or with SHIFT + ARROW then press the DEL key.
In addition to the above, use Resharper for Visual Studio to do what you want. Best VS plugin you will find ever. It provides a bunch of different commands that help with moving/deleting/copying code here there and everywhere. Not to mention refactor/generate/etc code.
Ctrl-Shift-Alt ↑or ↓ will move a method up or down, line up or down, etc.
Shift-Del - deletes the current line, but puts it in the clipboard (unless you modify your settings to not do this - I'm trying to recall if this is a VS standard shortcut, not just Resharper - been too long).
Ctrl-C, Ctrl-X without selecting copies/cuts the current line.
And on and on...
See http://www.jetbrains.com/resharper/docs/ReSharper40DefaultKeymap2.pdf for a full list.
Using the Brief keyboard mapping this is done using the Alt+L to mark the line and the - key on the numeric keypad (or Alt+D) to cut the line to clipboard. The cut will remove the line entirely, including the newline character.
Hitting the Ins key on the numeric keypad would put the line back into the document including the newline character.
IMHO Brief is a really well designed keyboard mapping.
PS: I think MSVC has an option to emulate the Brief keyboard mapping.
In Emacs, in addition to C-k (and C-k with a numeric prefix arg, to kill N lines), you can just use the mouse:
To kill one line: triple-click it, then right-click twice
To kill multiple lines: triple-click the first line, then right-click on the last line ("first" line can be after the "last" line -- "first" here means first one you click)

Resources