💡
Knowledge
  • Home
  • Technology
    • Browser
      • Chrome / Brave
        • Known Issues
    • Messaging
      • Discord
        • Known Issues
      • Microsoft Teams
      • Telegram
    • Office Production
      • Sheets
    • Music Production
    • Operational systems
      • Docker + OSX
      • Raspberry Pi OS
      • Linux
        • Terminal
        • Known Issues
        • Desktop Environment
          • Gnome
            • How to
            • Known Issues
            • Theming
          • Kde Plasma
        • How to
          • Audio
          • Proxy
          • SSH
          • ZSH
      • Windows
    • Programming
      • Code Quality
        • Stress Tests
      • Cascading Style Sheets(CSS)
      • Database
        • Postgres
        • SQLServer
      • Design Patterns
      • DevOps
        • Cloud Platforms
        • Continuous Integration
        • Docker
          • How to
          • IPSEC VPN Server
          • Docker Compose
          • Known issues
          • Proxy
        • Swarm
      • Git
        • How to
        • Known Issues
        • Github
        • Gitlab
          • GitlabCI
          • Gitlab Runner
      • IDE / Text Editor
        • Vim
          • Commands
        • PHPStorm
        • VSCode
      • Programming Languages
        • Typescript
        • Java
          • How to
          • Spring Boot
        • Javascript
          • Known issues
          • Backend
            • NestJS
            • NodeJS
          • Frontend
            • JQuery
            • React
            • Vue
          • How to
          • Package Manager
            • Yarn
          • Packages
          • Vanilla
        • PHP
          • About
          • Cache
          • Composer
          • Docker
          • How to
          • Known Issues
          • Laravel
            • Jet Stream
            • Know Issues
            • Sanctum
            • Sail
            • Valet
          • Tools
            • PHPUnit
          • Wordpress
            • Docker
            • WP CLI
            • Known Issues
            • WooComerce
        • Python
        • Shell Script
      • Server
        • Apache2
          • Known Issues
        • Nginx
          • How To
          • Known issues
      • Tools
        • Visual Studio Code
    • Stream
      • Game
      • Twitch
      • Tests
        • Unit Tests
    • Sites
    • Specs
    • Tools
  • Pessoal
    • About me
Powered by GitBook
On this page
  • Save read-only files
  • Create a directory and save a read-only file
  • Create alias
  • Set vim as default editor
  • Alternative 1:
  • Alternative 2: Global Context
  • Commands
  • Deleting words
  • Move lines up or down

Was this helpful?

  1. Technology
  2. Programming
  3. IDE / Text Editor

Vim

Save read-only files

When you can't save a read-only file, the command below can.

:w !sudo tee % >/dev/null

Create a directory and save a read-only file

:w !sudo mkdir ~/test && sudo tee %

The output will appear:

W13: Warning: file "test/.file" was created by another program since the last edition
[O]K, (L)oad file:

Then press "O"

Create alias

To create an alias for this command put the content below inside ~/.vimrc file:

cnoremap sudow w !sudo tee % >/dev/null

To use the new alias, type :sudow inside Vim editor

Set vim as default editor

Alternative 1:

sudo update-alternatives --config editor

Alternative 2: Global Context

Set to global context:

export VISUAL=vim
export EDITOR="$VISUAL"

Git

Set core.editor in your Git config:

git config --global core.editor "vim"

Set the GIT_EDITOR environment variable:

export GIT_EDITOR=vim

Commands

Deleting words

dw  ---> Delete the word from your cursor to the end of the word
diw ---> Delete inside word.
daw ---> Delete all words from your cursor
nnoremap <A-j> :m .+1<CR>==
nnoremap <A-k> :m .-2<CR>==
inoremap <A-j> <Esc>:m .+1<CR>==gi
inoremap <A-k> <Esc>:m .-2<CR>==gi
vnoremap <A-j> :m '>+1<CR>gv=gv
vnoremap <A-k> :m '<-2<CR>gv=gv

In normal mode or in insert mode, press Alt-j to move the current line down, or press Alt-k to move the current line up.

After visually selecting a block of lines (for example, by pressing V then moving the cursor down), press Alt-j to move the whole block down, or press Alt-k to move the block up.

PreviousIDE / Text EditorNextCommands

Last updated 2 years ago

Was this helpful?

The following mappings in your provide a quick way to move lines of text up or down. The mappings work in normal, insert and visual modes, allowing you to move the current line, or a selected block of lines.

Move lines up or down
vimrc