Negative numeric argument in Vim [duplicate] - vim

This question already has answers here:
Delete n lines in the up direction in vim
(5 answers)
Closed 9 years ago.
Is there a way to apply a vim command backward? For example, I want to kill 5 lines backward, instead of 5dd, is there something like -5dd?

From :he d:
["x]d{motion} Delete text that {motion} moves over [into
register
x]. See below for exceptions.
How about 5dk 4dk (k being the motion for upwards)?
Edit: changed count to 4 as this results in 5 lines being deleted apparently...

Related

Vim: delete from the cursor until the end of the bracket (or a character) [duplicate]

This question already has answers here:
VIM: Deleting from current position until a space
(6 answers)
Closed 4 years ago.
I would like delete everything from the cursor until the end of the bracket
For example: (the cursor is after "is")
[this is my text] -> [this is]
How can I do?
I would something like di]..., but don't delete the text before the cursor
To delete text from the cursor until a certain character ] in normal mode, use dt] or df]. The difference between t and f is that f will also delete ].
Assuming your curser is after is in [this is my text], typing
dt]
in normal mode will give you [this is] as result.
If you want to delete the bracket ] too, type
df]
instead to get [this is.

Adjusting all line to Left side of the file in gvim [duplicate]

This question already has answers here:
Remove all arbitary spaces before a line in Vim
(9 answers)
Closed 5 years ago.
I'm new to the vim editor.
How can I adjust all lines to the left? I have many lines which are indented and I want to arrange them so they all abut the left side of the file (no spacing at the start of the lines).
Select all line in visual mode and then type :left . Hope this helped.
keerthan
The simple key sequence :%left will do the trick, it basically applies the left command to all lines in the file.

Get how many times a given pattern are matched in vim [duplicate]

This question already has answers here:
Show Count of Matches in Vim
(11 answers)
Closed 8 years ago.
I an use /pattern to match patterns in the current file, is there a way to show many many matches there are after I hit enter for previous search command? Then I will have a sense that how many navigation to do to go through all of them.
You can define a simple mapping that prints the number of matches:
:nnoremap <A-n> :%s///gn<CR>
41 matches on 17 lines
My SearchPosition plugin provides a more elaborate variant of this:
1 match after cursor in this line, 8 following, 2 in previous lines;
total 10 within 11,42 for /\<SearchPosition\>/
There's also the IndexedSearch plugin, which integrates the reporting with the n / N commands.
As an alternative to /pattern, you could use:
:vim /pattern % | cw
to open a list of matches in the quickfix window.
You can also use:
:il[ist] /pattern/
and choose from the list with:
:{line number}

How can I yank the whole line without the "\n\r" at the end? [duplicate]

This question already has answers here:
Select entire line in VIM, without the new line character
(9 answers)
Closed 8 years ago.
I know that y$ can yank the string from the cursor's position to the end of line, but the "\n\r" is always included, is there any solution to do that without having the "\n\r" included?
You only need to move the cursor to the beginning of the line and yank from there to the end of the line:
0y$
^y$

How to delete to the last blank characters on the line [duplicate]

This question already has answers here:
How can you automatically remove trailing whitespace in vim
(14 answers)
Closed 9 years ago.
I have:
int x = 1;______
(underscores means spaces)
and I would like to get:
int x = 1;
My naive solution is $bld$, is there a quickest way?
In Emacs I use M-\ (delete-horizontal-space)
For the current line:
:s/\s\+$
For all lines:
:%s/\s\+$
The substitution text can be omitted if blank, so we don't need to write s/\s\+$//.
I do this with a search and replace mapping:
map <leader>W :%s/\s\+$//<CR>:let #/=''<CR>
:%s/\s\+$// deletes all trailing white space and then :let #/='' clears the search register.
:%s/\s\+$//
What it does is it searches for white spaces at the end of the line and replace them by nothing.
Source: http://vim.wikia.com/wiki/Remove_unwanted_spaces

Resources