# Tag Info

12

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 ...

12

Well, you can combine the "backward search" motion and the delete operator: d?$<Enter> 12 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. 10 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) "... 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 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, ... 9 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 8 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>. 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 It could be done with virtualedit=ALL: set virtualedit=all select visually vertical part of the text A\<ESC> return set virtualedit=block See the screen: 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 ... 6 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 ... 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 This would be very easy with a macro, but you've stated don't want to use one, so here's a few alternative methods. I think they're all more complicated than a simple macro-based solution, but they show off some interesting features of Vim that readers might want to use in other scenarios. Using :normal edits :5,7norm!d$4kA ^R" 5,7 # On ...

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

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

:/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 The short answer is: In Visual Block mode select lines to their ends ($) and use A to append some text at the end of each line. The longer answer: gg to go the beginning of the first line. CTRL-V (or the proper alternative CTRL-Q in e.g. gVim) to start blockwise visual selection. jjj$select all four lines down (jjj) and to the right until their individual ... 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 am going to suggest using Ctrl + v (<C-v>) to make a block. It sounds as if putting the second block after the first doesn't do what you want. However, if you put the first block in front of the second block, it should work. To move the first paragraph to before the second paragraph you can do: vip<C-v>$x"_d)P vip # Visually ...

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 ...

4

I like using a macro recording for this kind of task, since that allows me to use the Vim commands I know already to move and edit, rather than having to write (and debug!) regexps to accomplish the task. Using a macro recording, you can use the exact commands you'd use for this sequence: Delete \item (and space after it), add & (and space after it) ...

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