Search This Blog

Showing posts with label vim. Show all posts
Showing posts with label vim. Show all posts

Customize AstroNvim

Enable user customisation

cp -r ~/.config/nvim/lua/user_example ~/.config/nvim/lua/user



Install new plugins

nvim ~/.config/nvim/lua/user/init.lua

  plugins = {
    init = { 
      -- You can also add new plugins here as well:
      -- Add plugins, the packer syntax without the "use"
      { "bryant-the-coder/astron.nvim" }, -- astron colorscheme
    },
  },

:PackerSync



Change colorscheme

nvim ~/.config/nvim/lua/user/init.lua
 -- Set colorscheme to use
 -- colorscheme = "default_theme",
 colorscheme = "astron",



Disable relativenumber option

nvim ~/.config/nvim/lua/user/init.lua
relativenumber = false,



See also

Setup Neovim for Rust Development

  1. Install Neovim
  2. Install AstroNvim
    • After installed AstroNvim, you can customise it
  3. Install rust LSP
    In Neovim, execute command:
    :LspInstall rust
  4. Install rust language parser (tree-sitter)
    In Neovim, execute command:
    :TSInstall rust
  5. Install lua language parser (tree-sitter)
    In Neovim, execute command:
    :TSInstall lua
    This is useful for editting the Neovim config (lua) files (*.lua)





See also

Neovim configuration on Windows

  • Create a new folder: C:\Users\USER_NAME\AppData\Local\nvim
    mkdir %UserProfile%\AppData\Local\nvim
  • Create new file: C:\Users\USER_NAME\AppData\Local\nvim\init.vim and add configuration:
    set smartindent
    set tabstop=4
    set shiftwidth=4
    set expandtab
  • Create new file: C:\Users\USER_NAME\AppData\Local\nvim\init.vim and add configuration:
    " enable Windows shortcuts Ctrl-C Ctrl-V etc.
    source $VIMRUNTIME/mswin.vim
    behave mswin
    
    " enable mouse selection
    set mouse=a
    
    " Gui
    GuiTabline 0
    GuiPopupmenu 0
    GuiLinespace 5
    GuiFont Consolas:h13
    set termguicolors
    
    filetype on
    syntax enable
    set encoding=utf-8
    set background=light
  • Add "Open with Neovim" to context menu of File Explorer
    • Create a open-with-neovim.reg file:
      Windows Registry Editor Version 5.00
      
      [HKEY_CURRENT_USER\SOFTWARE\Classes\*\shell\Open with Neovim]
      
      [HKEY_CURRENT_USER\SOFTWARE\Classes\*\shell\Open with Neovim\command]
      @="C:\\Utils\\Neovim\\bin\\nvim-qt.exe \"%1\""
    • Click the reg file to add to Registry



See also

gVim on Windows 10: enabled copy and paste with Ctrl-C and Ctrl-V

  • Add the following lines to _vimrc
    • " make Ctrl-C Ctrl-V work
      source $VIMRUNTIME/mswin.vim
      
      " update Edit -> Paste menu item
      unmenu! Edit.Paste
      aunmenu Edit.Paste
      nnoremenu 20.360 &Edit.&Paste<Tab>Ctrl-V        "+gP
      cnoremenu    &Edit.&Paste<Tab>Ctrl-V        <C-R>



see also

Windows 10: make backspace work in gVim

  • Insert the following line to the start of the _vimrc file
    • set backspace=indent,eol,start



see also

Windows 10: Adjust gVim scaling on high DPI 4K screen

Fix: icons too small

  • Right click the gVim 8.2 shortcut icon to open the context menu
  • Select Properties
  • Activate Compatibility tab
  • Click Change high DPI settings button
  • In the new pop up window, check Override high DPI scaling behavior.
  • In the Scaling performed by: drop down list, select System (enhanced)



Fix: font too small

  • Edit _gvimrc in user's home directory (%USERPROFILE%)
    • set guifont=Consolas:h12

vim: format/indent xml file

  • It requires xmllint command. libxml2-utils need to be installed:
    sudo apt install libxml2-utils
  • Use vim open the xml file, use the following vim command to reformat:
    :%!xmllint --format -

VIM: commands

Mode switching

  • i - enter insert mode
  • : - enter command mode
  • R - enter replace mode
  • v - enter visual selection mode
  • SHIFT-v - enter visual line selection mode
  • CTRL-v - enter visual column selection mode
  • ESC - return to normal mode from insert or replace mode
  • ESC+ESC - return to normal mode from command or visual mode



VIM: tidy up HTML

First enable filetype indent then set filetype to html, then enable smartident:
:filetype indent on
:set filetype=html
:set smartindent
Then re-format the file using the following commands:
1G      # go to the beginning of file
gg=G    # reformat the file from the beginning

VIM: show column number

  • Option 1:
    set laststatus=2
    set statusline+=%F\ row\:%l\ col\:%c
  • Option 2:
    set ruler

vim: remove all java block comments

  1. Remove all /* ... */:
    :%s/\/\*\_.\{-}\*\///
  2. Remove all /** ... */:
    :%s/\/\*\*\_.\{-}\*\///

VIM: Fix indentations

In normal mode, gg=G where gg goes back to the first line and =G re-indents.

MacVIM: set default font in .gvimrc

edit ~/.gvimrc:
set guifont=Monaco:h15
Note: there is NO spaces around the equal sign.
set guifont=Courier\ New:h15
Note: slashes are required if the font name contains spaces.

VI (VIM): show or hide special characters

  • To show special characters e.g. tabs or line-breaks:
    :set list
    or set it in .vimrc
    set list
  • To hide special characters e.g. tabs or line-breaks:
    :set nolist
    or set it in .vimrc
    set nolist