Saturday, November 24, 2018

Vim editor commands

  1. To go to specific line, type line number after colon.
  2. If it is before opening the document, type like "vim +160 test.txt" to open and show the 160th line of the document.
  3. To edit multiple lines, select multiple lines and use substitute command: https://www.ostechnix.com/comment-multiple-lines-vim-editor/
  4. 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.
  5. Insert variable text in each line
  6. https://unix.stackexchange.com/questions/8101/how-to-insert-the-result-of-a-command-into-the-text-in-vim
  7. https://vi.stackexchange.com/questions/3109/insert-an-incrementing-number-to-each-line-in-either-a-selection-or-a-match
  8. line top is '/^' and line end is '/$'.
  9. several vim commands:
  10. https://vim.fandom.com/wiki/Search_and_replace
  11. You can use :%s/.\{1}$// to delete 1 character off the end of each line.
  12. To delete first top 2 spaces of all lines, type ":%s/^  //". If you want to delete one or more spaces then ":%s/^ +//".



  1. To save an editing file; the save path is relative to what is shown by ":pwd", and is changed by ":cd":
  2. https://stackoverflow.com/questions/4980168/how-to-save-as-a-new-file-and-keep-working-on-the-original-one-in-vim

  1. To search for a word in a current document, type "/" and the word(":" unnecessary).
  2. To replace characters only in a selection, type "¥%V" after usual "s" command: ":s¥%Vtarget/replacement/g"
  3. To input Windows' line ending which displayed as "^M", press Ctrl-v Ctrl-m.
  4. To show the number of lines in the opened file:
    :echo line('$')
  5. 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
  6. 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

Writing a post in Markdown in Blogger

Following articles are helpful. * [【令和最新版】Blogger で Markdown を用いて記事を書く方法](https://qiita.com/hoge_fu-ga/items/267ea5ad4f8c120eaeb8) * [Bl...