Sublime Text line wrap and commit messages - sublimetext3

I use Sublime Text (3) for my default Git commit message editor. I try to follow Git conventions using a hard limit on the number of characters per line (50 for the first line and 72 for the rest). I currently have guides set up at those intervals for visual reference, however rather than manually having to put a line return at the end of 72 characters, I would love to have ST automatically insert a line return for me. Essentially, I want to be able to write without line returns, but have actual returns put in for wrapping instead of just visually wrapping in the editor. Is there a reasonable way to do this?

There is a useful plugin for this (that I somehow missed in prior searches) called AutoWrap. AutoWrap does exactly what I wanted and automatically wraps the line after a certain number of characters with a line return, and the settings for activating it and the number of characters can be set by syntax type. Here is my associated Git Commit Message.sublime-settings file (from Packages/User):
{
"rulers": [50, 70],
"spell_check": true,
"auto_wrap": true,
"auto_wrap_width": 70
}
The auto_wrap and auto_wrap_width lines work perfectly with the plugin and I can keep or remove the rulers as need be.

Related

Using vimscript, how to know if a line's no has changed?

Question
When buffer contents have changed how do I know if a line, having say a line no of 100, has shifted to line no 104?
Note: Content of the line may change so can't track the line using search patterns.
Hacky Solution
I was thinking using the TextChanged* events along with the current cursor position and change in the total number of lines will help. But this seems like it could lead to an incorrect answer.
Context
I'm trying to create a plugin as a wrapper around vim's tags functionality.
The issue is: if a tag was inserted at line 100 and 4 lines were added above it, the tag points to an incorrect location, i.e. line 100, whereas it should be 104.
How do I calculate this difference of 4?
Solutions that apply to both vim and neovim would be appreciated.

Any way to add additional space after line number in Vim?

I am looking for a way to move text further from the line number in Vim. Default settings are to add one space after the line number when using set number. I would like to add a bit more. Using set numberwidth=n doesn't help, because additional space goes before the line number, not in between the line number and the text itself.
No native Vim option seems to alter this, but there is an old plugin which could accomplish what you want to achieve called vimroom. It is not actively being maintained and I don't know if it still works with current Vim versions. But this screenshot makes it look like it is possible to have the line numbers way on the left.
Hopefully this pointer helps you out!

How to call a function when text is wrapped in vim?

In vim I want to visually make transparent the space I have to write a text in markdown. I use hard wrapping with textwidth=79. I know by some calculation that I'll have 20 lines for a chapter for example. So, what I do is inserting 20 empty lines to get a visual feeling for what I can write. After writing some lines, I manually delete the number of lines already written from the empty lines, so that the visual impression still is correct.
What I want to do, is to automate this deletion process. That means I want vim to automatically remove one line below the last written line if this line is empty and after vim automatically started a new line because I reached 79 characters in the line before. How can I do this?
I know that there are autocommands in vim but I haven't found an <event> that fits to the action: after vim automatically hard wraps a line / reached new line in insert (or however you would like to describe it)
I don't think there's an event for that particular action but there's a buffer-local option called formatexpr that gq & co will use, if set. So you can write a function that inspects any placeholder whitespace, if existing. That function can call the text format command gqq to maintain original feel (+ the cursor movement to the new, empty line).

Easier line referencing

I was wondering if anyone knows of a plugin to enable easier line determination.
I have issues quickly scanning to see what line I was to reference in commands such as t and m
See this screenshot:
If I wanted to quickly reference line 5 (I do have line numbers switched on, I just accidentally cut it out in this screenshot) I find I have to look rather hard to find the correct line number.
so: Is there a plugin which makes referencing lines less eye-straining?
I guess your problem is with those deeper indented lines. sometime it is not easy to "connect" the line number and the line text. If this is the case, you may try followings:
set listchars=tab:>-
(see :h 'listchars' for detail) this line will show the <tab> with certain chars. for example, following screenshot is a formatted maven pom.xml, with relative deeper indent lines. I think it would be ok to read the line numbers of them. E.g. the line 1180-1184.
I hope it helps.
with plugin
If the above doesn't help, e.g. you have spaces not <tab>, you could try a plugin: indentLine, with this you could set a variable g:indentLine_char with the char you like. e.g. > to show indent level clearly.
The link of the plugin: https://github.com/Yggdroot/indentLine
:move and :copy are not limited to line numbers (absolute or relative) only, either as source or as target.
You can use search patterns too:
:m?foo
would move the current line just under the first line matching foo going upward,
:t/bar
would copy the current line just under the first line matching bar going downward,
:?foo?t/bar
would copy the first line matching foo above the current line to just below the first line matching bar going downward, and so on.
You can also use marks:
:'at'b
would copy the line marked a to below the line marked b,
:m''
would move the current line to just below the line you were before the last jump, and so on.

