The Stack Overflow podcast is back! Listen to an interview with our new CEO.

New answers tagged

1

The help page for mode() only mentions normal mode That's not true. The help page (:h mode()) is quite complete. You have to supply an optional argument for the mode() function. let s:mode = mode(1) if s:mode[0] ==# 'n' if s:mode[1] ==# 'i' " normal using i_CTRL-O elseif s:mode[1] ==# 'o' " normal Operator-pending else " ...


0

The other answer doesn’t give the full command (note the equals sign): :set selection=inclusive even though the default is supposed to be inclusive. On my debian box I had to add it to .vimrc because it was exclusive.


1

an alternative: you want to keep any lines: 1, 4, etc. You could use: awk '!((FNR-1)%3)' file > newfile # awk: when a condition is given without action: # prints the lines for which the condition returns 0. # FNR designates the line number in the current file. # a%3 : takes the modulus of a and 3. ( 0%3=0, 1%3=1, 2%3=2, 3%...


4

I know this is the vi channel, but to me this is a sed problem. sed -ne 'p;n;n;n' <file >newfile So you can wrangle it into a vi solution: :0 !Gsed -ne 'p;n;n;n'


17

The easiest solution to me would be: :%norm j3dd That is: %: for every line norm: run the following keys as if in normal mode j3dd: go down on line then delete 3 lines So from the first line, go down to the second one and delete the next 3 lines. The second Text I want to keep. is now on the second line. Go down one line, delete 3. Rinse and repeat. ...


6

You have some great solutions already available. Here is another one: :g/^/if line('.')%4!=1|:s/^/DELETE ME/|endif :g/^DELETE ME/d First, we perform an action on every line (:g matching against the ^ (start of line)) and for every line number perform the result of linenumber % 4. If the result is unequal to 1, we add DELETE ME at the beginning of the line, ...


3

An alternative (I suppose we start on the line 1, and delete the lines 2-4, 6-8 and so on, as per an example text): while line(".") < line("$") silent +1delete _ 3 endwhile If prefer doing this interactively, you can make use of the "command-line register". That is, press :+1del 3<CR> and then 1000@:


19

Very simple approach: Move to the first line you want to delete. Record a macro: qa3ddjq Repeat it with a high number: 1000@a Step three will repeat the macro a thousand times or until an error is encountered. Hitting end of file (hence no lines to delete) produces an error and repetition of the macro is canceled. See :help recording.


Top 50 recent answers are included