13

Well, you can combine the "backward search" motion and the delete operator: d?$<Enter>


10

The easy way: join the lines in the logical blocks before sorting. In detail: mark the lines join the indented lines to the lines above: :'<,'>s/\n /^A/ mark the lines again: gv sort them: :'<,'>sort mark the lines one more time: gv split the lines back and restore indentation: :'<,'>s/^A/\r /g ^A above is the character Ctrl-A (ASCII SOH)...


10

Try d0kJx Deletes backwards to the beginning of the line, moves up, then joins the two lines and then removes the space in between the two joined lines. You don't have to leave normal mode with this.


9

Try a global command: :g/^/exe ".w! line".line('.').".txt" :g/^/ Do a command for every line (you can adjust this regular expression if you only want to save certain lines, i.e. . for non-empty lines) exe "" execute the following command .w! save the current line and overwrite if already exists. (Remove ! if you don't want to auto-overwrite everything) "...


9

The feasibility of deleting parts of lines is elusive and a better vimmer than I will have to explain that. If anyone cares to donate an explanation I'd be happy to add it to this answer. But it's quite possible to delete groups of rows that match a beginning pattern and an ending pattern. The most obvious way, I think, is to combine the :global and :delete ...


8

You can also use :%s/\w\+/`&` to convert from Lorem ipsum dolor sit amet to `Lorem` `ipsum` `dolor` `sit` `amet` :% range to the next command (whole buffer) s is a substitute command :s/regexWhat/substituteValue without range will substitute on a current line. \w\+ is a regexp for a word & is a whole value of what has been matched with regexpWhat, ...


7

yes, you can do with the ^M character in your abbrev, for example: iabbrev Doc #^M# function :^M#^M# returns :^M# will be transformed into: # # function : # # returns : # To get ^M you need to type <C-v> <CR>.


7

The two commands below will reduce every line to the first sequence of non-whitespace character followed by a space: from 0.453945 -2.14126e-54 3.40152e-49 101325 214.355 to 0.453945 <-- space But your question is a little confusing so I'm not sure I understood what you want. With a substitution: :%s/\(\S\+\s\).*/\1 With a macro: :%normal! WD


6

It turns out something along these lines works (although there might well be better ways) -- using a substitute-without-substituting command instead of a global command: Starting with the answer here: How to show all unique types of a pattern? :%s/[A-Za-z]*\>/\=add(b:types, submatch(0))/ng I went with: let @a='' :%s/func\s*(\_[^;]\{-\};/\=setreg('A', ...


6

There is a :folddoclosed command which iterates over all closed folds (just like :g command for the whole buffer) and executes one or more commands on them. So I would close all folds, convert each fold into one long line by replacing the end-of-line with a unique marker, shuffle the lines around, and replace the markers with line-breaks. Something along zM ...


5

I've released a vim plugin that pretty closely matches this behavior. Instead of scrolling by exactly N lines, this maps <C-u>, <C-d> (half window) and <C-j>, <C-k> (quarter window) to scroll as close to N lines as possible due to the wrapped lines, then moves the cursor back to the original relative line position in the Vim window. ...


5

There are a few ways you could do this. The way I would probably do it is this: :%norm I-<space> Note that the <space> should be a literal space, not the text <space>. This simply applies the set of keystrokes I-<space> to every line in the buffer. Uppercase I enters insert mode on the first non-whitespace character of the current ...


5

If you wanted to delete entire line starting with a space, This pattern will be useful. :g/^\s.*/d g -global ^ - start of the line \s - space .* - anything after that d - delete If you want the starting whitespace to remain, but delete the remaining content, you can use, :%s/^\(\s\+\).*/\1/g


5

To obtain this result you could use :substitute, for example with the cursor on the first line: :s/\u\+/{\0}/g \u\+ one or more uppercase character: equivalent to [A-Z]\+, see:h \u \0 whole matched pattern, see :h sub-replace-special g is a flag needed to replace all occurrences in the line unless gdefault is on To affect more than one line, you can ...


5

Peter Rincker's SortGroup is the go-to script for this kind of work. https://gist.github.com/PeterRincker/582ea9be24a69e6dd8e237eb877b8978 Somewhat differently to vim's :sort, it takes a pattern which is supposed to match the text declaring lines as the start of a group. For example, :SortGroup /^\DeclareAcronym{/ will sort all the DeclareAcronym ...


4

What happens if you run: :let @a="" :MSExecNormalCmd "Ay after you have your blocks visually selected? ... the idea (even if the above doesn't work) is still to yank-append each visually selected block to the same register. But, since you use a specific plugin, you are the one who should know how to do it (i.e. reading the plugin's help).


4

With visual mode: hvk$d Explanation h - Move one to the left v - Start visual mode k$ - Move to the end of the previous line d - Delete selection


4

I can't use first backreference (\1) instead of hardcoded string Well, you haven't captured anything in the search so \1 has no value in the replacement. You can use a matched text later in the pattern, as a back-reference, as well as in the replacement. :%s/^\(.*\)\n\1/\1/ This allows you to find a line (\(.*\)) which has a duplicate line immediately ...


4

Idea: Let's join the n number of lines under case to a single line. Follow the process for all cases. Then, use sort to sort the cases. Then, cut those lines back and indent them. Steps: 1) Join n lines following case by typing this. (in your case, n is 3) :g/case / normal! 3gJ 2) Select all such cases using visual mode. Press v ot V to select all cases....


4

:/baa/,/quz/s/baa/bar/ works, but that will only work with the first occurrence of baa. If you want to replace all occurrences of baa with bar that come before quz: ,/quz/s/baa/bar If your scenario calls for replacing all occurrences of baa if quz is found: /quz/,%s/baa/bar That will replace all occurrences of baa with bar if quz is found. This is ...


4

A macro is certainly capable of doing this. Starting with the first three lines as a template entry 100/1/1 fields value 1 other section 1 is valid Place your cursor on the first line and execute: qqy2EnterjjoEscp$CtrlajCtrlajCtrlakk0q qq Start a macro in register q y2Enter Yank three lines jjoEscp Copy the lines below inserting an extra blank line ...


4

vimscript option For the result: 1 2 3 4 5 1 2 3 4 5 1 2 3 4 5 1 2 3 4 5 1 2 3 4 5 Next "commands" solves it: :for i in range(6)|call setline(i, repeat(' ', (i-1)*2).getline(i))|endfor For the result: 1 2 3 4 5 1 2 3 4 5 1 2 3 4 5 1 2 3 4 5 1 2 3 4 5 Not really sure about the "rule" :) Another option with "...


4

I can think of two solutions to this: 1: Use normal mode mappings only; do not use an operator-pending mode mapping As @D.Ben Knoble mentioned in his comment, instead of noremap j gj noremap k gk use nnoremap j gj nnoremap k gk The former maps j and k in normal, visual, and operator-pending modes, while the latter maps j and k only in normal mode. ...


4

There is no direct functionality for that. (At least non I know of.) Assuming that none of the field short, long and extra contains any line-breaks: First join the lines into a single line. g/^\\DeclareAcronym/,/}}$/join This selects the lines from \Declare to a line that ends with }} and joins those line into a single line. Then sort And finally ...