How to know in VI which line the cursor is on?

I want to copy paste some lines in vi.
I have a text like
python class1 def:
code code code
...
code code code
last line class1
python class2 def:
code code code
...
code code code
I want to copy the whole class1. I was trying to do it with yNy, so I needed to get N, that is, to count the number of lines the class has.
Then I thought it would be good to get the line number of python class1 def: (let's say X) and the last line class1 (Y), calculate N=Y-X, go to the first line of the class and do the yNy. However, I could not figure out how I can get the line numbers.
So, is there any way to know which line I am in? And in general, is there any other way to copy paste a whole block like the one I indicated?
This is my vi version:
VIM - Vi IMproved 7.3 (2010 Aug 15, compiled Oct 26 2012 16:44:45)
Included patches: 1-547
The current line number can be obtained by :.=. Ctrl-g gives more details including filename, column information, ...
In order to copy a block, go to the start of the line to be copied 0. Hitting v would start the visual mode. Navigate to the last line to be copied. Yank y. (Visual selection is now in buffer.)
Using only normal mode commands:
You can do y} to yank everything from the current line to and including the next empty line, delimiting what Vim considers to be a "paragraph". This may or may not work depending on your coding style.
Still using the notion of "paragraph", you can do yip or yap from anywhere in a "paragraph".
You can set the number option which allows you to see absolute line numbers and therefore be able to do y10G, "yank everything from here to line 10".
You can set the relativenumber option which allows you to see relative line numbers and therefore be able to do y5j, "yank everything from here to 5 lines below".
You can do V/foo<CR>y to yank everything from here to foo linewise.
More generally, you can simply use visual mode to select what you want and yank it.
You can also set a mark on the first line of the class with ma, move the cursor to its last line and do y'a (which sounds like the name of a Lovecraftian deity).
Using Ex commands:
Because the aforementioned number option shows absolute line numbers, you can see that the class ends at line 10 and do :.,10y.
Because the aforementioned relativenumber option shows relative line numbers, you can see that the class ends 5 line below and do :,+5y (dropping the implied .).
Using your statusline (or not):
You can :set ruler to have the current line number displayed on the right side of your statusbar if you have one or on the right side of your command line if you don't have a statusline.
Using Vimscript:
You can use line('.') to retrieve the number of the current line.
Using custom text-objects:
There are a number of custom text-objects available on vim.org for indented blocks, function arguments and many other things. Maybe there is one for Python classes.
More generally, I'd advise you to set either ruler, number or relativenumber permanently in your ~/.vimrc and get used to it.
ruler is the least invasive of the bunch but it's also the most limited: you know where you are but it doesn't help at all when you want to define a target.
number is the most classical and can be used to easily target a specific line.
relativenumber is a bit weird at first and, like number, can be used easily to target a specific line.
Choosing number or relativenumber is, as far as I'm concerned, a matter of taste. I find relativenumber very intuitive, YMMV.
Try the following in command mode
:.= returns line number of current line at bottom of screen
yNy or Nyy copies the next N lines, including the current line
p pastes the copied text after the current line
Additionally,
:set nu! in command mode will turn on/off the line number at the beginning of each line.
let the vim registers do this task. why bother calculating lines
for example if you want to copy line X to line y
1) move your cursor to 1st character of line X.
2) type "ma" . this will save current cursor position in register "a".
3) move cursor to last char of line Y.
4) type "y`a". copy is done
5) p pastes the copied text
This method can work not only lines but block ,words even on characters.

Resources