{"id":74079,"date":"2026-03-16T18:51:22","date_gmt":"2026-03-16T15:51:22","guid":{"rendered":"https:\/\/cloudspinx.com\/?p=74079"},"modified":"2026-03-16T18:51:22","modified_gmt":"2026-03-16T15:51:22","slug":"lpic-101-basic-file-editing-with-vimvi","status":"publish","type":"post","link":"https:\/\/computingforgeeks.com\/lpic-101-basic-file-editing-with-vimvi\/","title":{"rendered":"LPIC 101 &#8211; Basic File Editing with vim|vi"},"content":{"rendered":"\n<p>Everything is considered a file in Linux or Unix like systems, and if not so it is a process. But there are special files that are more than just files. For example, these are pipes and sockets. There is no difference between a file and a directory since a directory file contain names of other files. Texts, services, programs, etc are all files.<\/p>\n\n\n\n<p>In general, all devices either input or output are considered to be files according to the system. During our day-to-day operations as System Administrators, we have to edit these files in satisfaction of our work. File editing can be done with text editors like <em>vi<\/em>, <em>vim<\/em>, <em>nano<\/em> and <strong>emacs<\/strong>.<\/p>\n\n\n\n<p>In this guide, we are going to learn how to edit files using vi or vim editor in Linux.<\/p>\n\n\n\n<h3 class=\"wp-block-heading\">What is vim?<\/h3>\n\n\n\n<p><code>Vim<\/code> is an improved version of the <code>vi<\/code> editor. Vim is a highly configurable text editor built to enable efficient text editing in Unix and Linux operating systems. Sometimes it is called <strong>Programmer&#8217;s Text Editor<\/strong>.<\/p>\n\n\n\n<p>By default, vim editor is not installed on Linux. To check whether <code>vim<\/code> is installed, launch your terminal with <em>CTRL+ALT+T<\/em> keys and type &#8220;<code><em>vim<\/em><\/code>&#8221; you will see Vim splash page appear.<\/p>\n\n\n\n<figure class=\"wp-block-image size-large\"><img loading=\"lazy\" decoding=\"async\" width=\"1024\" height=\"576\" src=\"https:\/\/computingforgeeks.com\/wp-content\/uploads\/2025\/02\/vim-editor-1024x576.png\" alt=\"\" class=\"wp-image-74120\" title=\"\" srcset=\"https:\/\/computingforgeeks.com\/wp-content\/uploads\/2025\/02\/vim-editor-1024x576.png 1024w, https:\/\/computingforgeeks.com\/wp-content\/uploads\/2025\/02\/vim-editor-300x169.png 300w, https:\/\/computingforgeeks.com\/wp-content\/uploads\/2025\/02\/vim-editor-768x432.png 768w, https:\/\/computingforgeeks.com\/wp-content\/uploads\/2025\/02\/vim-editor-747x420.png 747w, https:\/\/computingforgeeks.com\/wp-content\/uploads\/2025\/02\/vim-editor-696x392.png 696w, https:\/\/computingforgeeks.com\/wp-content\/uploads\/2025\/02\/vim-editor-1068x601.png 1068w, https:\/\/computingforgeeks.com\/wp-content\/uploads\/2025\/02\/vim-editor.png 1280w\" sizes=\"auto, (max-width: 1024px) 100vw, 1024px\" \/><\/figure>\n\n\n\n<p>Otherwise run the following commands to install it.<\/p>\n\n\n\n<p>For Debian\/Ubuntu:<\/p>\n\n\n\n<pre class=\"wp-block-code\"><code>sudo apt update &amp;&amp; sudo apt install vim <\/code><\/pre>\n\n\n\n<p>For RHEL\/CentOS:<\/p>\n\n\n\n<pre class=\"wp-block-code\"><code>sudo yum install vim<\/code><\/pre>\n\n\n\n<p>For Arch Linux:<\/p>\n\n\n\n<pre class=\"wp-block-code\"><code>sudo pacman -S vim<\/code><\/pre>\n\n\n\n<p>For Fedora Linux 22 and above:<\/p>\n\n\n\n<pre class=\"wp-block-code\"><code>sudo dnf install vim-enhanced<\/code><\/pre>\n\n\n\n<h4 class=\"wp-block-heading\">Understanding vim Modes<\/h4>\n\n\n\n<p><code>vim<\/code> editor have three different execution modes for&nbsp;where program behavior changes;<\/p>\n\n\n\n<h5 class=\"wp-block-heading\">Command Mode<\/h5>\n\n\n\n<p>Also known as normal mode, this is where <code>vim<\/code>&nbsp;starts by default. In this mode, keyboard keys are associated with commands for navigation and text manipulation tasks.<\/p>\n\n\n\n<h5 class=\"wp-block-heading\">Insert Mode<\/h5>\n\n\n\n<p>The insert mode is straightforward: text appears on the screen as it is typed on the keyboard. It is the type of interaction most users expect from a text editor, but it is not how&nbsp;<code>vim<\/code>&nbsp;first presents a document.<\/p>\n\n\n\n<h5 class=\"wp-block-heading\">Ex Mode<\/h5>\n\n\n\n<p>This mode is sometimes also called colon commands because every command entered here is preceded with a colon (<code>:<\/code>). For example, to leave the vim editor and not save any changes you type <code>:q<\/code> and press the Enter key.<\/p>\n\n\n\n<h4 class=\"wp-block-heading\">Navigating Files using vim<\/h4>\n\n\n\n<p>You can navigate within a file in vim as follows;<\/p>\n\n\n\n<p>Move cursor left one character:<\/p>\n\n\n\n<pre class=\"wp-block-preformatted\"><strong>h<\/strong><\/pre>\n\n\n\n<p>Move cursor right one character:<\/p>\n\n\n\n<pre class=\"wp-block-preformatted\"><strong>l<\/strong><\/pre>\n\n\n\n<p>Move cursor down one line (the next line in the text):<\/p>\n\n\n\n<pre class=\"wp-block-preformatted\"><strong>j<\/strong><\/pre>\n\n\n\n<p>Move cursor up one line (the previous line in the text):<\/p>\n\n\n\n<pre class=\"wp-block-preformatted\"><strong>k<\/strong><\/pre>\n\n\n\n<h4 class=\"wp-block-heading\">vim command mode &#8211; Cursor move commands<\/h4>\n\n\n\n<p>The following are commonly used commands to move cursor in vim<\/p>\n\n\n\n<h5 class=\"wp-block-heading\">Moving Cursor<\/h5>\n\n\n\n<p>Move cursor forward one word to front of next word:<\/p>\n\n\n\n<pre class=\"wp-block-preformatted\"><strong>w<\/strong><\/pre>\n\n\n\n<p>Move cursor to end of current word:<\/p>\n\n\n\n<pre class=\"wp-block-preformatted\"><strong>e<\/strong><\/pre>\n\n\n\n<p>Move cursor backward one word:<\/p>\n\n\n\n<pre class=\"wp-block-preformatted\"><strong>b<\/strong><\/pre>\n\n\n\n<p>Move cursor to beginning of line:<\/p>\n\n\n\n<pre class=\"wp-block-preformatted\"><strong>^<\/strong><\/pre>\n\n\n\n<p>Move cursor to end of line:<\/p>\n\n\n\n<pre class=\"wp-block-preformatted\"><strong>$<\/strong><\/pre>\n\n\n\n<p>Move cursor to the file\u2019s first line:<\/p>\n\n\n\n<pre class=\"wp-block-preformatted\"><strong>gg<\/strong><\/pre>\n\n\n\n<p>Move cursor to the file\u2019s last line:<\/p>\n\n\n\n<pre class=\"wp-block-preformatted\"><strong>G<\/strong><\/pre>\n\n\n\n<p>Move cursor to file line number n:<\/p>\n\n\n\n<pre class=\"wp-block-preformatted\"><strong>nG<\/strong><\/pre>\n\n\n\n<h4 class=\"wp-block-heading\">Screen scrolling in vim<\/h4>\n\n\n\n<p>Scroll up almost one full screen:<\/p>\n\n\n\n<pre class=\"wp-block-preformatted\"><strong>Ctrl+B<\/strong><\/pre>\n\n\n\n<p>Scroll down almost one full screen:<\/p>\n\n\n\n<pre class=\"wp-block-preformatted\"><strong>Ctrl+F<\/strong><\/pre>\n\n\n\n<p>Scroll up half of a screen:<\/p>\n\n\n\n<pre class=\"wp-block-preformatted\"><strong>Ctrl+U<\/strong><\/pre>\n\n\n\n<p>Scroll down half of a screen:<\/p>\n\n\n\n<pre class=\"wp-block-preformatted\"><strong>Ctrl+D<\/strong><\/pre>\n\n\n\n<p>Scroll up one line:<\/p>\n\n\n\n<pre class=\"wp-block-preformatted\"><strong>Ctrl+Y<\/strong><\/pre>\n\n\n\n<p>Scroll down one line:<\/p>\n\n\n\n<pre class=\"wp-block-preformatted\"><strong>Ctrl+E<\/strong><\/pre>\n\n\n\n<h4 class=\"wp-block-heading\">vim command mode &#8211; edit commands<\/h4>\n\n\n\n<p>The following are commonly used vim command mode editing commands;<\/p>\n\n\n\n<h5 class=\"wp-block-heading\">Inserting in vim<\/h5>\n\n\n\n<p>Insert text after cursor:<\/p>\n\n\n\n<pre class=\"wp-block-preformatted\"><strong>a<\/strong><\/pre>\n\n\n\n<p>Insert text at end of text line:<\/p>\n\n\n\n<pre class=\"wp-block-preformatted\"><strong>A<\/strong><\/pre>\n\n\n\n<p>Insert text before cursor:<\/p>\n\n\n\n<pre class=\"wp-block-preformatted\"><strong>i<\/strong><\/pre>\n\n\n\n<p>Insert text before beginning of text line:<\/p>\n\n\n\n<pre class=\"wp-block-preformatted\"><strong>I<\/strong><\/pre>\n\n\n\n<p>Open a new text line below cursor, and move to insert mode:<\/p>\n\n\n\n<pre class=\"wp-block-preformatted\"><strong>o<\/strong><\/pre>\n\n\n\n<p>Open a new text line above cursor, and move to insert mode:<\/p>\n\n\n\n<pre class=\"wp-block-preformatted\"><strong>O<\/strong><\/pre>\n\n\n\n<h4 class=\"wp-block-heading\">Searching in vim<\/h4>\n\n\n\n<p>Forward searching:<\/p>\n\n\n\n<pre class=\"wp-block-preformatted\"><strong>?<\/strong><\/pre>\n\n\n\n<p>Backward searching:<\/p>\n\n\n\n<pre class=\"wp-block-preformatted\"><strong>\/<\/strong><\/pre>\n\n\n\n<h4 class=\"wp-block-heading\">Deleting in vim<\/h4>\n\n\n\n<p>Delete current line:<\/p>\n\n\n\n<pre class=\"wp-block-preformatted\"><strong>dd<\/strong><\/pre>\n\n\n\n<p>Cut four lines:<\/p>\n\n\n\n<pre class=\"wp-block-preformatted\"><strong>4dd<\/strong><\/pre>\n\n\n\n<p>Delete current word:<\/p>\n\n\n\n<pre class=\"wp-block-preformatted\"><strong>dw<\/strong><\/pre>\n\n\n\n<p>Cut a character:<\/p>\n\n\n\n<pre class=\"wp-block-preformatted\"><strong>x<\/strong><\/pre>\n\n\n\n<p>Cut to the end of the line:<\/p>\n\n\n\n<pre class=\"wp-block-preformatted\"><strong>D<\/strong><\/pre>\n\n\n\n<h4 class=\"wp-block-heading\">Pasting in vim<\/h4>\n\n\n\n<p>Paste copied text after cursor:<\/p>\n\n\n\n<pre class=\"wp-block-preformatted\"><strong>p<\/strong><\/pre>\n\n\n\n<p>Paste copied (yanked) text before cursor:<\/p>\n\n\n\n<pre class=\"wp-block-preformatted\"><strong>P<\/strong><\/pre>\n\n\n\n<h4 class=\"wp-block-heading\">Copying in vim<\/h4>\n\n\n\n<p>Yank (copy) current word:<\/p>\n\n\n\n<pre class=\"wp-block-preformatted\"><strong>yw<\/strong><\/pre>\n\n\n\n<p>Yank (copy) two lines:<\/p>\n\n\n\n<pre class=\"wp-block-preformatted\"><strong>2yy<\/strong><\/pre>\n\n\n\n<p>Yank (copy) current line:<\/p>\n\n\n\n<pre class=\"wp-block-preformatted\"><strong>yy<\/strong><\/pre>\n\n\n\n<h4 class=\"wp-block-heading\">vim ex mode commands<\/h4>\n\n\n\n<p>This is where saving our changes takes place in vim.<\/p>\n\n\n\n<h5 class=\"wp-block-heading\">Saving changes in vim<\/h5>\n\n\n\n<p>Write buffer to file and quit editor:<\/p>\n\n\n\n<pre class=\"wp-block-preformatted\"><strong>:x<\/strong><\/pre>\n\n\n\n<p>Write buffer to file and quit editor:<\/p>\n\n\n\n<pre class=\"wp-block-preformatted\"><strong>:wq<\/strong><\/pre>\n\n\n\n<p>Write buffer to file and quit editor (overrides protection):<\/p>\n\n\n\n<pre class=\"wp-block-preformatted\"><strong>:wq!<\/strong><\/pre>\n\n\n\n<p>Write buffer to file and stay in editor:<\/p>\n\n\n\n<pre class=\"wp-block-preformatted\"><strong>:w<\/strong><\/pre>\n\n\n\n<p>Write buffer to file and stay in editor (overrides protection):<\/p>\n\n\n\n<pre class=\"wp-block-preformatted\"><strong>:w!<\/strong><\/pre>\n\n\n\n<p>Quit editor without writing buffer to file:<\/p>\n\n\n\n<pre class=\"wp-block-preformatted\"><strong>:q<\/strong><\/pre>\n\n\n\n<p>Quit editor without writing buffer to file (overrides protection):<\/p>\n\n\n\n<pre class=\"wp-block-preformatted\"><strong>:q!<\/strong><\/pre>\n\n\n\n<p>Write buffer to file and quit editor:<\/p>\n\n\n\n<pre class=\"wp-block-preformatted\"><strong>ZZ<\/strong><\/pre>\n\n\n\n<h4 class=\"wp-block-heading\">Using Tabs in vi<\/h4>\n\n\n\n<p>Open a second tab in vim:<\/p>\n\n\n\n<pre class=\"wp-block-preformatted\"><strong>:tabe<\/strong><\/pre>\n\n\n\n<p>Listing all tabs in vim:<\/p>\n\n\n\n<pre class=\"wp-block-preformatted\"><strong>:tabs<\/strong><\/pre>\n\n\n\n<p>Switch to the next tab:<\/p>\n\n\n\n<pre class=\"wp-block-preformatted\"><strong>:tabn<\/strong><\/pre>\n\n\n\n<p>Switch to the previous tab:<\/p>\n\n\n\n<pre class=\"wp-block-preformatted\"><strong>:tabp<\/strong><\/pre>\n\n\n\n<h4 class=\"wp-block-heading\">Extra vim tips<\/h4>\n\n\n\n<h5 class=\"wp-block-heading\">Search and replace in vim<\/h5>\n\n\n\n<p>In vi and vim you cab search and replace text<\/p>\n\n\n\n<p>Example:<\/p>\n\n\n\n<pre class=\"wp-block-code\"><code>:%s\/OLDLINE\/NEWLINE\/g<\/code><\/pre>\n\n\n\n<h5 class=\"wp-block-heading\">Turning line numbering on and off<\/h5>\n\n\n\n<p>Turn on line numbering:<\/p>\n\n\n\n<pre class=\"wp-block-code\"><code>:set number\n#OR\n:set nu<\/code><\/pre>\n\n\n\n<p>Turn off line numbering:<\/p>\n\n\n\n<pre class=\"wp-block-code\"><code>:set nonumber\n#OR\n:set nonu<\/code><\/pre>\n\n\n\n<h5 class=\"wp-block-heading\">Enable Auto indentation<\/h5>\n\n\n\n<p>Use set command like below:<\/p>\n\n\n\n<pre class=\"wp-block-code\"><code>:set autoindent\n#OR\n:set ai<\/code><\/pre>\n\n\n\n<p>Turn off:<\/p>\n\n\n\n<pre class=\"wp-block-code\"><code>:set noautoindent\n#OR\n:set noai<\/code><\/pre>\n\n\n\n<p>Setting the indentation level:<\/p>\n\n\n\n<pre class=\"wp-block-code\"><code>:set shiftwidth=4<\/code><\/pre>\n\n\n\n<h5 class=\"wp-block-heading\">Ignore case on searches<\/h5>\n\n\n\n<p>Enable case ignore:<\/p>\n\n\n\n<pre class=\"wp-block-code\"><code>:set ignorecase\n:set ic<\/code><\/pre>\n\n\n\n<p>Turn case sensitivity back:<\/p>\n\n\n\n<pre class=\"wp-block-code\"><code>:set noignorecase\n:set noic<\/code><\/pre>\n\n\n\n<h4 class=\"wp-block-heading\">Using vimdiff command<\/h4>\n\n\n\n<p>You can use the <em>vimdiff<\/em> command to compare two, three or four files with vim or vi side by side.<\/p>\n\n\n\n<p>Example:<\/p>\n\n\n\n<pre class=\"wp-block-code\"><code>vimdiff file1 file2<\/code><\/pre>\n\n\n\n<h4 class=\"wp-block-heading\">Set vim as default editor<\/h4>\n\n\n\n<p>To set vim as our default editor, we add the following to our shell configuration i.e&nbsp;<code>~\/.bashrc<\/code> file.<\/p>\n\n\n\n<pre class=\"wp-block-code\"><code>export VISUAL=vim\nexport EDITOR=\"$VISUAL\"<\/code><\/pre>\n\n\n\n<h4 class=\"wp-block-heading\">How To Customize vim<\/h4>\n\n\n\n<p>To customize vim you create a file under <em>~\/.vimrc<\/em><\/p>\n\n\n\n<p>See example below:<\/p>\n\n\n\n<pre class=\"wp-block-code\"><code>$ cat  ~\/.vimrc\nset nocompatible\nset backup\nset history=1000\nset ignorecase\nset smartcase\nset hlsearch\nset incsearch\nset number\nset showmatch\nsyntax on\nhighlight Comment ctermfg=LightCyan\nset wrap<\/code><\/pre>\n\n\n\n<h4 class=\"wp-block-heading\">Conclusion<\/h4>\n\n\n\n<p>This marks the end of our guide on Basic File Editing with vim. I hope the guide have been helpful.<\/p>\n\n\n\n<p>Below are more interesting guides on LPIC 101.<\/p>\n\n\n\n<ul class=\"wp-block-list\">\n<li><a href=\"https:\/\/computingforgeeks.com\/lpic-101-compress-and-uncompress-files-using-tar-gzip-bzip2-and-xz-on-linux\/\" target=\"_blank\" rel=\"noreferrer noopener\">LPIC 101 &#8211; Compress and Uncompress Files Using tar, gzip, bzip2<\/a><\/li>\n\n\n\n<li><a href=\"https:\/\/computingforgeeks.com\/lpic-101-managing-processes-in-linux-systems\/\" target=\"_blank\" rel=\"noreferrer noopener\">LPIC 101 &#8211; Managing Processes in Linux Systems<\/a><\/li>\n\n\n\n<li><a href=\"https:\/\/computingforgeeks.com\/lpic-101-search-text-files-on-linux-using-regular-expressions\/\">LPIC 101 &#8211; Search Text Files on Linux Using Regular Expressions<\/a><\/li>\n\n\n\n<li><a href=\"https:\/\/computingforgeeks.com\/lpic-101-managing-processes-in-linux-systems\/\" target=\"_blank\" rel=\"noreferrer noopener\">LPIC 101 &#8211; Maintaining The Integrity of Linux Filesystems<\/a><\/li>\n<\/ul>\n","protected":false},"excerpt":{"rendered":"<p>Everything is considered a file in Linux or Unix like systems, and if not so it is a process. But there are special files that are more than just files. For example, these are pipes and sockets. There is no difference between a file and a directory since a directory file contain names of other &#8230; <a title=\"LPIC 101 &#8211; Basic File Editing with vim|vi\" class=\"read-more\" href=\"https:\/\/computingforgeeks.com\/lpic-101-basic-file-editing-with-vimvi\/\" aria-label=\"Read more about LPIC 101 &#8211; Basic File Editing with vim|vi\">Read more<\/a><\/p>\n","protected":false},"author":3,"featured_media":74127,"comment_status":"open","ping_status":"open","sticky":false,"template":"","format":"standard","meta":{"footnotes":""},"categories":[299,47,50],"tags":[39531,39728,413],"class_list":["post-74079","post","type-post","status-publish","format-standard","has-post-thumbnail","hentry","category-how-to","category-linux","category-linux-tutorials","tag-lpic-101-2","tag-vi","tag-vim"],"_links":{"self":[{"href":"https:\/\/computingforgeeks.com\/wp-json\/wp\/v2\/posts\/74079","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/computingforgeeks.com\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/computingforgeeks.com\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/computingforgeeks.com\/wp-json\/wp\/v2\/users\/3"}],"replies":[{"embeddable":true,"href":"https:\/\/computingforgeeks.com\/wp-json\/wp\/v2\/comments?post=74079"}],"version-history":[{"count":0,"href":"https:\/\/computingforgeeks.com\/wp-json\/wp\/v2\/posts\/74079\/revisions"}],"wp:featuredmedia":[{"embeddable":true,"href":"https:\/\/computingforgeeks.com\/wp-json\/wp\/v2\/media\/74127"}],"wp:attachment":[{"href":"https:\/\/computingforgeeks.com\/wp-json\/wp\/v2\/media?parent=74079"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/computingforgeeks.com\/wp-json\/wp\/v2\/categories?post=74079"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/computingforgeeks.com\/wp-json\/wp\/v2\/tags?post=74079"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}