4

You can use the :normal command, which allows you to run a sequence of Normal mode commands. When given a range, it repeats the sequence for every line. (It also starts at the beginning of each line, when given a range.) So you could use the e motion (end of the word, for a definition of word that includes keyword characters) or E (going up to the first ...


3

Seems like a great job for macros. Peter Rincker's may be fewer keystrokes, but I feel it's worth mentioning as if you need a more specific range than the whole file, it's a little easier to modify. With your cursor on the first column of the first line do the following: qq to start a macro Wysiw'+ Uses ys on second WORD (Just like Peter's) and moves to ...


3

You can use :normal to run a series of normal commands on lines in the buffer. :%norm Wysiw' This will skip to the second WORD and then use surround's ys command to surround with ' on the current iw text object. It does this for every line in the buffer, %. For more help see: :h :norm :h :range


3

Probably not exactly the solution you expect, but I'd rather use something like this: :g/^/ if search('^' . getline('.'), 'wn') != line('.') | delete | endif This will also remove duplicates (since you do mention unique sentences), e.g. This This is my first line, but longer. This is my first line, but longer. This is my first line becomes: This is my ...


3

There's something almost perverse in doing this with ex, akin to chopping a tree with a razor blade, or drinking a bucket of water through a straw. But if you stop and think for a few minutes about what you're doing, it's relatively straightforward: ex +'/aa\_.\{-}cc/' +'normal gny' +new +'normal P' +'%p' -scqa! file Translation, for the less masochistic ...


3

I'm not entirely sure what you want to accomplish, but from what I understand, you want to easily create boxes using commands/functions. Maybe this will help you get started on a solution. function! s:makebox(...) abort let width = str2nr(a:1) let height = a:0 < 2 ? width : str2nr(a:2) let margin = a:0 > 2 ? str2nr(a:3) : 0 let r_margin = ...


Only top voted, non community-wiki answers of a minimum length are eligible