Vim opens file even if the user does bot have write permission to the file. But after revision, how to write file content with sudo in Vim if Vim reports no permission to write the file. Use this command inside of vim to write to the file with sudo: :w !sudo tee % Here, !
Read more
Tag: vim
How to make Vim indent C++11 lambdas correctly?
Posted onVim seems not indent C++11 lambas very well. How to make Vim indent C++11 lambdas correctly? For this following program, Vim indents it as #include <iostream> #include <string> #include <vector> #include <algorithm> int main () { std::vector<std::string> strs({“one”, “two”}); std::vector<std::string> newstrs; std::transform(strs.begin(), strs.end(), std::back_inserter(newstrs), [](const std::string& s) -> std::string { if (s == “one”) {
Read more
Making Evolution Not Wrap Lines in Composed Emails
Posted onEvolution seems wrap long lines automatically in “Plain Text” mode. How to make Evolution not wrap lines in composed Emails? Evolution does not have (so far) “Flowing Text” mode where “the text is soft broken at the composer edge, but those soft breaks aren’t translated to hard breaks when the mail is sent” ( Reference:
Read more
How to upgrade vim to version 8 on CentOS 7?
Posted onvim on CentOS 7 is version 7.4 with patches 1-160: $ vim –version VIM – Vi IMproved 7.4 (2013 Aug 10, compiled Dec 21 2016 17:00:20) Included patches: 1-160 How to upgrade it to version 8 which is the latest major version? Update on Oct 23 2018: the repository introduced in the original method is
Read more
How to detect whether a file is being written by any other process in Linux?
Posted onHow to detect whether a file is being written by any other process in Linux? Before a program open a file to processes it, it wants to ensure no other processes are writing to it. Here, we are sure after the files are written and closed, they will not be written any more. Hence, one-time
Read more
In Vim, are there shortcuts to set tab widths to 2 and 4?
Posted onTab widths may be different for different languages. Even with a common language, the tab width settings can be different for different projects. In Vim, are there shortcuts to set tab widths to 2 and 4? To quickly change the tab widths when changing projects. I am afraid no. But you create shortcuts for setting
Read more
How to move cursor to a specific byte in Vim?
Posted onIn Vim, ’20G’ moves the cursor to line 20 in command mode. But how to move the cursor to a specific byte in Vim? In normal mode, 20go will move the cursor to byte 20. Or in command line, :goto 20 or :go 20 From vimdoc: :[range]go[to] [count] [count]go Go to {count} byte in the
Read more
In Vim, how to search and replace in visual selection?
Posted onSearch and replace in the whole text in Vim can be done by :%s/from/to/gc. But how to search and replace in visual selection only? The %V atom in Vim restricts a pattern so that it matches only inside the visual selection. So, your command for searching and replacing only in the visual selection can be
Read more
How to manually set Vim’s filetype?
Posted onVim can detects the file types from quite well. But under certain situations, such as creating a new file, Vim does not automatically set the file type. How to manually set it? In side Vim, to set a filetype, set value to the filetype variable. For example, to set the filetype to php: :set filetype=php
Xterm color codes for Vim on Linux
Posted onVim uses Xterm color codes like 9, 1 and 114 on Linux. What’s the overall mapping from color to codes or codes to color? Xterm color table: You can also find the Xterm color codes here.
Vim turns to be slow after enabling some plugins, how to find which leads the problem?
Posted onVim itself is very fast. But it turns to be slow after enabling some plugins. How to find which plugin leads the slowness of Vim? You may use the profiling mechanisms in Vim. Please check a tutorial on profiling Vim. For profiling Vim startup: vim –startuptime profile.log For profiling certain actions in Vim: :profile start
Read more
Required packages for building YouCompleteMe for Vim on Fedora 21
Posted onYouCompleteMe for Vim on Fedora 21 reports this error: [zma@laptop:~/.vim/bundle/YouCompleteMe]$ ./install.sh — The C compiler identification is GNU 4.9.2 — The CXX compiler identification is GNU 4.9.2 — Check for working C compiler: /usr/bin/cc — Check for working C compiler: /usr/bin/cc — works — Detecting C compiler ABI info — Detecting C compiler ABI info
Read more
How to make taglist recognize specific files with certain extensions as C source files?
Posted onHow to make taglist recognize specific files with certain extensions as C source files? You may try adding this line to your ~/.vimrc: autocmd BufRead,BufNewFile *.c0 set filetype=c Reference: https://stackoverflow.com/questions/9013263/vim-tagslist-plugin-not-detecting-custom-language-racket
Emacs Remembering Last Editing Positions
Posted onHow to make emacs remember last editing positions in files. It will be convenient next time I open the same file the cursor automatically moves to the position I was last time editing the same file. The behavior seems enabled by default in Vim. How to make Emacs do this? I use the saveplace mode.
Read more
How to Wrap and NOT Wrap Lines in vim
Posted onHow to Wrap and NOT Wrap Lines in vim? Make vim wrap lines: :set wrap For not wrap which will be useful when reading some data result such as logs: :set nowrap It can also be written into the .vimrc config files
Auto indenting for OCaml code in Vim
Posted onHow to set up auto indenting for OCaml code in Vim? The built-in indenting in Vim for OCaml seems not very good. Please check the post at https://www.systutorials.com/5212/auto-indenting-for-ocaml-code-in-vim-with-ocp-indent/
Vim Regular Expressions Tutorials
Posted onGood tutorials on Vim regular Expressions. Vim Regular Expressions: http://www.softpanorama.org/Editors/Vimorama/vim_regular_expressions.shtml Another good one in Chinese: http://www.study-area.org/tips/vim/Vim-10.html
Auto completion in Vim
Posted onHow to enable auto code completion in Vim, like in the IDE? Several plugins I use: snipMate: Plugin for using TextMate-style snippets in Vim omnicppcomplete: Plugin for C/C++ omnicompletion neocomplcache: Ultimate auto completion system for Vim
How to manage plugins for Vim?
Posted onThe Vim plugin directory under ~/.vim seems messy—a plugin has different files in different directories and the files from different plugins are put together. This is hard to add/remove plugins. Is there any better method for managing them? I use pathogen and am very happy with it. After installing pathogen, any plugins you want to
Read more
3 Ways of Making Case Insensitive Search in Vim/Vi
Posted onBy default, Vim/Vi’s search is case sensitive. However, if I want to search case insensitively, is there any method? For example, I search for dog, instead of matching dog only case sensitively, I also want to find out phases containing Dog, DOg, etc. There are several methods: 1. Setting the search to be case insensitive
Read more