- To go to specific line, type line number after colon.
- If it is before opening the document, type like "vim +160 test.txt" to open and show the 160th line of the document.
- To edit multiple lines, select multiple lines and use substitute command: https://www.ostechnix.com/comment-multiple-lines-vim-editor/
- To open a file with cursor positioned at a specified line, do as in "vi +36 test.txt" to go to line 36 of "test.txt" file.
- Insert variable text in each line
- https://unix.stackexchange.com/questions/8101/how-to-insert-the-result-of-a-command-into-the-text-in-vim
- https://vi.stackexchange.com/questions/3109/insert-an-incrementing-number-to-each-line-in-either-a-selection-or-a-match
- line top is '/^' and line end is '/$'.
- several vim commands:
- https://vim.fandom.com/wiki/Search_and_replace
- You can use
:%s/.\{1}$//to delete 1 character off the end of each line. - To delete first top 2 spaces of all lines, type ":%s/^ //". If you want to delete one or more spaces then ":%s/^ +//".
- To save an editing file; the save path is relative to what is shown by ":pwd", and is changed by ":cd":

https://stackoverflow.com/questions/4980168/how-to-save-as-a-new-file-and-keep-working-on-the-original-one-in-vim
- To search for a word in a current document, type "/" and the word(":" unnecessary).
- To replace characters only in a selection, type "¥%V" after usual "s" command: ":s¥%Vtarget/replacement/g"
- To input Windows' line ending which displayed as "^M", press Ctrl-v Ctrl-m.
- To show the number of lines in the opened file:
:echo line('$') - To break
:g/^\$/-1j
https://unix.stackexchange.com/questions/327305/how-do-i-remove-newline-character-from-lines-preceding-a-particular-pattern/329238#329238?newreg=f56f163962ec4ab69405f93c2552e53e - To run vim commands without opening a file in console, use -c option:
vim YOURFILE -c 'g/{/-1j' -c ":sav $OUTFILE" -c 'q'
No comments:
Post a Comment